MessageHandler.c 670 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682
  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 >= (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) )
  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. //check Transaction active
  1237. if(gunType[gun_index] == 'J')
  1238. {
  1239. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1240. {
  1241. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1242. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1243. {
  1244. meterValueSend[gun_index] =1;
  1245. }
  1246. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1247. {
  1248. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1249. if((access(filenmae,F_OK))!=-1)
  1250. {
  1251. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1252. sprintf(str,"rm -f %s",filenmae);
  1253. system(str);
  1254. }
  1255. }
  1256. }// End for CHAdeMO
  1257. }
  1258. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1259. {
  1260. for (int index = 0; index < CCS_QUANTITY; index++)
  1261. {
  1262. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1263. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1264. {
  1265. meterValueSend[gun_index] =1;
  1266. }
  1267. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1268. {
  1269. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1270. if((access(filenmae,F_OK))!=-1)
  1271. {
  1272. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1273. sprintf(str,"rm -f %s",filenmae);
  1274. system(str);
  1275. }
  1276. }
  1277. } // End for CCS
  1278. }
  1279. else if(gunType[gun_index] == 'G')
  1280. {
  1281. for (int index = 0; index < GB_QUANTITY; index++)
  1282. {
  1283. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1284. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1285. {
  1286. meterValueSend[gun_index] =1;
  1287. }
  1288. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1289. {
  1290. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1291. if((access(filenmae,F_OK))!=-1)
  1292. {
  1293. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1294. sprintf(str,"rm -f %s",filenmae);
  1295. system(str);
  1296. }
  1297. }
  1298. }// End for GB
  1299. }
  1300. else
  1301. {
  1302. for (int index = 0; index < AC_QUANTITY; index++)
  1303. {
  1304. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1305. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1306. {
  1307. meterValueSend[gun_index] =1;
  1308. }
  1309. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1310. {
  1311. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1312. if((access(filenmae,F_OK))!=-1)
  1313. {
  1314. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1315. sprintf(str,"rm -f %s",filenmae);
  1316. system(str);
  1317. }
  1318. }
  1319. }//End for AC
  1320. }
  1321. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1322. if(meterValueSend[gun_index] == 1)
  1323. {
  1324. sendMeterValuesRequest(gun_index);
  1325. #if 1 // for TempStopTransaction
  1326. storeTempStopTransaction(gun_index);
  1327. #endif
  1328. }
  1329. }
  1330. //==============================================
  1331. // Check Connector reserved
  1332. //==============================================
  1333. //===============================
  1334. // Check if Reserve is expired
  1335. //===============================
  1336. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1337. {
  1338. double diff_t;
  1339. struct tm tp;
  1340. // current time
  1341. time_t t = time(NULL);
  1342. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1343. tp.tm_isdst = -1;
  1344. time_t utc = mktime(&tp);
  1345. diff_t = difftime(utc, t);
  1346. if(diff_t <= 0)
  1347. {
  1348. DEBUG_INFO("reserve expired !!! \n");
  1349. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1350. }
  1351. }//END OF Check if Reserve is expired
  1352. //==========================================
  1353. // csu trigger FirmwareStatusNotificationReq
  1354. //==========================================
  1355. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1356. {
  1357. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1358. }
  1359. //==========================================
  1360. // csu trigger CancelReservationConf
  1361. //==========================================
  1362. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1363. {
  1364. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1365. }
  1366. //==========================================
  1367. // csu trigger ChangeAvailabilityConf
  1368. //==========================================
  1369. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1370. {
  1371. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1372. }
  1373. //==========================================
  1374. // csu trigger UnlockConnectorConf
  1375. //==========================================
  1376. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1377. {
  1378. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1379. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1380. }
  1381. //==========================================
  1382. // csu trigger ReserveNowConf
  1383. //==========================================
  1384. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1385. {
  1386. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1387. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1388. }
  1389. //==========================================
  1390. // csu trigger DataTransferReq
  1391. //==========================================
  1392. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1393. {
  1394. sendDataTransferRequest(gun_index);
  1395. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1396. }
  1397. }
  1398. }
  1399. //==========================================
  1400. // send request routine
  1401. //==========================================
  1402. int sendAuthorizeRequest(int gun_index)
  1403. {
  1404. mtrace();
  1405. int result = FAIL;
  1406. char message[100]={0};
  1407. char guid[37];
  1408. char tempdata[65]={0};
  1409. DEBUG_INFO("sendAuthorizeRequest \n");
  1410. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1411. //Local Authorize
  1412. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1413. {
  1414. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1415. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1418. result = PASS;
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1421. authorizeRetryTimes = 0;
  1422. return result;
  1423. }
  1424. 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))||
  1425. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1426. {
  1427. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1428. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1429. {
  1430. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1431. {
  1432. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1433. }
  1434. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1435. {
  1436. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1437. }
  1438. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1439. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1440. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1441. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1442. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1443. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1444. authorizeRetryTimes = 0;
  1445. return result;
  1446. }
  1447. else
  1448. {
  1449. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1450. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1451. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1453. result = PASS;
  1454. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1455. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1456. authorizeRetryTimes = 0;
  1457. return result;
  1458. }
  1459. }
  1460. //initailize struct Authorize
  1461. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1462. //get data from shared memory
  1463. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1464. random_uuid(guid);
  1465. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1466. LWS_Send(message);
  1467. sprintf(tempdata, "Authorize,%d", gun_index);
  1468. if(hashmap_operation(0, guid, tempdata) == 1)
  1469. {
  1470. result = PASS;
  1471. DEBUG_ERROR("Authorize mapItem pass\n");
  1472. }
  1473. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1474. return result;
  1475. }
  1476. int sendBootNotificationRequest(void)
  1477. {
  1478. mtrace();
  1479. int result = FAIL;
  1480. char message[500]={0}, payload[700]={0};
  1481. char guid[37]={0};
  1482. char tempdata[65]={0};
  1483. int IsGunCharging = FALSE;
  1484. //check Transaction active
  1485. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1486. {
  1487. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1488. {
  1489. IsGunCharging = TRUE;
  1490. }
  1491. }
  1492. for (int index = 0; index < CCS_QUANTITY; index++)
  1493. {
  1494. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1495. {
  1496. IsGunCharging = TRUE;
  1497. }
  1498. }
  1499. for (int index = 0; index < GB_QUANTITY; index++)
  1500. {
  1501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1502. {
  1503. IsGunCharging = TRUE;
  1504. }
  1505. }
  1506. for (int index = 0; index < AC_QUANTITY; index++)
  1507. {
  1508. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1509. {
  1510. IsGunCharging = TRUE;
  1511. }
  1512. }
  1513. if(IsGunCharging == TRUE)
  1514. {
  1515. server_sign = TRUE;
  1516. return result;
  1517. }
  1518. // Fill BootNotification fields
  1519. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1520. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1521. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1522. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1523. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1524. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1525. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1526. #if 0
  1527. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1528. ShmOCPP16Data->ChargeBoxId
  1529. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1530. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1531. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1532. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1533. ,ShmOCPP16Data->BootNotification.CpIccid
  1534. ,ShmOCPP16Data->BootNotification.CpImsi
  1535. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1536. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1537. #endif
  1538. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1539. ShmOCPP16Data->ChargeBoxId
  1540. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1541. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1542. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1543. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1544. ,ShmOCPP16Data->BootNotification.CpIccid
  1545. ,ShmOCPP16Data->BootNotification.CpImsi);
  1546. random_uuid(guid);
  1547. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1548. LWS_Send(message);
  1549. sprintf(tempdata, "BootNotification,0");
  1550. 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*/)
  1551. {
  1552. result = PASS;
  1553. }
  1554. memset(queuedata, 0, sizeof(queuedata));
  1555. strcpy(queuedata,message);
  1556. return result;
  1557. }
  1558. int sendDataTransferRequest(int gun_index)
  1559. {
  1560. mtrace();
  1561. char message[1000]={0};
  1562. char guid[37]={0};
  1563. char tempdata[65]={0};
  1564. int result = FAIL;
  1565. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1566. random_uuid(guid);
  1567. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1568. MESSAGE_TYPE_CALL,
  1569. guid,
  1570. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1571. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1572. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1573. LWS_Send(message);
  1574. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1575. 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*/)
  1576. {
  1577. result = PASS;
  1578. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1579. }
  1580. return result;
  1581. }
  1582. int sendDiagnosticsStatusNotificationRequest(char *status)
  1583. {
  1584. mtrace();
  1585. int result = FAIL;
  1586. char message[110]={0};
  1587. char guid[37]={0};
  1588. char tempdata[65]={0};
  1589. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1590. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1591. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1592. random_uuid(guid);
  1593. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1594. LWS_Send(message);
  1595. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1596. if(hashmap_operation(0, guid, tempdata) == 1)
  1597. {
  1598. result = PASS;
  1599. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1600. }
  1601. //#ifdef SystemLogMessage
  1602. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1603. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1604. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1605. //#endif
  1606. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1607. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1608. //record status
  1609. if(strcmp(status,"Idle")==0)
  1610. {
  1611. DiagnosticsStatusNotificationStatus = 0;
  1612. }
  1613. else if(strcmp(status,"Uploaded")==0)
  1614. {
  1615. DiagnosticsStatusNotificationStatus = 1;
  1616. }
  1617. else if(strcmp(status,"UploadFailed")==0)
  1618. {
  1619. DiagnosticsStatusNotificationStatus = 2;
  1620. }
  1621. else if(strcmp(status,"Uploading")==0)
  1622. {
  1623. DiagnosticsStatusNotificationStatus = 3;
  1624. }
  1625. return result;
  1626. }
  1627. int sendFirmwareStatusNotificationRequest(char *status)
  1628. {
  1629. mtrace();
  1630. int result = FAIL;
  1631. char message[110]={0};
  1632. char guid[37]={0};
  1633. char tempdata[65]={0};
  1634. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1635. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1636. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1637. random_uuid(guid);
  1638. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1639. LWS_Send(message);
  1640. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1641. 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*/)
  1642. {
  1643. result = PASS;
  1644. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1645. }
  1646. //#ifdef SystemLogMessage
  1647. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1648. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1649. //#endif
  1650. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1651. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1652. //record status
  1653. if(strcmp(status,"Downloaded")==0)
  1654. {
  1655. FirmwareStatusNotificationStatus = 0;
  1656. }
  1657. else if(strcmp(status,"DownloadFailed")==0)
  1658. {
  1659. FirmwareStatusNotificationStatus = 1;
  1660. }
  1661. else if(strcmp(status,"Downloading")==0)
  1662. {
  1663. FirmwareStatusNotificationStatus = 2;
  1664. }
  1665. else if(strcmp(status,"Idle")==0)
  1666. {
  1667. FirmwareStatusNotificationStatus = 3;
  1668. }
  1669. else if(strcmp(status,"InstallationFailed")==0)
  1670. {
  1671. FirmwareStatusNotificationStatus = 4;
  1672. }
  1673. else if(strcmp(status,"Installing")==0)
  1674. {
  1675. FirmwareStatusNotificationStatus = 5;
  1676. }
  1677. else if(strcmp(status,"Installed")==0)
  1678. {
  1679. FirmwareStatusNotificationStatus = 6;
  1680. }
  1681. return result;
  1682. }
  1683. int sendHeartbeatRequest(int gun_index)
  1684. {
  1685. mtrace();
  1686. int result = FAIL;
  1687. char message[80]={0};
  1688. char guid[37]={0};
  1689. char tempdata[65]={0};
  1690. random_uuid(guid);
  1691. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1692. , MESSAGE_TYPE_CALL
  1693. , guid );
  1694. LWS_Send(message);
  1695. sprintf(tempdata, "Heartbeat,%d", 0);
  1696. 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*/)
  1697. {
  1698. result = PASS;
  1699. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1700. }
  1701. return result;
  1702. }
  1703. int sendStartTransactionRequest(int gun_index)
  1704. {
  1705. mtrace();
  1706. int result = FAIL;
  1707. char message[250]={0};
  1708. char guid[37]={0};
  1709. struct timeval tmnow;
  1710. struct tm *tm;
  1711. char buf[28];//, usec_buf[6];
  1712. char tempdata[65]={0};
  1713. int tempIndex = 0;
  1714. DEBUG_INFO("sendStartTransactionRequest...");
  1715. gettimeofday(&tmnow, NULL);
  1716. time_t t;
  1717. t = time(NULL);
  1718. /*UTC time and date*/
  1719. tm = gmtime(&t);
  1720. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1721. #if 0 // remove temporally
  1722. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1723. strcat(buf,".");
  1724. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1725. strcat(buf,usec_buf);
  1726. #endif
  1727. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1728. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1729. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1730. // clear StartTransaction Response
  1731. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1732. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1733. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1734. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1735. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1736. if(gunType[gun_index] == 'J')
  1737. {
  1738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1739. {
  1740. tempIndex = ((gun_index==2) ? 1: 0);
  1741. }
  1742. else
  1743. {
  1744. tempIndex = gun_index;
  1745. }
  1746. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1747. {
  1748. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1749. {
  1750. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1751. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1752. }
  1753. }
  1754. }
  1755. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1756. {
  1757. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1758. {
  1759. tempIndex = ((gun_index==2) ? 1: 0);
  1760. }
  1761. else
  1762. {
  1763. tempIndex = gun_index;
  1764. }
  1765. for (int index = 0; index < CCS_QUANTITY; index++)
  1766. {
  1767. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1768. {
  1769. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1770. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1771. }
  1772. }
  1773. }
  1774. else if(gunType[gun_index] == 'G')
  1775. {
  1776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1777. {
  1778. tempIndex = ((gun_index==2) ? 1: 0);
  1779. }
  1780. else
  1781. {
  1782. tempIndex = gun_index;
  1783. }
  1784. for (int index = 0; index < GB_QUANTITY; index++)
  1785. {
  1786. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1787. {
  1788. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1789. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1790. }
  1791. }
  1792. }
  1793. else
  1794. {
  1795. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1796. {
  1797. tempIndex = 2;
  1798. }
  1799. else
  1800. {
  1801. tempIndex = gun_index;
  1802. }
  1803. for (int index = 0; index < AC_QUANTITY; index++)
  1804. {
  1805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1806. {
  1807. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1808. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1809. }
  1810. }
  1811. }
  1812. random_uuid(guid);
  1813. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1814. , MESSAGE_TYPE_CALL
  1815. , guid
  1816. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1817. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1818. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1819. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1820. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1821. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1822. 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*/)
  1823. {
  1824. result = PASS;
  1825. }
  1826. strcpy(queuedata, message);
  1827. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1828. if(GetTransactionQueueNum() == 1)
  1829. {
  1830. LWS_Send(message);
  1831. }
  1832. return result;
  1833. }
  1834. int sendStatusNotificationRequest(int gun_index)
  1835. {
  1836. mtrace();
  1837. int result = FAIL;
  1838. char message[600]={0};
  1839. char guid[37];
  1840. int currentStatus = 0;
  1841. struct timeval tmnow;
  1842. struct tm *tm;
  1843. char buf[28];//, usec_buf[6];
  1844. char tempdata[65]={0};
  1845. int tempIndex = 0;
  1846. gettimeofday(&tmnow, NULL);
  1847. time_t t;
  1848. t = time(NULL);
  1849. /*UTC time and date*/
  1850. tm = gmtime(&t);
  1851. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1852. #if 0 // remove temporally
  1853. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1854. strcat(buf,".");
  1855. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1856. strcat(buf,usec_buf);
  1857. #endif
  1858. printf("%s",buf);
  1859. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1860. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1861. // it's option
  1862. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1863. /*
  1864. enum _SYSTEM_STATUS
  1865. {
  1866. S_BOOTING = 0,
  1867. S_IDLE, = 1
  1868. S_AUTHORIZING, =2
  1869. S_REASSIGN_CHECK, =3
  1870. S_REASSIGN, =4
  1871. S_PRECHARGE, =5
  1872. S_PREPARING_FOR_EV, =6
  1873. S_PREPARING_FOR_EVSE, =7
  1874. S_CHARGING, =8
  1875. S_TERMINATING, =9
  1876. S_COMPLETE, =10
  1877. S_ALARM, =11
  1878. S_FAULT =12
  1879. }
  1880. */
  1881. //check Transaction active
  1882. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1883. if(gunType[gun_index] == 'J')
  1884. {
  1885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1886. {
  1887. tempIndex = ((gun_index==2) ? 1: 0);
  1888. }
  1889. else
  1890. {
  1891. tempIndex = gun_index;
  1892. }
  1893. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1894. {
  1895. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1896. {
  1897. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1898. {
  1899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1900. {
  1901. currentStatus = 1; //OCPP Status: Preparing
  1902. }
  1903. else
  1904. {
  1905. currentStatus = 0; //OCPP Status: Available
  1906. }
  1907. }
  1908. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1909. {
  1910. currentStatus = 1; //OCPP Status: Preparing
  1911. }
  1912. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1913. {
  1914. currentStatus = 2; //OCPP Status: Charging
  1915. }
  1916. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1917. {
  1918. currentStatus = 5; //OCPP Status: Finishing
  1919. }
  1920. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1921. {
  1922. currentStatus = 4; //OCPP Status: SuspendedEV
  1923. }
  1924. 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
  1925. {
  1926. currentStatus = 7; //OCPP Status: Unavailable
  1927. }
  1928. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1929. {
  1930. currentStatus = 8; //OCPP Status: Faulted
  1931. }
  1932. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1933. {
  1934. currentStatus = 6; //OCPP Status: Reserved
  1935. }
  1936. } //end of the same index
  1937. }//end of for CHAdeMO_QUANTITY
  1938. }
  1939. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1940. {
  1941. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1942. {
  1943. tempIndex = ((gun_index==2) ? 1: 0);
  1944. }
  1945. else
  1946. {
  1947. tempIndex = gun_index;
  1948. }
  1949. for (int index = 0; index < CCS_QUANTITY; index++)
  1950. {
  1951. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1952. {
  1953. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1954. {
  1955. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1956. {
  1957. currentStatus = 1; //OCPP Status: Preparing
  1958. }
  1959. else
  1960. {
  1961. currentStatus = 0; //OCPP Status: Available
  1962. }
  1963. }
  1964. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1965. {
  1966. currentStatus = 1; //OCPP Status: Preparing
  1967. }
  1968. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1969. {
  1970. currentStatus = 2; //OCPP Status: Charging
  1971. }
  1972. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1973. {
  1974. currentStatus = 5; //OCPP Status: Finishing
  1975. }
  1976. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1977. {
  1978. currentStatus = 4; //OCPP Status: SuspendedEV
  1979. }
  1980. 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
  1981. {
  1982. currentStatus = 7; //OCPP Status : Unavailable
  1983. }
  1984. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1985. {
  1986. currentStatus = 8; //OCPP Status: Faulted
  1987. }
  1988. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1989. {
  1990. currentStatus = 6; //OCPP Status: Reserved
  1991. }
  1992. } //end of the same index
  1993. } // end of for CCS_QUANTITY
  1994. }
  1995. else if(gunType[gun_index] == 'G')
  1996. {
  1997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1998. {
  1999. tempIndex = ((gun_index==2) ? 1: 0);
  2000. }
  2001. else
  2002. {
  2003. tempIndex = gun_index;
  2004. }
  2005. for (int index = 0; index < GB_QUANTITY; index++)
  2006. {
  2007. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2008. {
  2009. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2010. {
  2011. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2012. {
  2013. currentStatus = 1; //OCPP Status: Preparing
  2014. }
  2015. else
  2016. {
  2017. currentStatus = 0; //OCPP Status: Available
  2018. }
  2019. }
  2020. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  2021. {
  2022. currentStatus = 1; //OCPP Status: Preparing
  2023. }
  2024. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2025. {
  2026. currentStatus = 2; //OCPP Status: Charging
  2027. }
  2028. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2029. {
  2030. currentStatus = 5; //OCPP Status: Finishing
  2031. }
  2032. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2033. {
  2034. currentStatus = 4; //OCPP Status: SuspendedEV
  2035. }
  2036. 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
  2037. {
  2038. currentStatus = 7; //OCPP Status: Unavailable
  2039. }
  2040. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2041. {
  2042. currentStatus = 8; //OCPP Status: Faulted
  2043. }
  2044. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2045. {
  2046. currentStatus = 6; //OCPP Status: Reserved
  2047. }
  2048. } //end of the same index
  2049. } // end of for GB_QUANTITY
  2050. }
  2051. else
  2052. {
  2053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2054. {
  2055. tempIndex = 2;
  2056. }
  2057. else
  2058. {
  2059. tempIndex = gun_index;
  2060. }
  2061. for (int index = 0; index < AC_QUANTITY; index++)
  2062. {
  2063. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2064. {
  2065. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2066. {
  2067. 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))
  2068. {
  2069. currentStatus = 1; //OCPP Status: Preparing
  2070. }
  2071. else
  2072. {
  2073. currentStatus = 0; //OCPP Status: Available
  2074. }
  2075. }
  2076. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2077. {
  2078. currentStatus = 1; //OCPP Status: Preparing
  2079. }
  2080. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2081. {
  2082. currentStatus = 2; //OCPP Status: Charging
  2083. }
  2084. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2085. {
  2086. currentStatus = 5; //OCPP Status: Finishing
  2087. }
  2088. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2089. {
  2090. currentStatus = 4; //OCPP Status: SuspendedEV
  2091. }
  2092. 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
  2093. {
  2094. currentStatus = 7; //OCPP Status: Unavailable
  2095. }
  2096. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2097. {
  2098. currentStatus = 8; //OCPP Status: Faulted
  2099. }
  2100. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2101. {
  2102. currentStatus = 6; //OCPP Status: Reserved
  2103. }
  2104. }//end of the same index
  2105. }//end of for AC_QUANTITY
  2106. }
  2107. //it's option
  2108. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2109. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2110. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2111. random_uuid(guid);
  2112. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2113. , MESSAGE_TYPE_CALL
  2114. , guid
  2115. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2116. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2117. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2118. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2119. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2120. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2121. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2122. LWS_Send(message);
  2123. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2124. 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*/)
  2125. {
  2126. //DEBUG_ERROR("statusNotification mapitem pass");
  2127. result = PASS;
  2128. }
  2129. return result;
  2130. }
  2131. int sendStopTransactionRequest(int gun_index)
  2132. {
  2133. mtrace();
  2134. int result = FAIL;
  2135. //char message[1500]={0};
  2136. char guid[37]={0};
  2137. char tempdata[65]={0};
  2138. int tempIndex = 0;
  2139. //int idx_sample=0;
  2140. DEBUG_ERROR("sendStopTransactionRequest \n");
  2141. memset(queuedata, 0, sizeof(queuedata));
  2142. //ENERGY_ACTIVE_IMPORT_REGISTER
  2143. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2144. if(gunType[gun_index] == 'J')
  2145. {
  2146. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2147. {
  2148. tempIndex = ((gun_index==2) ? 1: 0);
  2149. }
  2150. else
  2151. {
  2152. tempIndex = gun_index;
  2153. }
  2154. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2155. {
  2156. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2157. {
  2158. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2159. }
  2160. }// END OF CHAdeMO_QUANTITY
  2161. }
  2162. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2163. {
  2164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2165. {
  2166. tempIndex = ((gun_index==2) ? 1: 0);
  2167. }
  2168. else
  2169. {
  2170. tempIndex = gun_index;
  2171. }
  2172. for (int index = 0; index < CCS_QUANTITY; index++)
  2173. {
  2174. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2175. {
  2176. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2177. }
  2178. }// END OF CCS_QUANTITY
  2179. }
  2180. else if(gunType[gun_index] == 'G')
  2181. {
  2182. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2183. {
  2184. tempIndex = ((gun_index==2) ? 1: 0);
  2185. }
  2186. else
  2187. {
  2188. tempIndex = gun_index;
  2189. }
  2190. for (int index = 0; index < GB_QUANTITY; index++)
  2191. {
  2192. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2193. {
  2194. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2195. }
  2196. }// END OF GB_QUANTITY
  2197. }
  2198. else
  2199. {
  2200. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2201. {
  2202. tempIndex = 2;
  2203. }
  2204. else
  2205. {
  2206. tempIndex = gun_index;
  2207. }
  2208. for (int index = 0; index < AC_QUANTITY; index++)
  2209. {
  2210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2211. {
  2212. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2213. }
  2214. }// END OF AC_QUANTITY
  2215. }
  2216. //Stop Transaction Time
  2217. struct timeval tmnow;
  2218. struct tm *tm;
  2219. char buf[28];//, usec_buf[6];
  2220. gettimeofday(&tmnow, NULL);
  2221. time_t t;
  2222. t = time(NULL);
  2223. /*UTC time and date*/
  2224. tm = gmtime(&t);
  2225. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2227. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2228. random_uuid(guid);
  2229. /***********************************transactionData******************************************************/
  2230. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2231. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2232. //=================================
  2233. // Transaction_Begin
  2234. //=================================
  2235. // Energy.Active.Export.Interval
  2236. //idx_sample=0;
  2237. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2238. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2240. 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*/]);
  2241. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2242. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2243. {
  2244. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2245. }
  2246. else
  2247. {
  2248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2249. }
  2250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2251. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2252. //=================================
  2253. // Transaction_End
  2254. //=================================
  2255. //Current.Export
  2256. //idx_sample=1;
  2257. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2258. if(gunType[gun_index] == 'J')
  2259. {
  2260. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2261. {
  2262. tempIndex = ((gun_index==2) ? 1: 0);
  2263. }
  2264. else
  2265. {
  2266. tempIndex = gun_index;
  2267. }
  2268. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2269. {
  2270. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2271. {
  2272. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2273. }
  2274. }// End of for CHAdeMO_QUANTITY
  2275. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2276. }
  2277. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2278. {
  2279. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2280. {
  2281. tempIndex = ((gun_index==2) ? 1: 0);
  2282. }
  2283. else
  2284. {
  2285. tempIndex = gun_index;
  2286. }
  2287. for (int index = 0; index < CCS_QUANTITY; index++)
  2288. {
  2289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2290. {
  2291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2292. }
  2293. }// End of for CCS_QUANTITY
  2294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2295. }
  2296. else if(gunType[gun_index] == 'G')
  2297. {
  2298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2299. {
  2300. tempIndex = ((gun_index==2) ? 1: 0);
  2301. }
  2302. else
  2303. {
  2304. tempIndex = gun_index;
  2305. }
  2306. for (int index = 0; index < GB_QUANTITY; index++)
  2307. {
  2308. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2309. {
  2310. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2311. }
  2312. }// End of for GB_QUANTITY
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2314. }
  2315. else
  2316. {
  2317. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2318. {
  2319. tempIndex = 2;
  2320. }
  2321. else
  2322. {
  2323. tempIndex = gun_index;
  2324. }
  2325. for (int index = 0; index < AC_QUANTITY; index++)
  2326. {
  2327. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2328. {
  2329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2330. }
  2331. }// End of for AC_QUANTITY
  2332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2333. }
  2334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2335. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2337. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2340. //Energy.Active.Export.Interval
  2341. //idx_sample=2;
  2342. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2343. if(gunType[gun_index] == 'J')
  2344. {
  2345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2346. {
  2347. tempIndex = ((gun_index==2) ? 1: 0);
  2348. }
  2349. else
  2350. {
  2351. tempIndex = gun_index;
  2352. }
  2353. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2354. {
  2355. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2356. {
  2357. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2358. }
  2359. }// END OF CHAdeMO_QUANTITY
  2360. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2361. }
  2362. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2363. {
  2364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2365. {
  2366. tempIndex = ((gun_index==2) ? 1: 0);
  2367. }
  2368. else
  2369. {
  2370. tempIndex = gun_index;
  2371. }
  2372. for (int index = 0; index < CCS_QUANTITY; index++)
  2373. {
  2374. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2375. {
  2376. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2377. }
  2378. }// END OF CCS_QUANTITY
  2379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2380. }
  2381. else if(gunType[gun_index] == 'G')
  2382. {
  2383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2384. {
  2385. tempIndex = ((gun_index==2) ? 1: 0);
  2386. }
  2387. else
  2388. {
  2389. tempIndex = gun_index;
  2390. }
  2391. for (int index = 0; index < GB_QUANTITY; index++)
  2392. {
  2393. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2394. {
  2395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2396. }
  2397. }// END OF GB_QUANTITY
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2399. }
  2400. else
  2401. {
  2402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2403. {
  2404. tempIndex = 2;
  2405. }
  2406. else
  2407. {
  2408. tempIndex = gun_index;
  2409. }
  2410. for (int index = 0; index < AC_QUANTITY; index++)
  2411. {
  2412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2413. {
  2414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2415. }
  2416. }// END OF AC_QUANTITY
  2417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2418. }
  2419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2422. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2424. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2425. //Power.Active.Export
  2426. //idx_sample=3;
  2427. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2428. if(gunType[gun_index] == 'J')
  2429. {
  2430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2431. {
  2432. tempIndex = ((gun_index==2) ? 1: 0);
  2433. }
  2434. else
  2435. {
  2436. tempIndex = gun_index;
  2437. }
  2438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2439. {
  2440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2441. {
  2442. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2443. }
  2444. } // End for CHAdeMO_QUANTITY
  2445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2446. }
  2447. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2448. {
  2449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2450. {
  2451. tempIndex = ((gun_index==2) ? 1: 0);
  2452. }
  2453. else
  2454. {
  2455. tempIndex = gun_index;
  2456. }
  2457. for (int index = 0; index < CCS_QUANTITY; index++)
  2458. {
  2459. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2460. {
  2461. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2462. }
  2463. } // END for CCS_QUANTITY
  2464. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2465. }
  2466. else if(gunType[gun_index] == 'G')
  2467. {
  2468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2469. {
  2470. tempIndex = ((gun_index==2) ? 1: 0);
  2471. }
  2472. else
  2473. {
  2474. tempIndex = gun_index;
  2475. }
  2476. for (int index = 0; index < GB_QUANTITY; index++)
  2477. {
  2478. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2479. {
  2480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2481. }
  2482. }// END for GB_QUANTITY
  2483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2484. }
  2485. else
  2486. {
  2487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2488. {
  2489. tempIndex = 2;
  2490. }
  2491. else
  2492. {
  2493. tempIndex = gun_index;
  2494. }
  2495. for (int index = 0; index < AC_QUANTITY; index++)
  2496. {
  2497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2498. {
  2499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2500. }
  2501. } // END for AC_QUANTITY
  2502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2503. }
  2504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2507. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2510. //Voltage
  2511. //idx_sample=4;
  2512. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2513. if(gunType[gun_index] == 'J')
  2514. {
  2515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2516. {
  2517. tempIndex = ((gun_index==2) ? 1: 0);
  2518. }
  2519. else
  2520. {
  2521. tempIndex = gun_index;
  2522. }
  2523. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2524. {
  2525. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2526. {
  2527. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2528. }
  2529. } // END OF FOR CHAdeMO_QUANTITY
  2530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2531. }
  2532. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2533. {
  2534. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2535. {
  2536. tempIndex = ((gun_index==2) ? 1: 0);
  2537. }
  2538. else
  2539. {
  2540. tempIndex = gun_index;
  2541. }
  2542. for (int index = 0; index < CCS_QUANTITY; index++)
  2543. {
  2544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2545. {
  2546. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2547. }
  2548. } // END OF FOR CCS_QUANTITY
  2549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2550. }
  2551. else if(gunType[gun_index] == 'G')
  2552. {
  2553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2554. {
  2555. tempIndex = ((gun_index==2) ? 1: 0);
  2556. }
  2557. else
  2558. {
  2559. tempIndex = gun_index;
  2560. }
  2561. for (int index = 0; index < GB_QUANTITY; index++)
  2562. {
  2563. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2564. {
  2565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2566. }
  2567. } // END OF FOR GB_QUANTITY
  2568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2569. }
  2570. else
  2571. {
  2572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2573. {
  2574. tempIndex = 2;
  2575. }
  2576. else
  2577. {
  2578. tempIndex = gun_index;
  2579. }
  2580. for (int index = 0; index < AC_QUANTITY; index++)
  2581. {
  2582. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2583. {
  2584. 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
  2585. }
  2586. } // END OF FOR AC_QUANTITY
  2587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2588. }
  2589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2592. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2595. //SoC
  2596. //idx_sample=5;
  2597. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2598. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2599. {
  2600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2601. {
  2602. tempIndex = ((gun_index==2) ? 1: 0);
  2603. }
  2604. else
  2605. {
  2606. tempIndex = gun_index;
  2607. }
  2608. if(gunType[gun_index] == 'J')
  2609. {
  2610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2611. {
  2612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2613. {
  2614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2615. }
  2616. }
  2617. }
  2618. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2619. {
  2620. for (int index = 0; index < CCS_QUANTITY; index++)
  2621. {
  2622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2623. {
  2624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2625. }
  2626. }
  2627. }
  2628. else if(gunType[gun_index] == 'G')
  2629. {
  2630. for (int index = 0; index < GB_QUANTITY; index++)
  2631. {
  2632. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2633. {
  2634. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2635. }
  2636. }
  2637. }
  2638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2644. } // END FOR DC CASE
  2645. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2646. {
  2647. 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\"}]}]}]"
  2648. ,MESSAGE_TYPE_CALL
  2649. ,guid
  2650. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2651. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2655. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2657. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2698. );
  2699. }
  2700. else
  2701. {
  2702. 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\"}]}]}]"
  2703. ,MESSAGE_TYPE_CALL
  2704. ,guid
  2705. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2706. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2710. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2729. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2746. );
  2747. }
  2748. #if 0 // for TempStopTransaction
  2749. //Delete TempStopTransaction
  2750. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2751. {
  2752. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2753. }
  2754. #endif
  2755. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2756. if(hashmap_operation(0, guid, tempdata) == 1)
  2757. {
  2758. result = PASS;
  2759. DEBUG_INFO("StopTransaction mapitem pass\n");
  2760. }
  2761. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2762. if(GetTransactionQueueNum() == 1)
  2763. {
  2764. LWS_Send(queuedata);
  2765. }
  2766. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2767. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2768. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2769. {
  2770. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2771. }
  2772. //for test
  2773. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2774. return result;
  2775. }
  2776. int sendMeterValuesRequest(int gun_index)
  2777. {
  2778. mtrace();
  2779. int result = FAIL;
  2780. // char message[1500]={0};
  2781. char guid[37]={0};
  2782. //int idx_sample=0;
  2783. //int length = 0;
  2784. char tempdata[65]={0};
  2785. int tempIndex = 0;
  2786. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2787. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2788. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2789. {
  2790. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2791. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2792. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2793. return result;
  2794. }
  2795. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2796. {
  2797. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2798. }
  2799. memset(queuedata, 0, sizeof(queuedata));
  2800. //set value
  2801. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2802. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2803. random_uuid(guid);
  2804. //UTC Date time
  2805. struct timeval tmnow;
  2806. struct tm *tm;
  2807. char buf[28];//, usec_buf[6];
  2808. gettimeofday(&tmnow, NULL);
  2809. time_t t;
  2810. t = time(NULL);
  2811. /*UTC time and date*/
  2812. tm = gmtime(&t);
  2813. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2814. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2815. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2816. //idx_sample=0;
  2817. //********************************(1)Current.Export************************************************/
  2818. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2819. if(gunType[gun_index] == 'J')
  2820. {
  2821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2822. {
  2823. tempIndex = ((gun_index==2) ? 1: 0);
  2824. }
  2825. else
  2826. {
  2827. tempIndex = gun_index;
  2828. }
  2829. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2830. {
  2831. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2832. {
  2833. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2834. }
  2835. }
  2836. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2837. }
  2838. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2839. {
  2840. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2841. {
  2842. tempIndex = ((gun_index==2) ? 1: 0);
  2843. }
  2844. else
  2845. {
  2846. tempIndex = gun_index;
  2847. }
  2848. for (int index = 0; index < CCS_QUANTITY; index++)
  2849. {
  2850. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2851. {
  2852. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2853. }
  2854. }
  2855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2856. }
  2857. else if(gunType[gun_index] == 'G')
  2858. {
  2859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2860. {
  2861. tempIndex = ((gun_index==2) ? 1: 0);
  2862. }
  2863. else
  2864. {
  2865. tempIndex = gun_index;
  2866. }
  2867. for (int index = 0; index < GB_QUANTITY; index++)
  2868. {
  2869. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2870. {
  2871. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2872. }
  2873. }
  2874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2875. }
  2876. else
  2877. {
  2878. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2879. {
  2880. tempIndex = 2;
  2881. }
  2882. else
  2883. {
  2884. tempIndex = gun_index;
  2885. }
  2886. for (int index = 0; index < AC_QUANTITY; index++)
  2887. {
  2888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2889. {
  2890. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2891. }
  2892. }
  2893. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2894. }
  2895. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2898. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2901. //idx_sample=1;
  2902. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2903. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2904. if(gunType[gun_index] == 'J')
  2905. {
  2906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2907. {
  2908. tempIndex = ((gun_index==2) ? 1: 0);
  2909. }
  2910. else
  2911. {
  2912. tempIndex = gun_index;
  2913. }
  2914. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2915. {
  2916. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2917. {
  2918. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2919. }
  2920. } // END OF FOR CHAdeMO_QUANTITY
  2921. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2922. }
  2923. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2924. {
  2925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2926. {
  2927. tempIndex = ((gun_index==2) ? 1: 0);
  2928. }
  2929. else
  2930. {
  2931. tempIndex = gun_index;
  2932. }
  2933. for (int index = 0; index < CCS_QUANTITY; index++)
  2934. {
  2935. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2936. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2937. {
  2938. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2939. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2940. }
  2941. } // END OF CCS_QUANTITY
  2942. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2943. }
  2944. else if(gunType[gun_index] == 'G')
  2945. {
  2946. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2947. {
  2948. tempIndex = ((gun_index==2) ? 1: 0);
  2949. }
  2950. else
  2951. {
  2952. tempIndex = gun_index;
  2953. }
  2954. for (int index = 0; index < GB_QUANTITY; index++)
  2955. {
  2956. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2957. {
  2958. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2959. }
  2960. } // END OF GB_QUANTITY
  2961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2962. }
  2963. else
  2964. {
  2965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2966. {
  2967. tempIndex = 2;
  2968. }
  2969. else
  2970. {
  2971. tempIndex = gun_index;
  2972. }
  2973. for (int index = 0; index < AC_QUANTITY; index++)
  2974. {
  2975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2976. {
  2977. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2978. }
  2979. }
  2980. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2981. }
  2982. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  2985. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2986. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2988. //idx_sample=2;
  2989. //********************************(4)Power.Active.Export************************************************/
  2990. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2991. if(gunType[gun_index] == 'J')
  2992. {
  2993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2994. {
  2995. tempIndex = ((gun_index==2) ? 1: 0);
  2996. }
  2997. else
  2998. {
  2999. tempIndex = gun_index;
  3000. }
  3001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3002. {
  3003. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3004. {
  3005. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  3006. }
  3007. } // END OF FOR
  3008. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3009. }
  3010. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3011. {
  3012. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3013. {
  3014. tempIndex = ((gun_index==2) ? 1: 0);
  3015. }
  3016. else
  3017. {
  3018. tempIndex = gun_index;
  3019. }
  3020. for (int index = 0; index < CCS_QUANTITY; index++)
  3021. {
  3022. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3023. {
  3024. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3025. }
  3026. }
  3027. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3028. }
  3029. else if(gunType[gun_index] == 'G')
  3030. {
  3031. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3032. {
  3033. tempIndex = ((gun_index==2) ? 1: 0);
  3034. }
  3035. else
  3036. {
  3037. tempIndex = gun_index;
  3038. }
  3039. for (int index = 0; index < GB_QUANTITY; index++)
  3040. {
  3041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3042. {
  3043. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3044. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3045. }
  3046. }
  3047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3048. }
  3049. else
  3050. {
  3051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3052. {
  3053. tempIndex = 2;
  3054. }
  3055. else
  3056. {
  3057. tempIndex = gun_index;
  3058. }
  3059. for (int index = 0; index < AC_QUANTITY; index++)
  3060. {
  3061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3062. {
  3063. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3064. }
  3065. }
  3066. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3067. }
  3068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3069. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Import]);
  3071. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3073. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3074. //idx_sample=3;
  3075. //***********************************************(5)VOLTAGE******************************************************/
  3076. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3077. if(gunType[gun_index] == 'J')
  3078. {
  3079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3080. {
  3081. tempIndex = ((gun_index==2) ? 1: 0);
  3082. }
  3083. else
  3084. {
  3085. tempIndex = gun_index;
  3086. }
  3087. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3088. {
  3089. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3090. {
  3091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3092. }
  3093. }
  3094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3095. }
  3096. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3097. {
  3098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3099. {
  3100. tempIndex = ((gun_index==2) ? 1: 0);
  3101. }
  3102. else
  3103. {
  3104. tempIndex = gun_index;
  3105. }
  3106. for (int index = 0; index < CCS_QUANTITY; index++)
  3107. {
  3108. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3109. {
  3110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3111. }
  3112. }
  3113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3114. }
  3115. else if(gunType[gun_index] == 'G')
  3116. {
  3117. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3118. {
  3119. tempIndex = ((gun_index==2) ? 1: 0);
  3120. }
  3121. else
  3122. {
  3123. tempIndex = gun_index;
  3124. }
  3125. for (int index = 0; index < GB_QUANTITY; index++)
  3126. {
  3127. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3128. {
  3129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3130. }
  3131. }
  3132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3133. }
  3134. else
  3135. {
  3136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3137. {
  3138. tempIndex = 2;
  3139. }
  3140. else
  3141. {
  3142. tempIndex = gun_index;
  3143. }
  3144. for (int index = 0; index < AC_QUANTITY; index++)
  3145. {
  3146. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3147. {
  3148. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3149. }
  3150. }
  3151. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3152. }
  3153. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3155. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  3156. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3159. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3160. {
  3161. //idx_sample=4;
  3162. //sampledValue = NULL;
  3163. //***********************************************(6)SOC******************************************************/
  3164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3165. {
  3166. tempIndex = ((gun_index==2) ? 1: 0);
  3167. }
  3168. else
  3169. {
  3170. tempIndex = gun_index;
  3171. }
  3172. if(gunType[gun_index] == 'J')
  3173. {
  3174. //tempIndex = ((gun_index==2) ? 1: 0);
  3175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3176. {
  3177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3178. {
  3179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3180. }
  3181. }
  3182. }
  3183. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3184. {
  3185. //tempIndex = ((gun_index==2) ? 1: 0);
  3186. for (int index = 0; index < CCS_QUANTITY; index++)
  3187. {
  3188. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3189. {
  3190. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3191. }
  3192. }
  3193. }
  3194. else if(gunType[gun_index] == 'G')
  3195. {
  3196. //tempIndex = ((gun_index==2) ? 1: 0);
  3197. for (int index = 0; index < GB_QUANTITY; index++)
  3198. {
  3199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3200. {
  3201. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3202. }
  3203. }
  3204. }
  3205. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3207. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  3208. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3209. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3210. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3211. }
  3212. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3213. {
  3214. 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\"}]}]}]"
  3215. ,MESSAGE_TYPE_CALL
  3216. ,guid
  3217. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3218. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3219. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3220. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3221. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3222. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3223. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3224. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3225. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3226. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3227. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3228. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3229. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3230. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3231. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3232. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3233. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3234. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3235. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3236. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3237. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3238. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3239. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3240. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3241. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3242. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3243. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3244. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3245. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3246. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3247. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3248. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3249. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3250. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3251. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3252. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3253. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3254. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3255. );
  3256. }
  3257. else
  3258. {
  3259. 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\"}]}]}]"
  3260. ,MESSAGE_TYPE_CALL
  3261. ,guid
  3262. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3263. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3264. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3265. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3266. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3267. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3268. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3269. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3270. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3271. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3272. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3273. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3274. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3275. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3276. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3277. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3278. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3279. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3280. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3281. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3282. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3283. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3284. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3285. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3286. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3287. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3288. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3289. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3290. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3291. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3292. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3293. );
  3294. }
  3295. // Put request guid to hash map
  3296. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3297. 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*/)
  3298. {
  3299. result = PASS;
  3300. DEBUG_INFO("MeterValues mapitem pass\n");
  3301. }
  3302. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3303. if(GetTransactionQueueNum() == 1)
  3304. {
  3305. LWS_Send(queuedata);
  3306. }
  3307. return result;
  3308. }
  3309. //==========================================
  3310. // send confirm routine
  3311. //==========================================
  3312. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3313. {
  3314. mtrace();
  3315. int result = FAIL;
  3316. char message[100]={0};
  3317. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3319. LWS_Send(message);
  3320. result = TRUE;
  3321. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3322. return result;
  3323. }
  3324. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3325. {
  3326. mtrace();
  3327. int result = FAIL;
  3328. char message[100]={0};
  3329. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3330. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3331. LWS_Send(message);
  3332. result = TRUE;
  3333. return result;
  3334. }
  3335. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3336. {
  3337. mtrace();
  3338. int result = FAIL;
  3339. char message[100]={0};
  3340. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3341. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3342. LWS_Send(message);
  3343. result = TRUE;
  3344. return result;
  3345. }
  3346. int sendClearCacheConfirmation(char *uuid,char *payload)
  3347. {
  3348. mtrace();
  3349. int result = FAIL;
  3350. char message[500]={0};
  3351. // int count = 0;
  3352. // int gun_index = 0;
  3353. // char guid[37];
  3354. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3355. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3356. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3357. LWS_Send(message);
  3358. return result;
  3359. }
  3360. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3361. {
  3362. mtrace();
  3363. int result = FAIL;
  3364. char message[500]={0};
  3365. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3366. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3367. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3368. LWS_Send(message);
  3369. return result;
  3370. }
  3371. int sendDataTransferConfirmation(char *uuid,char *payload)
  3372. {
  3373. mtrace();
  3374. char statusStr[20]={0};
  3375. char dataStr[10]={0};
  3376. char sstr[20]={0};
  3377. int c = 0;
  3378. char *loc;
  3379. int result = FAIL;
  3380. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3381. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3382. /**********************status**************************/
  3383. loc = strstr(payload, "status");
  3384. memset(sstr ,0, sizeof(sstr) );
  3385. c = 0;
  3386. while (loc[3+strlen("status")+c] != '\"')
  3387. {
  3388. sstr[c] = loc[3+strlen("status")+c];
  3389. c++;
  3390. }
  3391. sstr[c] = '\0';
  3392. strcpy(statusStr, sstr);
  3393. /**********************data**************************/
  3394. loc = strstr(payload, "data");
  3395. memset(sstr ,0, sizeof(sstr) );
  3396. c = 0;
  3397. while (loc[3+strlen("data")+c] != '\"')
  3398. {
  3399. sstr[c] = loc[3+strlen("data")+c];
  3400. c++;
  3401. }
  3402. sstr[c] = '\0';
  3403. strcpy(dataStr, sstr);
  3404. return result;
  3405. }
  3406. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3407. {
  3408. mtrace();
  3409. int result = FAIL;
  3410. char message[1000]={0};
  3411. double diff_f = 0.0;
  3412. int diff_i = 0;
  3413. int diffSeconds = 0;
  3414. struct tm tp;
  3415. int TimeZero = FALSE;
  3416. int CompositeScheduleIndex = 0;
  3417. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3418. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3419. {
  3420. TimeZero = TRUE;
  3421. }
  3422. else
  3423. {
  3424. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3425. }
  3426. if(TimeZero == FALSE)
  3427. {
  3428. tp.tm_isdst = -1;
  3429. time_t utc = mktime(&tp);
  3430. time_t t = time(NULL);
  3431. diff_f = difftime(t, utc);
  3432. diff_i = (int)diff_f;
  3433. diffSeconds = diff_i % 86400;//86400 seconds/day
  3434. }
  3435. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3436. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3437. #if 0 //remove temporally
  3438. 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}"
  3439. ,MESSAGE_TYPE_CALLRESULT
  3440. ,uuid
  3441. ,payload
  3442. ,connectorIdInt
  3443. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3444. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3445. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3446. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3447. #endif
  3448. if(nPeriod == 0)
  3449. {
  3450. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3451. {
  3452. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3453. ,MESSAGE_TYPE_CALLRESULT
  3454. ,uuid
  3455. ,payload
  3456. ,connectorIdInt);
  3457. }
  3458. else
  3459. {
  3460. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3461. ,MESSAGE_TYPE_CALLRESULT
  3462. ,uuid
  3463. ,payload
  3464. ,connectorIdInt
  3465. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3466. }
  3467. }
  3468. else
  3469. {
  3470. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3471. ,MESSAGE_TYPE_CALLRESULT
  3472. ,uuid
  3473. ,payload
  3474. ,connectorIdInt
  3475. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3476. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3477. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3478. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3479. int len = nPeriod;
  3480. //Last Period StartPriod is less than diffSeconds
  3481. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3482. {
  3483. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3484. , 0
  3485. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3486. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3487. }
  3488. else
  3489. {
  3490. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3491. {
  3492. 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)
  3493. {
  3494. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3495. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3496. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3497. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3498. }
  3499. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3500. {
  3501. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3502. , ((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*/))
  3503. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3504. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3505. }
  3506. }
  3507. }
  3508. sprintf(message + strlen(message), "]}}]");
  3509. }
  3510. LWS_Send(message);
  3511. result = TRUE;
  3512. return result;
  3513. }
  3514. int sendGetConfigurationConfirmation(char *uuid)
  3515. {
  3516. mtrace();
  3517. int result = FAIL;
  3518. int MaxKeySupported = 0;
  3519. int sentConfigurationNumber= 0;
  3520. int sentunConfigurationNumber= 0;
  3521. char message[4000]={0};
  3522. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3523. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3524. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3525. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3526. ,MESSAGE_TYPE_CALLRESULT
  3527. ,uuid );
  3528. //configuration key
  3529. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3530. {
  3531. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3532. {
  3533. if (sentConfigurationNumber == 0)
  3534. {
  3535. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3536. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3537. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3538. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3539. }
  3540. else
  3541. {
  3542. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3543. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3544. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3545. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3546. }
  3547. sentConfigurationNumber = sentConfigurationNumber + 1;
  3548. }
  3549. }
  3550. sprintf(message + strlen(message), "]");
  3551. if(UnknownKeynum != 0)
  3552. {
  3553. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3554. //unkown key
  3555. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3556. {
  3557. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3558. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3559. if(sentunConfigurationNumber == 0)
  3560. {
  3561. sprintf(message + strlen(message), "\"%s\""
  3562. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3563. }
  3564. else
  3565. {
  3566. sprintf(message + strlen(message), ",\"%s\""
  3567. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3568. }
  3569. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3570. }
  3571. sprintf(message + strlen(message), "]");
  3572. }
  3573. sprintf(message + strlen(message), "}]");
  3574. LWS_Send(message);
  3575. return result;
  3576. }
  3577. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3578. {
  3579. mtrace();
  3580. int result = FAIL;
  3581. char message[400]={0};
  3582. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3583. if(strcmp(payload,"")==0)
  3584. {
  3585. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3586. }
  3587. else
  3588. {
  3589. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3590. }
  3591. LWS_Send(message);
  3592. result = TRUE;
  3593. return result;
  3594. }
  3595. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3596. {
  3597. mtrace();
  3598. int result = FAIL;
  3599. char message[80]={0};
  3600. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3601. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3602. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3603. LWS_Send(message);
  3604. result = TRUE;
  3605. return result;
  3606. }
  3607. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3608. {
  3609. mtrace();
  3610. int result = FAIL;
  3611. char message[80]={0};
  3612. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3613. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3614. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3615. LWS_Send(message);
  3616. result = TRUE;
  3617. return result;
  3618. }
  3619. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3620. {
  3621. mtrace();
  3622. int result = FAIL;
  3623. char message[80]={0};
  3624. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3625. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3626. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3627. LWS_Send(message);
  3628. result = TRUE;
  3629. return result;
  3630. }
  3631. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3632. {
  3633. mtrace();
  3634. int result = FAIL;
  3635. char message[80]={0};
  3636. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3637. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3638. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3639. LWS_Send(message);
  3640. result = TRUE;
  3641. return result;
  3642. }
  3643. int sendResetConfirmation(char *uuid,char *payload)
  3644. {
  3645. mtrace();
  3646. int result = FAIL;
  3647. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3648. char message[80]={0};
  3649. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3651. LWS_Send(message);
  3652. result = TRUE;
  3653. return result;
  3654. }
  3655. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3656. {
  3657. mtrace();
  3658. int result = FAIL;
  3659. char message[500]={0};
  3660. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3661. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3662. LWS_Send(message);
  3663. result = TRUE;
  3664. return result;
  3665. }
  3666. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3667. {
  3668. mtrace();
  3669. int result = FAIL;
  3670. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3671. char message[80]={0};
  3672. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3673. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3674. LWS_Send(message);
  3675. result = TRUE;
  3676. return result;
  3677. }
  3678. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3679. {
  3680. mtrace();
  3681. int result = FAIL;
  3682. char message[80]={0};
  3683. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3684. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3685. LWS_Send(message);
  3686. result = TRUE;
  3687. return result;
  3688. }
  3689. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3690. {
  3691. mtrace();
  3692. int result = FAIL;
  3693. char message[80]={0};
  3694. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3695. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3696. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3697. LWS_Send(message);
  3698. result = TRUE;
  3699. return result;
  3700. }
  3701. int sendUpdateFirmwareConfirmation(char *uuid)
  3702. {
  3703. mtrace();
  3704. int result = FAIL;
  3705. char message[60]={0};
  3706. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3707. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3708. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3709. LWS_Send(message);
  3710. result = TRUE;
  3711. return result;
  3712. }
  3713. //==========================================
  3714. // send CallError routine
  3715. //==========================================
  3716. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3717. {
  3718. mtrace();
  3719. //int result = FAIL;
  3720. char message[220]={0};
  3721. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3722. #ifdef SystemLogMessage
  3723. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3724. uniqueId, action, errorCode, errorDescription);
  3725. #endif
  3726. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3727. LWS_Send(message);
  3728. //result = TRUE;
  3729. }
  3730. //==========================================
  3731. // Handle server request routine Start
  3732. //==========================================
  3733. #define GUN_NUM 1
  3734. int handleCancelReservationRequest(char *uuid, char *payload)
  3735. {
  3736. mtrace();
  3737. int result = FAIL;
  3738. int gunNO = 0;
  3739. int reservationIdInt =0;
  3740. char comfirmstr[20];
  3741. int c = 0;
  3742. int copyTo = 0;
  3743. char *loc;
  3744. char sstr[100]={0};
  3745. DEBUG_INFO("handle CancelReservationRequest\n");
  3746. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3747. c = 0;
  3748. copyTo = 0;
  3749. loc = strstr(payload, "reservationId");
  3750. memset(sstr ,0, sizeof(sstr) );
  3751. while (loc[strlen("reservationId")+2+c] != '}')
  3752. {
  3753. if(loc[strlen("interval")+2+c] != ' ')
  3754. {
  3755. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3756. copyTo = copyTo + 1;
  3757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3758. }
  3759. c++;
  3760. }
  3761. sstr[copyTo] = '\0';
  3762. reservationIdInt = atoi(sstr);
  3763. memset(comfirmstr, 0, sizeof comfirmstr);
  3764. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3765. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3766. //check Transaction active
  3767. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3768. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3769. {
  3770. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3771. {
  3772. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3773. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3774. if(gunType[2] == 'J')
  3775. {
  3776. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3777. }
  3778. else
  3779. {
  3780. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3781. }
  3782. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3783. goto end;
  3784. }
  3785. }
  3786. for (int index = 0; index < CCS_QUANTITY; index++)
  3787. {
  3788. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3789. {
  3790. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3791. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3792. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3793. {
  3794. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3795. }
  3796. else
  3797. {
  3798. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3799. }
  3800. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3801. goto end;
  3802. }
  3803. }
  3804. for (int index = 0; index < GB_QUANTITY; index++)
  3805. {
  3806. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3807. {
  3808. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3809. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3810. if(gunType[2] == 'G')
  3811. {
  3812. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3813. }
  3814. else
  3815. {
  3816. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3817. }
  3818. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3819. goto end;
  3820. }
  3821. }
  3822. for (int index = 0; index < AC_QUANTITY; index++)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3825. {
  3826. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3827. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3828. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3829. {
  3830. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3831. }
  3832. else
  3833. {
  3834. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3835. }
  3836. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3837. goto end;
  3838. }
  3839. }
  3840. //The reservationId does NOT match the reservationId
  3841. sendCancelReservationConfirmation(uuid, comfirmstr);
  3842. end:
  3843. // Fill in ocpp packet uuid
  3844. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3845. return result;
  3846. }
  3847. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3848. {
  3849. mtrace();
  3850. int result = FAIL;
  3851. int gunIndex = 0;
  3852. char sstr[90]={0},sstrtemp[50]={ 0 };
  3853. char typeStr[16]={0};
  3854. char comfirmstr[20];
  3855. int specificId = FALSE;
  3856. char *loc;
  3857. //int intervalInt = 0;
  3858. int c = 0;
  3859. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3860. strcpy(sstrtemp, stringtrimspace(payload));
  3861. /*** connectorId ****/
  3862. loc = strstr(sstrtemp, "connectorId");
  3863. memset(sstr ,0, sizeof(sstr) );
  3864. c = 0;
  3865. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3866. {
  3867. sstr[c] = loc[strlen("connectorId")+2+c];
  3868. c++;
  3869. }
  3870. sstr[c] = '\0';
  3871. gunIndex = atoi(sstr);
  3872. /***type ****/
  3873. loc = strstr(sstrtemp, "type");
  3874. memset(sstr ,0, sizeof(sstr) );
  3875. c = 0;
  3876. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3877. {
  3878. sstr[c] = loc[3+strlen("type")+c];
  3879. c++;
  3880. }
  3881. sstr[c] = '\0';
  3882. strcpy(typeStr, sstr);
  3883. if(gunIndex != 0)
  3884. {
  3885. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3886. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3887. }
  3888. else
  3889. {
  3890. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3891. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3892. }
  3893. memset(comfirmstr, 0, sizeof comfirmstr);
  3894. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3895. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3896. {
  3897. specificId = TRUE;
  3898. }
  3899. if(specificId == FALSE)
  3900. goto end;
  3901. if(gunIndex != 0)
  3902. {
  3903. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3904. }
  3905. else
  3906. {
  3907. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3908. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3909. }
  3910. /*
  3911. enum SYSTEM_STATUS
  3912. {
  3913. SYS_MODE_BOOTING = 0,
  3914. SYS_MODE_IDLE = 1,
  3915. SYS_MODE_AUTHORIZING = 2,
  3916. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3917. SYS_MODE_REASSIGN = 4,
  3918. SYS_MODE_PREPARING = 5,
  3919. SYS_MODE_PREPARE_FOR_EV = 6,
  3920. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3921. SYS_MODE_CHARGING = 8,
  3922. SYS_MODE_TERMINATING = 9,
  3923. SYS_MODE_COMPLETE = 10,
  3924. SYS_MODE_ALARM = 11,
  3925. SYS_MODE_FAULT = 12,
  3926. SYS_MODE_RESERVATION = 13,
  3927. SYS_MODE_BOOKING = 14,
  3928. SYS_MODE_MAINTAIN = 15,
  3929. SYS_MODE_DEBUG = 16,
  3930. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3931. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3932. SYS_MODE_UPDATE = 19
  3933. };
  3934. */
  3935. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3936. {
  3937. //check Transaction active
  3938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3939. {
  3940. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  3941. {
  3942. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3943. {
  3944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3945. }
  3946. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3947. {
  3948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3949. }
  3950. else
  3951. {
  3952. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3953. }
  3954. goto end;
  3955. }
  3956. }//END FOR CHAdeMO_QUANTITY
  3957. for (int index = 0; index < CCS_QUANTITY; index++)
  3958. {
  3959. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  3960. {
  3961. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3962. {
  3963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3964. }
  3965. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3966. {
  3967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3968. }
  3969. else
  3970. {
  3971. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3972. }
  3973. goto end;
  3974. }
  3975. }//END FOR CCS_QUANTITY
  3976. for (int index = 0; index < GB_QUANTITY; index++)
  3977. {
  3978. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  3979. {
  3980. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3981. {
  3982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3983. }
  3984. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3985. {
  3986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3987. }
  3988. else
  3989. {
  3990. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3991. }
  3992. goto end;
  3993. }
  3994. }// END FOR GB_QUANTITY
  3995. for (int index = 0; index < AC_QUANTITY; index++)
  3996. {
  3997. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  3998. {
  3999. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4000. {
  4001. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4002. }
  4003. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4004. {
  4005. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4006. }
  4007. else
  4008. {
  4009. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4010. }
  4011. goto end;
  4012. }
  4013. }//END FOR AC_QUANTITY
  4014. }//END FOR AvailabilityTypeStr[Inoperative]
  4015. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  4016. {
  4017. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4018. //check Transaction active
  4019. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4020. {
  4021. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4022. {
  4023. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4024. goto end;
  4025. }
  4026. }//END FOR CHAdeMO_QUANTITY
  4027. for (int index = 0; index < CCS_QUANTITY; index++)
  4028. {
  4029. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4030. {
  4031. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4032. goto end;
  4033. }
  4034. }//END FOR CCS_QUANTITY
  4035. for (int index = 0; index < GB_QUANTITY; index++)
  4036. {
  4037. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4038. {
  4039. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4040. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4041. goto end;
  4042. }
  4043. }// END FOR GB_QUANTITY
  4044. for (int index = 0; index < AC_QUANTITY; index++)
  4045. {
  4046. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4047. {
  4048. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4049. goto end;
  4050. }
  4051. }//END FOR CHAdeMO_QUANTITY
  4052. }//END FOR AvailabilityTypeStr[Operative]
  4053. end:
  4054. if(gunIndex != 0)
  4055. {
  4056. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4057. }
  4058. else
  4059. {
  4060. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4061. }
  4062. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4063. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4064. return result;
  4065. }
  4066. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4067. {
  4068. mtrace();
  4069. int result = FAIL;
  4070. char sstr[100]={0},sstrtemp[160]={ 0 };
  4071. char keystr[40]={0};
  4072. char valuestr[100]={0};
  4073. char *loc;
  4074. int c = 0;
  4075. char comfirmstr[20]={0};
  4076. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4077. strcpy(sstrtemp, stringtrimspace(payload));
  4078. /***key ****/
  4079. loc = strstr(sstrtemp, "key");
  4080. memset(sstr ,0, sizeof(sstr) );
  4081. c = 0;
  4082. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4083. {
  4084. sstr[c] = loc[3+strlen("key")+c];
  4085. c++;
  4086. }
  4087. sstr[c] = '\0';
  4088. strcpy(keystr, sstr);
  4089. //DEBUG_INFO( "keystr=%s\n",keystr);
  4090. /***value ****/
  4091. loc = strstr(sstrtemp, "value");
  4092. memset(sstr ,0, sizeof(sstr) );
  4093. c = 0;
  4094. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4095. {
  4096. sstr[c] = loc[3+strlen("value")+c];
  4097. c++;
  4098. }
  4099. sstr[c] = '\0';
  4100. strcpy(valuestr, sstr);
  4101. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4102. if((uuid==NULL) || (payload ==NULL) )
  4103. {
  4104. #ifdef Debug
  4105. DEBUG_INFO("payload is null\n");
  4106. #endif
  4107. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4108. }
  4109. else
  4110. {
  4111. int status = setKeyValue(keystr, valuestr);
  4112. switch(status)
  4113. {
  4114. case ConfigurationStatus_Accepted:
  4115. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4116. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4117. StoreConfigurationTable();
  4118. break;
  4119. case ConfigurationStatus_Rejected:
  4120. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4121. break;
  4122. case RebootRequired:
  4123. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4124. StoreConfigurationTable();
  4125. break;
  4126. case NotSupported:
  4127. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4128. break;
  4129. default:
  4130. break;
  4131. }
  4132. }
  4133. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4134. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4135. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4136. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4137. {
  4138. ChageWebSocketPingInterval(atoi(valuestr));
  4139. }
  4140. return result;
  4141. }
  4142. int handleClearCacheRequest(char *uuid, char *payload)
  4143. {
  4144. mtrace();
  4145. int result = FAIL;
  4146. char comfirmstr[20];
  4147. int fd;
  4148. char rmFileCmd[100]={0};
  4149. struct stat stats;
  4150. DEBUG_INFO("handle ClearCacheRequest\n");
  4151. stat("/Storage/OCPP", &stats);
  4152. // Check for directory existence
  4153. if (S_ISDIR(stats.st_mode) == 1)
  4154. {
  4155. //DEBUG_ERROR("\n OCPP directory exist \n");
  4156. }
  4157. else
  4158. {
  4159. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4160. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4161. system(rmFileCmd);
  4162. }
  4163. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4164. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4165. {
  4166. DEBUG_INFO("AuthorizationCache file exist.\n");
  4167. }
  4168. else
  4169. {
  4170. DEBUG_INFO("AuthorizationCache file not exist\n");
  4171. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4172. if(log == NULL)
  4173. {
  4174. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4175. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4176. goto end;
  4177. }
  4178. else
  4179. {
  4180. fclose(log);
  4181. }
  4182. }
  4183. fd = open(AuthorizationCache_JSON,O_RDWR);
  4184. if(fd < 0)
  4185. {
  4186. DEBUG_INFO("open AuthorizationCache file failed\n");
  4187. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4188. }
  4189. else
  4190. {
  4191. DEBUG_INFO("open AuthorizationCache file successful\n");
  4192. //* 清空? 件 */
  4193. ftruncate(fd,0);
  4194. //* ? 新设置? 件? 移??*/
  4195. lseek(fd,0,SEEK_SET);
  4196. close(fd);
  4197. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4198. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4199. }
  4200. end:
  4201. sendClearCacheConfirmation(uuid, comfirmstr);
  4202. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4203. return result;
  4204. }
  4205. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4206. {
  4207. mtrace();
  4208. int result = FAIL;
  4209. int resultRename;
  4210. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4211. char chargingProfilePurposeStr[26]={0};
  4212. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4213. char tempchargingProfilePurposeStr[26]={0};
  4214. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4215. char str[100]={0};
  4216. int c = 0;
  4217. //int i = 0;
  4218. //char * pch;
  4219. char *loc;
  4220. char fname[200]={0};
  4221. char comfirmstr[20]={0};
  4222. char word[1600]={0};
  4223. int clearflag = FALSE;
  4224. int chargingProfileIdIsNULL = FALSE;
  4225. int connectorIsNULL = FALSE;
  4226. int chargingProfilePurposeIsNULL = FALSE;
  4227. int stackLevelIsNULL = FALSE;
  4228. //int GotoEnd = FALSE;
  4229. FILE *fptr1, *fptr2;
  4230. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4231. int n_chargingProfile=0;
  4232. int isEmptyFile = FALSE;
  4233. char sLineWord[1600]={0};
  4234. char chargingProfiles[10][100]={0};
  4235. int ChargeProfileCount = 0;
  4236. char ch;
  4237. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4238. strcpy(sstrtemp, stringtrimspace(payload));
  4239. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4240. //***id ****/
  4241. c = 0;
  4242. loc = strstr(sstrtemp, "id");
  4243. memset(sstr ,0, sizeof(sstr) );
  4244. if(loc == NULL)
  4245. {
  4246. chargingProfileIdIsNULL = TRUE;
  4247. }
  4248. else
  4249. {
  4250. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4251. {
  4252. sstr[c] = loc[strlen("id")+2+c];
  4253. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4254. c++;
  4255. }
  4256. sstr[c] = '\0';
  4257. chargingProfileIdInt = atoi(sstr);
  4258. }
  4259. //***connectorId ****/
  4260. c=0;
  4261. loc = strstr(sstrtemp, "connectorId");
  4262. memset(sstr ,0, sizeof(sstr) );
  4263. if(loc == NULL)
  4264. {
  4265. connectorIsNULL = TRUE;
  4266. }
  4267. else
  4268. {
  4269. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4270. {
  4271. sstr[c] = loc[strlen("connectorId")+2+c];
  4272. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4273. c++;
  4274. }
  4275. sstr[c] = '\0';
  4276. connectorIdInt = atoi(sstr);
  4277. }
  4278. //***chargingProfilePurpose ****/
  4279. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4280. memset(sstr ,0, sizeof(sstr) );
  4281. c = 0;
  4282. if(loc == NULL)
  4283. {
  4284. chargingProfilePurposeIsNULL = TRUE;
  4285. }
  4286. else
  4287. {
  4288. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4289. {
  4290. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4291. c++;
  4292. }
  4293. sstr[c] = '\0';
  4294. strcpy(chargingProfilePurposeStr, sstr);
  4295. }
  4296. //***stackLevel ****/
  4297. c=0;
  4298. loc = strstr(sstrtemp, "stackLevel");
  4299. memset(sstr ,0, sizeof(sstr) );
  4300. if(loc == NULL)
  4301. {
  4302. stackLevelIsNULL = TRUE;
  4303. }
  4304. else
  4305. {
  4306. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4307. {
  4308. sstr[c] = loc[strlen("stackLevel")+2+c];
  4309. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4310. c++;
  4311. }
  4312. sstr[c] = '\0';
  4313. stackLevelInt = atoi(sstr);
  4314. }
  4315. if(connectorIsNULL == FALSE)
  4316. {
  4317. switch(connectorIdInt)
  4318. {
  4319. case 0:
  4320. if(chargingProfilePurposeIsNULL == TRUE)
  4321. {
  4322. int l = 0;
  4323. strcpy(fname, ChargePointMaxProfile_JSON);
  4324. if((access(fname,F_OK))!=-1)
  4325. {
  4326. strcpy(chargingProfiles[l], fname);
  4327. l = l + 1;
  4328. }
  4329. strcpy(fname, TxDefaultProfile_0_JSON);
  4330. if((access(fname,F_OK))!=-1)
  4331. {
  4332. strcpy(chargingProfiles[l], fname);
  4333. l = l + 1;
  4334. }
  4335. ChargeProfileCount = l;
  4336. }
  4337. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4338. {
  4339. strcpy(fname, ChargePointMaxProfile_JSON);
  4340. if((access(fname,F_OK))!=-1)
  4341. {
  4342. strcpy(chargingProfiles[0], fname);
  4343. ChargeProfileCount = 1;
  4344. }
  4345. }
  4346. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4347. {
  4348. strcpy(fname, TxDefaultProfile_0_JSON);
  4349. if((access(fname,F_OK))!=-1)
  4350. {
  4351. strcpy(chargingProfiles[0], fname);
  4352. ChargeProfileCount = 1;
  4353. }
  4354. }
  4355. break;
  4356. default:
  4357. if(chargingProfilePurposeIsNULL == TRUE)
  4358. {
  4359. int m = 0;
  4360. memset(fname, 0, sizeof fname);
  4361. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4362. if((access(fname,F_OK))!=-1)
  4363. {
  4364. strcpy(chargingProfiles[m], fname);
  4365. m = m + 1;
  4366. }
  4367. memset(fname, 0, sizeof fname);
  4368. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4369. if((access(fname,F_OK))!=-1)
  4370. {
  4371. strcpy(chargingProfiles[m], fname);
  4372. m = m + 1;
  4373. }
  4374. ChargeProfileCount = m;
  4375. }
  4376. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4377. {
  4378. //strcpy(fname, TxDefaultProfile_1_JSON);
  4379. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4380. if((access(fname,F_OK))!=-1)
  4381. {
  4382. strcpy(chargingProfiles[0], fname);
  4383. ChargeProfileCount = 1;
  4384. }
  4385. }
  4386. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4387. {
  4388. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4389. if((access(fname,F_OK))!=-1)
  4390. {
  4391. strcpy(chargingProfiles[0], fname);
  4392. ChargeProfileCount = 1;
  4393. }
  4394. //strcpy(fname, TxProfile_1_JSON);
  4395. }
  4396. //strcpy(fname, ChargePointMaxProfile_JSON );
  4397. break;
  4398. }
  4399. }
  4400. else // Check all Charging Profiles
  4401. {
  4402. int i = 0;
  4403. char fnametemp[200]={0};
  4404. ChargeProfileCount = 0;
  4405. //Check ChargePointMaxProfile.json exit
  4406. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4407. {
  4408. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4409. i = i + 1;
  4410. }
  4411. //Check TxDefaultProfile_0.json exit
  4412. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4413. {
  4414. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4415. i = i + 1;
  4416. }
  4417. //Check TxDefaultProfile_%d.json
  4418. for(int j=1; j <= gunTotalNumber; j++)
  4419. {
  4420. memset(fnametemp, 0, sizeof fnametemp);
  4421. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4422. if((access(fnametemp,F_OK))!=-1)
  4423. {
  4424. strcpy(chargingProfiles[i], fnametemp);
  4425. i = i + 1;
  4426. }
  4427. }
  4428. //Check TxProfile_%d.json
  4429. for(int j=1; j <= gunTotalNumber; j++)
  4430. {
  4431. memset(fnametemp, 0, sizeof fnametemp);
  4432. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4433. if((access(fnametemp,F_OK))!=-1)
  4434. {
  4435. strcpy(chargingProfiles[i], fnametemp);
  4436. i = i + 1;
  4437. }
  4438. }
  4439. ChargeProfileCount = i;
  4440. }// End connectorIsNULL is TRUE
  4441. if(ChargeProfileCount == 0)
  4442. {
  4443. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4444. goto end;
  4445. }
  4446. #if 0
  4447. fptr1 = fopen(fname, "r");
  4448. if (!fptr1)
  4449. {
  4450. //file not exist
  4451. DEBUG_INFO("Unable to open the input file!!\n");
  4452. fptr1 = fopen(fname, "w+");
  4453. }
  4454. fclose(fptr1);
  4455. #endif
  4456. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4457. {
  4458. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4459. goto end;
  4460. }
  4461. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4462. {
  4463. memset(str, 0, sizeof str);
  4464. // clear temp file
  4465. sprintf(str,"rm -f %s",temp);
  4466. system(str);
  4467. for(int k=0; k < ChargeProfileCount; k++)
  4468. {
  4469. memset(str, 0, sizeof str);
  4470. //clear file in C
  4471. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4472. system(str);
  4473. }
  4474. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4475. goto end;
  4476. }
  4477. else if(connectorIsNULL == TRUE)
  4478. {
  4479. for(int k=0; k < ChargeProfileCount; k++)
  4480. {
  4481. fptr1 = fopen(chargingProfiles[k], "r");
  4482. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4483. //Check Charging Profile Count
  4484. while(fscanf(fptr1, "%s", word) != EOF)
  4485. {
  4486. //DEBUG_INFO("word=%s\n",word);
  4487. if(strstr(word, "chargingProfileId")!= NULL)
  4488. {
  4489. //DEBUG_INFO("test chargingProfileId \n");
  4490. n_chargingProfile = n_chargingProfile + 1;
  4491. //DEBUG_INFO("chargingProfileId Found\n");
  4492. }
  4493. }
  4494. rewind(fptr1);
  4495. //search Charging Profile Element
  4496. //int i= 0;
  4497. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4498. {
  4499. //------------------------tempconnectorIdInt------------------------//
  4500. loc = strstr(sLineWord, "connectorId");
  4501. c = 0;
  4502. memset(sstr ,0, sizeof(sstr) );
  4503. while (loc[strlen("connectorId")+2+c] != ',')
  4504. {
  4505. sstr[c] = loc[strlen("connectorId")+2+c];
  4506. c++;
  4507. }
  4508. sstr[c] = '\0';
  4509. tempconnectorIdInt = atoi(sstr);
  4510. printf("file's gun number is %d\n", tempconnectorIdInt);
  4511. //--------------------------chargingProfileId--------------------//
  4512. c = 0;
  4513. loc = strstr(sLineWord, "chargingProfileId");
  4514. memset(sstr ,0, sizeof(sstr) );
  4515. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4516. {
  4517. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4518. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4519. c++;
  4520. }
  4521. sstr[c] = '\0';
  4522. tempchargingProfileIdInt = atoi(sstr);
  4523. //stackLevel
  4524. c = 0;
  4525. loc = strstr(sLineWord, "stackLevel");
  4526. memset(sstr ,0, sizeof(sstr) );
  4527. while (loc[strlen("stackLevel")+2+c] != ',')
  4528. {
  4529. sstr[c] = loc[strlen("stackLevel")+2+c];
  4530. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4531. c++;
  4532. }
  4533. sstr[c] = '\0';
  4534. tempstackLevelInt = atoi(sstr);
  4535. c = 0;
  4536. loc = strstr(sLineWord, "chargingProfilePurpose");
  4537. memset(sstr ,0, sizeof(sstr) );
  4538. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4539. {
  4540. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4541. c++;
  4542. }
  4543. sstr[c] = '\0';
  4544. strcpy(tempchargingProfilePurposeStr, sstr);
  4545. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4546. {
  4547. //------- not write to fptr2-------//
  4548. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4549. //clearflag = TRUE;
  4550. }
  4551. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4552. {
  4553. //------- not write to fptr2-------//
  4554. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4555. }
  4556. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4557. {
  4558. //------- not write to fptr2-------//
  4559. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4560. }
  4561. else
  4562. {
  4563. fprintf(fptr2, sLineWord);//writing data into file
  4564. }
  4565. memset(sLineWord, 0, sizeof sLineWord);
  4566. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4567. if(clearflag == TRUE)
  4568. {
  4569. fclose(fptr1);
  4570. fclose(fptr2);
  4571. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4572. system(str);
  4573. // clear temp file
  4574. sprintf(str,"rm -f %s",temp);
  4575. system(str);
  4576. }
  4577. else
  4578. {
  4579. fclose(fptr1);
  4580. fclose(fptr2);
  4581. memset(str, 0, sizeof str);
  4582. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4583. system(str);
  4584. resultRename = rename(temp, chargingProfiles[k]);
  4585. if(resultRename == 0)
  4586. {
  4587. DEBUG_INFO("File ChargingProfile renamed successfully");
  4588. }
  4589. else
  4590. {
  4591. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4592. }
  4593. if(comfirmstr[0]== 0)
  4594. {
  4595. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4596. }
  4597. //Check chargingProfile is empty file
  4598. /*------ Read the file ----------------*/
  4599. fptr1=fopen(chargingProfiles[k],"r");
  4600. ch=fgetc(fptr1);
  4601. rewind(fptr1);
  4602. memset(sLineWord, 0, sizeof sLineWord);
  4603. if(ch!=EOF)
  4604. {
  4605. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4606. {
  4607. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4608. if(sLineWord[0]=='\0')
  4609. {
  4610. isEmptyFile = TRUE;
  4611. break;
  4612. }
  4613. else
  4614. {
  4615. isEmptyFile = FALSE;
  4616. break;
  4617. }
  4618. }
  4619. }
  4620. fclose(fptr1);
  4621. if(isEmptyFile == TRUE)
  4622. {
  4623. memset(str, 0, sizeof str);
  4624. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4625. system(str);
  4626. }
  4627. }
  4628. }// End of while(int k=0; k < ChargePointCount; k++)
  4629. }
  4630. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4631. {
  4632. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4633. for(int k=0; k < ChargeProfileCount; k++)
  4634. {
  4635. fptr1 = fopen(chargingProfiles[k], "r");
  4636. fptr2 = fopen(temp, "w+");
  4637. //Check Charging Profile Count
  4638. while(fscanf(fptr1, "%s", word) != EOF)
  4639. {
  4640. //DEBUG_INFO("word=%s\n",word);
  4641. if(strstr(word, "chargingProfileId")!= NULL)
  4642. {
  4643. //DEBUG_INFO("test chargingProfileId \n");
  4644. n_chargingProfile = n_chargingProfile + 1;
  4645. //DEBUG_INFO("chargingProfileId Found\n");
  4646. }
  4647. }
  4648. rewind(fptr1);
  4649. //search Charging Profile Element
  4650. //int i= 0;
  4651. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4652. {
  4653. //*************************tempconnectorIdInt*********************************/
  4654. loc = strstr(sLineWord, "connectorId");
  4655. c = 0;
  4656. memset(sstr ,0, sizeof(sstr) );
  4657. while (loc[strlen("connectorId")+2+c] != ',')
  4658. {
  4659. sstr[c] = loc[strlen("connectorId")+2+c];
  4660. c++;
  4661. }
  4662. sstr[c] = '\0';
  4663. tempconnectorIdInt = atoi(sstr);
  4664. //chargingProfileId
  4665. c = 0;
  4666. loc = strstr(sLineWord, "chargingProfileId");
  4667. memset(sstr ,0, sizeof(sstr) );
  4668. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4669. {
  4670. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4671. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4672. c++;
  4673. }
  4674. sstr[c] = '\0';
  4675. tempchargingProfileIdInt = atoi(sstr);
  4676. //stackLevel
  4677. c = 0;
  4678. loc = strstr(sLineWord, "stackLevel");
  4679. memset(sstr ,0, sizeof(sstr) );
  4680. while (loc[strlen("stackLevel")+2+c] != ',')
  4681. {
  4682. sstr[c] = loc[strlen("stackLevel")+2+c];
  4683. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4684. c++;
  4685. }
  4686. sstr[c] = '\0';
  4687. tempstackLevelInt = atoi(sstr);
  4688. c = 0;
  4689. loc = strstr(sLineWord, "chargingProfilePurpose");
  4690. memset(sstr ,0, sizeof(sstr) );
  4691. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4692. {
  4693. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4694. c++;
  4695. }
  4696. sstr[c] = '\0';
  4697. strcpy(tempchargingProfilePurposeStr, sstr);
  4698. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4699. {
  4700. //------- not write to fptr2-------//
  4701. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4702. //clearflag = TRUE;
  4703. }
  4704. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4705. {
  4706. //------- not write to fptr2-------//
  4707. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4708. }
  4709. else if(stackLevelIsNULL == TRUE)
  4710. {
  4711. //Clear Whole File
  4712. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4713. clearflag = TRUE;
  4714. break;
  4715. }
  4716. else
  4717. {
  4718. fprintf(fptr2, sLineWord);//writing data into file
  4719. }
  4720. memset(sLineWord, 0, sizeof sLineWord);
  4721. }
  4722. if(clearflag == TRUE)
  4723. {
  4724. fclose(fptr1);
  4725. fclose(fptr2);
  4726. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4727. system(str);
  4728. // clear temp file
  4729. sprintf(str,"rm -f %s",temp);
  4730. system(str);
  4731. }
  4732. else
  4733. {
  4734. fclose(fptr1);
  4735. fclose(fptr2);
  4736. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4737. system(str);
  4738. resultRename = rename(temp, chargingProfiles[k]);
  4739. if(resultRename == 0)
  4740. {
  4741. DEBUG_INFO("File ChargingProfile renamed successfully");
  4742. }
  4743. else
  4744. {
  4745. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4746. }
  4747. if(comfirmstr[0]== 0)
  4748. {
  4749. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4750. }
  4751. //Check chargingProfile is empty file
  4752. /*------ Read the file ----------------*/
  4753. fptr1=fopen(chargingProfiles[k],"r");
  4754. ch=fgetc(fptr1);
  4755. rewind(fptr1);
  4756. memset(sLineWord, 0, sizeof sLineWord);
  4757. if(ch!=EOF)
  4758. {
  4759. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4760. {
  4761. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4762. if(sLineWord[0]=='\0')
  4763. {
  4764. isEmptyFile = TRUE;
  4765. break;
  4766. }
  4767. else
  4768. {
  4769. isEmptyFile = FALSE;
  4770. break;
  4771. }
  4772. }
  4773. }
  4774. fclose(fptr1);
  4775. if(isEmptyFile == TRUE)
  4776. {
  4777. memset(str, 0, sizeof str);
  4778. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4779. system(str);
  4780. }
  4781. /*------- End of reading ---------------*/
  4782. }
  4783. } // while(int k=0; k < ChargeProfileCount; k++)
  4784. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4785. end:
  4786. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4787. return result;
  4788. }
  4789. int handleDataTransferRequest(char *uuid, char *payload)
  4790. {
  4791. mtrace();
  4792. int result = FAIL;
  4793. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4794. char tempvendorId[255]={0};
  4795. char tempmessageId[50]={0};
  4796. char tempdata[50]={0};
  4797. char sstr[160]={0};//sstr[200]={ 0 };
  4798. char message[80]={0};
  4799. int c = 0;
  4800. char *loc;
  4801. DEBUG_INFO("handle DataTransferRequest\n");
  4802. if((uuid != NULL) && (payload != NULL))
  4803. {
  4804. //===============================
  4805. // vendorId
  4806. //===============================
  4807. c = 0;
  4808. loc = strstr(payload, "vendorId");
  4809. while (loc[strlen("vendorId")+3+c] != '\"')
  4810. {
  4811. sstr[c] = loc[strlen("vendorId")+3+c];
  4812. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4813. c++;
  4814. }
  4815. sstr[c] = '\0';
  4816. strcpy(tempvendorId,sstr);
  4817. //===============================
  4818. // messageId
  4819. //===============================
  4820. memset(sstr ,0, sizeof(sstr) );
  4821. c = 0;
  4822. loc = strstr(payload, "messageId");
  4823. while (loc[strlen("messageId")+3+c] != '\"')
  4824. {
  4825. sstr[c] = loc[strlen("messageId")+3+c];
  4826. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4827. c++;
  4828. }
  4829. sstr[c] = '\0';
  4830. strcpy(tempmessageId,sstr);
  4831. //===============================
  4832. // data
  4833. //===============================
  4834. memset(sstr ,0, sizeof(sstr) );
  4835. c = 0;
  4836. loc = strstr(payload, "data");
  4837. printf("loc=%s\n",loc);
  4838. while (loc[strlen("data")+3+c] != '\"')
  4839. {
  4840. sstr[c] = loc[strlen("data")+3+c];
  4841. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4842. c++;
  4843. }
  4844. sstr[c] = '\0';
  4845. strcpy(tempdata,sstr);
  4846. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4847. }
  4848. else
  4849. {
  4850. char guid[37]={0};
  4851. random_uuid(guid);
  4852. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4853. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4854. }
  4855. LWS_Send(message);
  4856. return result;
  4857. }
  4858. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4859. {
  4860. mtrace();
  4861. int result = FAIL;
  4862. int connectorIdInt, durationInt;
  4863. char chargingRateUnitStr[4]={0};
  4864. //int tempconnectorIdInt,
  4865. int tempdurationInt;
  4866. float tempminChargingRateFloat = 0.0;
  4867. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4868. int tempStartPeriodInt=0;
  4869. float tempLimitInt=0.0;//0.1;
  4870. int tempNumberPhasesInt=0;
  4871. char fname[200];
  4872. char comfirmstr[20];
  4873. //float totallimit =0.0;
  4874. float MinChargingRate =0.0;
  4875. //double diff_t;
  4876. //struct tm tp;
  4877. FILE *fptr1;
  4878. int c = 0;
  4879. //int i = 0;
  4880. char * pch;
  4881. char *loc;
  4882. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4883. int n_chargingProfile = 0;
  4884. int n_SchedulePeriods = 0;
  4885. char SchedulePeriodList[10][200]={0};
  4886. char sLineWord[1600]={0};
  4887. //int n_periods = 0;
  4888. char word[1000]={0};
  4889. int confirmPeriods = 0;
  4890. struct StructProfile ChargePointMaxProfile;
  4891. struct StructProfile TxDefaultProfile;
  4892. struct StructProfile TxProfile;
  4893. struct StructProfile TxDefaultProfiletemp[2]={0};
  4894. int TxDefaultProfileFileIsNull=FALSE;
  4895. int ChargePointMaxProfileIsNull=FALSE;
  4896. int TxProfileIsNull=FALSE;
  4897. int CompositeSceduleIndex = 0;
  4898. char ChargePointMaxProfileScheduleStr[30]={0};
  4899. char TxDefaultProfileScheduleStr[30]={0};
  4900. char TxProfileScheduleStr[30]={0};
  4901. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4902. strcpy(sstrtemp, stringtrimspace(payload));
  4903. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4904. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4905. memset(&TxProfile,0,sizeof(struct StructProfile));
  4906. c=0;
  4907. loc = strstr(sstrtemp, "connectorId");
  4908. memset(sstr ,0, sizeof(sstr) );
  4909. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4910. {
  4911. sstr[c] = loc[strlen("connectorId")+2+c];
  4912. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4913. c++;
  4914. }
  4915. sstr[c] = '\0';
  4916. connectorIdInt = atoi(sstr);
  4917. c=0;
  4918. loc = strstr(sstrtemp, "duration");
  4919. memset(sstr ,0, sizeof(sstr) );
  4920. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4921. {
  4922. sstr[c] = loc[strlen("duration")+2+c];
  4923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4924. c++;
  4925. }
  4926. sstr[c] = '\0';
  4927. durationInt = atoi(sstr);
  4928. c = 0;
  4929. loc = strstr(sstrtemp, "chargingRateUnit");
  4930. memset(sstr ,0, sizeof(sstr) );
  4931. if(loc == NULL)
  4932. {
  4933. }
  4934. else
  4935. {
  4936. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4937. {
  4938. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4939. c++;
  4940. }
  4941. sstr[c] = '\0';
  4942. strcpy(chargingRateUnitStr, sstr);
  4943. }
  4944. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4945. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4946. if(connectorIdInt==0) // connectorId is 0
  4947. {
  4948. //******************************ChargePointMaxProfile*****************************************************/
  4949. strcpy(fname, ChargePointMaxProfile_JSON );
  4950. char word[30]={0};
  4951. char sLineWord[1060]={0};
  4952. int n_chargingProfile=0;
  4953. ChargePointMaxProfileIsNull=TRUE;
  4954. if((access(fname,F_OK))!=-1)
  4955. {
  4956. fptr1 = fopen(fname, "r");
  4957. int c;
  4958. c = fgetc(fptr1);
  4959. //DEBUG_INFO("c:%d\n",c);
  4960. rewind(fptr1);
  4961. if(c == EOF)
  4962. {
  4963. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4964. ChargePointMaxProfileIsNull=TRUE;
  4965. fclose(fptr1);
  4966. }
  4967. else
  4968. {
  4969. ChargePointMaxProfileIsNull=FALSE;
  4970. while(fscanf(fptr1, "%s", word) != EOF)
  4971. {
  4972. if(strcmp(word, "chargingProfileId") == 0)
  4973. {
  4974. n_chargingProfile = n_chargingProfile + 1;
  4975. printf("Found\n");
  4976. }
  4977. }
  4978. rewind(fptr1);
  4979. //search Charging Profile Element
  4980. int i= 0;
  4981. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4982. #if 0
  4983. /***********connectorId****************/
  4984. c = 0;
  4985. loc = strstr(sLineWord, "connectorId");
  4986. // printf("loc=%s\n",loc);
  4987. memset(sstr ,0, sizeof(sstr) );
  4988. while (loc[strlen("connectorId")+2+c] != ',')
  4989. {
  4990. sstr[c] = loc[strlen("connectorId")+2+c];
  4991. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4992. c++;
  4993. }
  4994. sstr[c] = '\0';
  4995. tempconnectorIdInt = atoi(sstr);
  4996. #endif
  4997. //***********validFrom**************/
  4998. c = 0;
  4999. loc = strstr(sLineWord, "validFrom");
  5000. //DEBUG_INFO("loc=%s\n",loc);
  5001. memset(sstr ,0, sizeof(sstr) );
  5002. if(loc != NULL)
  5003. {
  5004. while (loc[3+strlen("validFrom")+c] != '\"')
  5005. {
  5006. sstr[c] = loc[3+strlen("validFrom")+c];
  5007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5008. c++;
  5009. }
  5010. sstr[c] = '\0';
  5011. DEBUG_INFO("validFrom=%s\n",sstr);
  5012. strcpy(tempvalidFromStr,sstr);
  5013. }
  5014. else
  5015. {
  5016. strcpy(tempvalidFromStr,"");
  5017. }
  5018. //**********startSchedule**********/
  5019. c = 0;
  5020. loc = strstr(sLineWord, "startSchedule");
  5021. //DEBUG_INFO("loc=%s\n",loc);
  5022. memset(sstr ,0, sizeof(sstr) );
  5023. if(loc != NULL)
  5024. {
  5025. while (loc[3+strlen("startSchedule")+c] != '\"')
  5026. {
  5027. sstr[c] = loc[3+strlen("startSchedule")+c];
  5028. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5029. c++;
  5030. }
  5031. sstr[c] = '\0';
  5032. strcpy(tempstartScheduleStr, sstr);
  5033. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5034. }
  5035. else
  5036. {
  5037. strcpy(tempstartScheduleStr, "");
  5038. strcpy(ChargePointMaxProfileScheduleStr, "");
  5039. }
  5040. //**********chargingRateUnit**********/
  5041. c = 0;
  5042. loc = strstr(sLineWord, "chargingRateUnit");
  5043. memset(sstr ,0, sizeof(sstr) );
  5044. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5045. {
  5046. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5047. c++;
  5048. }
  5049. sstr[c] = '\0';
  5050. strcpy(tempchargingRateUnitStr, sstr);
  5051. //**********minChargingRate*******/
  5052. c = 0;
  5053. loc = strstr(sLineWord, "minChargingRate");
  5054. //printf("loc=%s\n",loc);
  5055. if(loc != NULL)
  5056. {
  5057. memset(sstr ,0, sizeof(sstr) );
  5058. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5059. {
  5060. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5062. c++;
  5063. }
  5064. sstr[c] = '\0';
  5065. tempminChargingRateFloat = atof(sstr);
  5066. }
  5067. else
  5068. {
  5069. tempminChargingRateFloat = 0.0;
  5070. }
  5071. //
  5072. #if 0
  5073. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5074. tp.tm_isdst = -1;
  5075. time_t utc = mktime(&tp);
  5076. // current time
  5077. time_t t = time(NULL);
  5078. #endif
  5079. //diff_t = difftime(t, utc);
  5080. //parsing strings to words
  5081. i = 0;
  5082. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5083. loc = loc+3+strlen("chargingSchedulePeriod");
  5084. pch = strtok(loc ,"{");
  5085. while (pch != NULL)
  5086. {
  5087. strcpy(SchedulePeriodList[i], pch);
  5088. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5089. //printf ("%s\n",pch);
  5090. pch = strtok (NULL, "{");
  5091. i = i + 1;
  5092. }
  5093. n_SchedulePeriods = i;
  5094. for(int i=0;i<n_SchedulePeriods;i++)
  5095. {
  5096. //*************startPeriod****************/
  5097. c = 0;
  5098. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5099. memset(sstr ,0, sizeof(sstr) );
  5100. while (loc[strlen("startPeriod")+2+c] != ',')
  5101. {
  5102. sstr[c] = loc[strlen("startPeriod")+2+c];
  5103. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5104. c++;
  5105. }
  5106. sstr[c] = '\0';
  5107. tempStartPeriodInt = atoi(sstr);
  5108. //*************limit****************/
  5109. c = 0;
  5110. loc = strstr(SchedulePeriodList[i], "limit");
  5111. memset(sstr ,0, sizeof(sstr) );
  5112. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5113. {
  5114. sstr[c] = loc[strlen("limit")+2+c];
  5115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5116. c++;
  5117. }
  5118. sstr[c] = '\0';
  5119. tempLimitInt = atof(sstr);
  5120. //*************numberPhases****************/
  5121. c = 0;
  5122. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5123. memset(sstr ,0, sizeof(sstr) );
  5124. if(loc != NULL)
  5125. {
  5126. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5127. {
  5128. sstr[c] = loc[strlen("numberPhases")+2+c];
  5129. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5130. c++;
  5131. }
  5132. sstr[c] = '\0';
  5133. tempNumberPhasesInt = atoi(sstr);
  5134. }
  5135. else
  5136. {
  5137. tempNumberPhasesInt = 0;
  5138. }
  5139. ChargePointMaxProfile.Duration = durationInt;
  5140. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5141. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5142. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5143. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5144. }
  5145. if(MinChargingRate < tempminChargingRateFloat)
  5146. MinChargingRate = tempminChargingRateFloat;
  5147. }
  5148. }// End of file ChargingProfile
  5149. } //THE END OF ACCESS ChargePointMaxProfile
  5150. //******************************TxDefaultProfile***********************************************/
  5151. strcpy(fname, TxDefaultProfile_0_JSON);
  5152. memset(word, 0, 30);
  5153. memset(sLineWord, 0, 1060);
  5154. //char word[30]={0};
  5155. //char sLineWord[1060]={0};
  5156. n_chargingProfile=0;
  5157. TxDefaultProfileFileIsNull=TRUE;
  5158. if((access(fname,F_OK))!=-1)
  5159. {
  5160. fptr1 = fopen(fname, "r");
  5161. c = 0;
  5162. c = fgetc(fptr1);
  5163. //DEBUG_INFO("c:%d\n",c);
  5164. rewind(fptr1);
  5165. if(c == EOF)
  5166. {
  5167. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5168. TxDefaultProfileFileIsNull=TRUE;
  5169. fclose(fptr1);
  5170. }
  5171. else
  5172. {
  5173. TxDefaultProfileFileIsNull=FALSE;
  5174. while(fscanf(fptr1, "%s", word) != EOF)
  5175. {
  5176. if(strcmp(word, "chargingProfileId") == 0)
  5177. {
  5178. n_chargingProfile = n_chargingProfile + 1;
  5179. printf("Found\n");
  5180. }
  5181. }
  5182. rewind(fptr1);
  5183. //search Charging Profile Element
  5184. int i= 0;
  5185. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5186. #if 0
  5187. /***********connectorId****************/
  5188. c = 0;
  5189. loc = strstr(sLineWord, "connectorId");
  5190. // printf("loc=%s\n",loc);
  5191. memset(sstr ,0, sizeof(sstr) );
  5192. while (loc[strlen("connectorId")+2+c] != ',')
  5193. {
  5194. sstr[c] = loc[strlen("connectorId")+2+c];
  5195. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5196. c++;
  5197. }
  5198. sstr[c] = '\0';
  5199. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5200. tempconnectorIdInt = atoi(sstr);
  5201. #endif
  5202. //***********validFrom**************/
  5203. c = 0;
  5204. loc = strstr(sLineWord, "validFrom");
  5205. //DEBUG_INFO("loc=%s\n",loc);
  5206. memset(sstr ,0, sizeof(sstr) );
  5207. if(loc != NULL)
  5208. {
  5209. while (loc[3+strlen("validFrom")+c] != '\"')
  5210. {
  5211. sstr[c] = loc[3+strlen("validFrom")+c];
  5212. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5213. c++;
  5214. }
  5215. sstr[c] = '\0';
  5216. DEBUG_INFO("validFrom=%s\n",sstr);
  5217. strcpy(tempvalidFromStr,sstr);
  5218. }
  5219. else
  5220. {
  5221. strcpy(tempvalidFromStr,"");
  5222. }
  5223. //**********startSchedule**********/
  5224. c = 0;
  5225. loc = strstr(sLineWord, "startSchedule");
  5226. //DEBUG_INFO("loc=%s\n",loc);
  5227. memset(sstr ,0, sizeof(sstr) );
  5228. if(loc != NULL)
  5229. {
  5230. while (loc[3+strlen("startSchedule")+c] != '\"')
  5231. {
  5232. sstr[c] = loc[3+strlen("startSchedule")+c];
  5233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5234. c++;
  5235. }
  5236. sstr[c] = '\0';
  5237. strcpy(tempstartScheduleStr, sstr);
  5238. strcpy(TxDefaultProfileScheduleStr, sstr);
  5239. }
  5240. else
  5241. {
  5242. strcpy(tempstartScheduleStr, "");
  5243. strcpy(TxDefaultProfileScheduleStr, "");
  5244. }
  5245. //**********chargingRateUnit**********/
  5246. c = 0;
  5247. loc = strstr(sLineWord, "chargingRateUnit");
  5248. memset(sstr ,0, sizeof(sstr) );
  5249. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5250. {
  5251. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5252. c++;
  5253. }
  5254. sstr[c] = '\0';
  5255. strcpy(tempchargingRateUnitStr, sstr);
  5256. //**********minChargingRate*******/
  5257. c = 0;
  5258. loc = strstr(sLineWord, "minChargingRate");
  5259. //printf("loc=%s\n",loc);
  5260. if(loc != NULL)
  5261. {
  5262. memset(sstr ,0, sizeof(sstr) );
  5263. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5264. {
  5265. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5267. c++;
  5268. }
  5269. sstr[c] = '\0';
  5270. tempminChargingRateFloat = atof(sstr);
  5271. }
  5272. else
  5273. {
  5274. tempminChargingRateFloat = 0.0;
  5275. }
  5276. #if 0
  5277. //
  5278. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5279. tp.tm_isdst = -1;
  5280. time_t utc = mktime(&tp);
  5281. // current time
  5282. time_t t = time(NULL);
  5283. //diff_t = difftime(t, utc);
  5284. #endif
  5285. //parsing strings to words
  5286. i = 0;
  5287. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5288. loc = loc+3+strlen("chargingSchedulePeriod");
  5289. pch = strtok(loc ,"{");
  5290. while (pch != NULL)
  5291. {
  5292. strcpy(SchedulePeriodList[i], pch);
  5293. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5294. //printf ("%s\n",pch);
  5295. pch = strtok (NULL, "{");
  5296. i = i + 1;
  5297. }
  5298. n_SchedulePeriods = i;
  5299. for(int i=0;i<n_SchedulePeriods;i++)
  5300. {
  5301. //*************startPeriod****************/
  5302. c = 0;
  5303. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5304. memset(sstr ,0, sizeof(sstr) );
  5305. while (loc[strlen("startPeriod")+2+c] != ',')
  5306. {
  5307. sstr[c] = loc[strlen("startPeriod")+2+c];
  5308. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5309. c++;
  5310. }
  5311. sstr[c] = '\0';
  5312. tempStartPeriodInt = atoi(sstr);
  5313. //*************limit****************/
  5314. c = 0;
  5315. loc = strstr(SchedulePeriodList[i], "limit");
  5316. memset(sstr ,0, sizeof(sstr) );
  5317. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5318. {
  5319. sstr[c] = loc[strlen("limit")+2+c];
  5320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5321. c++;
  5322. }
  5323. sstr[c] = '\0';
  5324. tempLimitInt = atof(sstr);
  5325. //*************numberPhases****************/
  5326. c = 0;
  5327. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5328. memset(sstr ,0, sizeof(sstr) );
  5329. if(loc != NULL)
  5330. {
  5331. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5332. {
  5333. sstr[c] = loc[strlen("numberPhases")+2+c];
  5334. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5335. c++;
  5336. }
  5337. sstr[c] = '\0';
  5338. tempNumberPhasesInt = atoi(sstr);
  5339. }
  5340. else
  5341. {
  5342. tempNumberPhasesInt = 0;
  5343. }
  5344. TxDefaultProfile.Duration = durationInt;
  5345. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5346. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5347. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5348. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5349. }
  5350. if(MinChargingRate < tempminChargingRateFloat)
  5351. MinChargingRate = tempminChargingRateFloat;
  5352. }
  5353. }
  5354. }// the end of ACCESS TxDefaultProfile
  5355. //--------------------- Composite Schedule-----------------------------//
  5356. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5357. {
  5358. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5359. struct tm tp;
  5360. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5361. tp.tm_isdst = -1;
  5362. time_t utc = mktime(&tp);
  5363. time_t t = time(NULL);
  5364. double diff_f = difftime(t, utc);
  5365. int diff_i; //= (int)diff_f;
  5366. int quotient; //= diff_i / 86400;//86400 seconds/day
  5367. int period = 0;
  5368. if(diff_f >= 0)
  5369. {
  5370. diff_i = (int)diff_f;
  5371. quotient = diff_i / 86400;
  5372. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5373. {
  5374. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5375. {
  5376. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5377. {
  5378. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5379. }
  5380. else
  5381. {
  5382. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5383. }
  5384. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5385. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5386. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5387. period = period + 1;
  5388. }
  5389. }
  5390. }
  5391. confirmPeriods = period;
  5392. }
  5393. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5394. {
  5395. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5396. struct tm tp;
  5397. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5398. tp.tm_isdst = -1;
  5399. time_t utc = mktime(&tp);
  5400. time_t t = time(NULL);
  5401. double diff_f = difftime(t, utc);
  5402. int diff_i; // = (int)diff_f;
  5403. int quotient; // = diff_i / 86400;//86400 seconds/day
  5404. int period = 0;
  5405. if(diff_f >= 0)
  5406. {
  5407. diff_i = (int)diff_f;
  5408. quotient = diff_i / 86400;//86400 seconds/day
  5409. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5410. {
  5411. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5412. {
  5413. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5414. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5415. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5416. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5417. period = period + 1;
  5418. }
  5419. }
  5420. }
  5421. confirmPeriods = period;
  5422. }
  5423. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5424. {
  5425. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5426. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5427. {
  5428. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5430. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5431. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5432. }
  5433. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5434. }
  5435. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5436. {
  5437. confirmPeriods = 0;
  5438. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5439. //goto end;
  5440. }
  5441. //* Define temporary variables */
  5442. struct tm *gtime;
  5443. time_t now;
  5444. char buf[28];
  5445. /* Read the current system time */
  5446. time(&now);
  5447. /* Convert the system time to GMT (now UTC) */
  5448. gtime = gmtime(&now);
  5449. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5450. // make .conf
  5451. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5452. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5453. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5454. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5455. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5456. }
  5457. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5458. {
  5459. //*****************************ChargePointMaxProfile******************************************/
  5460. strcpy(fname, ChargePointMaxProfile_JSON);
  5461. ChargePointMaxProfileIsNull=TRUE;
  5462. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5463. {
  5464. fptr1 = fopen(fname, "r");
  5465. int c;
  5466. c = fgetc(fptr1);
  5467. //DEBUG_INFO("c:%d\n",c);
  5468. rewind(fptr1);
  5469. if(c == EOF)
  5470. {
  5471. DEBUG_INFO("\n End of file reached.");
  5472. ChargePointMaxProfileIsNull=TRUE;
  5473. fclose(fptr1);
  5474. }
  5475. else
  5476. {
  5477. ChargePointMaxProfileIsNull=FALSE;
  5478. while(fscanf(fptr1, "%s", word) != EOF)
  5479. {
  5480. if(strcmp(word, "chargingProfileId") == 0)
  5481. {
  5482. n_chargingProfile = n_chargingProfile + 1;
  5483. }
  5484. }
  5485. rewind(fptr1);
  5486. //search Charging Profile Element
  5487. int i = 0;
  5488. int j = 0;
  5489. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5490. #if 0
  5491. /***********connectorId****************/
  5492. c = 0;
  5493. loc = strstr(sLineWord, "connectorId");
  5494. memset(sstr ,0, sizeof(sstr) );
  5495. while (loc[strlen("connectorId")+2+c] != ',')
  5496. {
  5497. sstr[c] = loc[strlen("connectorId")+2+c];
  5498. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5499. c++;
  5500. }
  5501. sstr[c] = '\0';
  5502. tempconnectorIdInt = atoi(sstr);
  5503. #endif
  5504. //***********validFrom**************/
  5505. c = 0;
  5506. loc = strstr(sLineWord, "validFrom");
  5507. if(loc != NULL)
  5508. {
  5509. memset(sstr ,0, sizeof(sstr) );
  5510. while (loc[3+strlen("validFrom")+c] != '\"')
  5511. {
  5512. sstr[c] = loc[3+strlen("validFrom")+c];
  5513. c++;
  5514. }
  5515. sstr[c] = '\0';
  5516. strcpy(tempvalidFromStr,sstr);
  5517. }
  5518. else
  5519. {
  5520. strcpy(tempvalidFromStr,"");
  5521. }
  5522. //***********validFrom**************/
  5523. c = 0;
  5524. loc = strstr(sLineWord, "duration");
  5525. if(loc != NULL)
  5526. {
  5527. memset(sstr ,0, sizeof(sstr) );
  5528. while (loc[2+strlen("duration")+c] != ',')
  5529. {
  5530. sstr[c] = loc[2+strlen("duration")+c];
  5531. c++;
  5532. }
  5533. sstr[c] = '\0';
  5534. tempdurationInt = atoi(sstr);
  5535. }
  5536. else
  5537. {
  5538. tempdurationInt = 0;
  5539. }
  5540. //**********startSchedule**********/
  5541. c = 0;
  5542. loc = strstr(sLineWord, "startSchedule");
  5543. memset(sstr ,0, sizeof(sstr) );
  5544. if(loc != NULL)
  5545. {
  5546. while (loc[3+strlen("startSchedule")+c] != '\"')
  5547. {
  5548. sstr[c] = loc[3+strlen("startSchedule")+c];
  5549. c++;
  5550. }
  5551. sstr[c] = '\0';
  5552. strcpy(tempstartScheduleStr, sstr);
  5553. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5554. }
  5555. else
  5556. {
  5557. strcpy(tempstartScheduleStr, "");
  5558. strcpy(ChargePointMaxProfileScheduleStr, "");
  5559. }
  5560. //**********chargingRateUnit**********/
  5561. c = 0;
  5562. loc = strstr(sLineWord, "chargingRateUnit");
  5563. memset(sstr ,0, sizeof(sstr) );
  5564. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5565. {
  5566. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5567. c++;
  5568. }
  5569. sstr[c] = '\0';
  5570. strcpy(tempchargingRateUnitStr, sstr);
  5571. //**********minChargingRate*******/
  5572. c = 0;
  5573. loc = strstr(sLineWord, "minChargingRate");
  5574. if(loc != NULL)
  5575. {
  5576. memset(sstr ,0, sizeof(sstr) );
  5577. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5578. {
  5579. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5580. c++;
  5581. }
  5582. sstr[c] = '\0';
  5583. tempminChargingRateFloat = atof(sstr);
  5584. }
  5585. else
  5586. {
  5587. tempminChargingRateFloat = 0.0;
  5588. }
  5589. #if 0
  5590. //
  5591. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5592. tp.tm_isdst = -1;
  5593. time_t utc = mktime(&tp);
  5594. time_t t = time(NULL);
  5595. //diff_t = difftime(t, utc);
  5596. #endif
  5597. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5598. //DEBUG_INFO(" debug 5 -1\n");
  5599. //parsing strings to words
  5600. i = 0;
  5601. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5602. loc = loc+3+strlen("chargingSchedulePeriod");
  5603. pch = strtok(loc ,"{");
  5604. while (pch != NULL)
  5605. {
  5606. strcpy(SchedulePeriodList[i], pch);
  5607. pch = strtok (NULL, "{");
  5608. i = i + 1;
  5609. }
  5610. n_SchedulePeriods = i;
  5611. for(int i=0;i<n_SchedulePeriods;i++)
  5612. {
  5613. //*************startPeriod****************/
  5614. c = 0;
  5615. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5616. memset(sstr ,0, sizeof(sstr) );
  5617. while (loc[strlen("startPeriod")+2+c] != ',')
  5618. {
  5619. sstr[c] = loc[strlen("startPeriod")+2+c];
  5620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5621. c++;
  5622. }
  5623. sstr[c] = '\0';
  5624. tempStartPeriodInt = atoi(sstr);
  5625. //*************limit****************/
  5626. c = 0;
  5627. loc = strstr(SchedulePeriodList[i], "limit");
  5628. memset(sstr ,0, sizeof(sstr) );
  5629. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5630. {
  5631. sstr[c] = loc[strlen("limit")+2+c];
  5632. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5633. c++;
  5634. }
  5635. sstr[c] = '\0';
  5636. tempLimitInt = atof(sstr);
  5637. //*************numberPhases****************/
  5638. c = 0;
  5639. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5640. memset(sstr ,0, sizeof(sstr) );
  5641. if(loc != NULL)
  5642. {
  5643. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5644. {
  5645. sstr[c] = loc[strlen("numberPhases")+2+c];
  5646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5647. c++;
  5648. }
  5649. sstr[c] = '\0';
  5650. tempNumberPhasesInt = atoi(sstr);
  5651. }
  5652. else
  5653. {
  5654. tempNumberPhasesInt = 0;
  5655. }
  5656. if(j == 0)
  5657. {
  5658. ChargePointMaxProfile.Duration = tempdurationInt;
  5659. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5660. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5661. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5662. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5663. }
  5664. }
  5665. if(MinChargingRate < tempminChargingRateFloat)
  5666. {
  5667. MinChargingRate = tempminChargingRateFloat;
  5668. }
  5669. if(confirmPeriods < n_SchedulePeriods)
  5670. {
  5671. confirmPeriods = n_SchedulePeriods;
  5672. }
  5673. j = j + 1;
  5674. }
  5675. fclose(fptr1);
  5676. }
  5677. }// the end of access file ChargePointMaxProfile
  5678. //****************************TxDefaultProfile************************************************/
  5679. memset(fname, 0, sizeof fname);
  5680. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5681. TxDefaultProfileFileIsNull=TRUE;
  5682. if((access(fname,F_OK))!=-1)
  5683. {
  5684. fptr1 = fopen(fname, "r");
  5685. c = 0;
  5686. c = fgetc(fptr1);
  5687. //DEBUG_INFO("c:%d\n",c);
  5688. rewind(fptr1);
  5689. if(c == EOF)
  5690. {
  5691. DEBUG_INFO("\n End of file reached.");
  5692. TxDefaultProfileFileIsNull=TRUE;
  5693. fclose(fptr1);
  5694. }
  5695. else
  5696. {
  5697. TxDefaultProfileFileIsNull=FALSE;
  5698. while(fscanf(fptr1, "%s", word) != EOF)
  5699. {
  5700. if(strcmp(word, "chargingProfileId") == 0)
  5701. {
  5702. n_chargingProfile = n_chargingProfile + 1;
  5703. }
  5704. }
  5705. rewind(fptr1);
  5706. //search Charging Profile Element
  5707. int i = 0;
  5708. int j = 0;
  5709. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5710. //DEBUG_INFO(" 1-1\n");
  5711. #if 0
  5712. /***********connectorId****************/
  5713. c = 0;
  5714. loc = strstr(sLineWord, "connectorId");
  5715. memset(sstr ,0, sizeof(sstr) );
  5716. while (loc[strlen("connectorId")+2+c] != ',')
  5717. {
  5718. sstr[c] = loc[strlen("connectorId")+2+c];
  5719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5720. c++;
  5721. }
  5722. sstr[c] = '\0';
  5723. tempconnectorIdInt = atoi(sstr);
  5724. #endif
  5725. //***********validFrom**************/
  5726. c = 0;
  5727. loc = strstr(sLineWord, "validFrom");
  5728. if(loc != NULL)
  5729. {
  5730. memset(sstr ,0, sizeof(sstr) );
  5731. while (loc[3+strlen("validFrom")+c] != '\"')
  5732. {
  5733. sstr[c] = loc[3+strlen("validFrom")+c];
  5734. c++;
  5735. }
  5736. sstr[c] = '\0';
  5737. strcpy(tempvalidFromStr,sstr);
  5738. }
  5739. else
  5740. {
  5741. strcpy(tempvalidFromStr,"");
  5742. }
  5743. //***********duration**************/
  5744. c = 0;
  5745. loc = strstr(sLineWord, "duration");
  5746. if(loc != NULL)
  5747. {
  5748. memset(sstr ,0, sizeof(sstr) );
  5749. while (loc[2+strlen("duration")+c] != ',')
  5750. {
  5751. sstr[c] = loc[2+strlen("duration")+c];
  5752. c++;
  5753. }
  5754. sstr[c] = '\0';
  5755. tempdurationInt = atoi(sstr);
  5756. }
  5757. else
  5758. {
  5759. tempdurationInt = 0;
  5760. }
  5761. //**********startSchedule**********/
  5762. c = 0;
  5763. loc = strstr(sLineWord, "startSchedule");
  5764. memset(sstr ,0, sizeof(sstr) );
  5765. if(loc != NULL)
  5766. {
  5767. while (loc[3+strlen("startSchedule")+c] != '\"')
  5768. {
  5769. sstr[c] = loc[3+strlen("startSchedule")+c];
  5770. c++;
  5771. }
  5772. sstr[c] = '\0';
  5773. strcpy(tempstartScheduleStr, sstr);
  5774. strcpy(TxDefaultProfileScheduleStr, sstr);
  5775. }
  5776. else
  5777. {
  5778. strcpy(tempstartScheduleStr, "");
  5779. strcpy(TxDefaultProfileScheduleStr, "");
  5780. }
  5781. //**********chargingRateUnit**********/
  5782. c = 0;
  5783. loc = strstr(sLineWord, "chargingRateUnit");
  5784. memset(sstr ,0, sizeof(sstr) );
  5785. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5786. {
  5787. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5788. c++;
  5789. }
  5790. sstr[c] = '\0';
  5791. strcpy(tempchargingRateUnitStr, sstr);
  5792. //**********minChargingRate*******/
  5793. c = 0;
  5794. loc = strstr(sLineWord, "minChargingRate");
  5795. if(loc != NULL)
  5796. {
  5797. memset(sstr ,0, sizeof(sstr) );
  5798. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5799. {
  5800. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5801. c++;
  5802. }
  5803. sstr[c] = '\0';
  5804. tempminChargingRateFloat = atof(sstr);
  5805. }
  5806. else
  5807. {
  5808. tempminChargingRateFloat = 0.0;
  5809. }
  5810. #if 0
  5811. //
  5812. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5813. tp.tm_isdst = -1;
  5814. time_t utc = mktime(&tp);
  5815. time_t t = time(NULL);
  5816. //diff_t = difftime(t, utc);
  5817. #endif
  5818. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5819. //parsing strings to words
  5820. i = 0;
  5821. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5822. loc = loc+3+strlen("chargingSchedulePeriod");
  5823. pch = strtok(loc ,"{");
  5824. while (pch != NULL)
  5825. {
  5826. strcpy(SchedulePeriodList[i], pch);
  5827. pch = strtok (NULL, "{");
  5828. i = i + 1;
  5829. }
  5830. n_SchedulePeriods = i;
  5831. for(int i=0;i<n_SchedulePeriods;i++)
  5832. {
  5833. //*************startPeriod****************/
  5834. c = 0;
  5835. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5836. memset(sstr ,0, sizeof(sstr) );
  5837. while (loc[strlen("startPeriod")+2+c] != ',')
  5838. {
  5839. sstr[c] = loc[strlen("startPeriod")+2+c];
  5840. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5841. c++;
  5842. }
  5843. sstr[c] = '\0';
  5844. tempStartPeriodInt = atoi(sstr);
  5845. //*************limit****************/
  5846. c = 0;
  5847. loc = strstr(SchedulePeriodList[i], "limit");
  5848. memset(sstr ,0, sizeof(sstr) );
  5849. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5850. {
  5851. sstr[c] = loc[strlen("limit")+2+c];
  5852. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5853. c++;
  5854. }
  5855. sstr[c] = '\0';
  5856. tempLimitInt = atof(sstr);
  5857. //*************numberPhases****************/
  5858. c = 0;
  5859. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5860. memset(sstr ,0, sizeof(sstr) );
  5861. if(loc != NULL)
  5862. {
  5863. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5864. {
  5865. sstr[c] = loc[strlen("numberPhases")+2+c];
  5866. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. tempNumberPhasesInt = atoi(sstr);
  5871. }
  5872. else
  5873. {
  5874. tempNumberPhasesInt = 0;
  5875. }
  5876. if(j == 0)
  5877. {
  5878. TxDefaultProfile.Duration = tempdurationInt;
  5879. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5880. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5881. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5882. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5883. }
  5884. else
  5885. {
  5886. //other stack level charging Profile
  5887. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5888. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5889. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5890. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5891. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5892. }
  5893. }
  5894. if(MinChargingRate < tempminChargingRateFloat)
  5895. MinChargingRate = tempminChargingRateFloat;
  5896. if(confirmPeriods < n_SchedulePeriods)
  5897. confirmPeriods = n_SchedulePeriods;
  5898. j = j + 1;
  5899. //DEBUG_INFO(" 1-2\n");
  5900. }
  5901. fclose(fptr1);
  5902. //Stacking Charging Profiles
  5903. for(int l=0; l <(j-1) ;l++)
  5904. {
  5905. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5906. {
  5907. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5908. {
  5909. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5910. {
  5911. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5912. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5913. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5914. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5915. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5916. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5917. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5918. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5919. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5920. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5921. }
  5922. else
  5923. {
  5924. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5925. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5926. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5927. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5928. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5929. }
  5930. }
  5931. }
  5932. }
  5933. //end of Stacking Charging Profiles
  5934. }
  5935. }// the end of ACCESS TxDefaultProfile
  5936. //****************************TxProfile************************************************/
  5937. memset(fname, 0, sizeof fname);
  5938. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5939. TxProfileIsNull=TRUE;
  5940. if((access(fname,F_OK))!=-1)
  5941. {
  5942. fptr1 = fopen(fname, "r");
  5943. c = 0;
  5944. c = fgetc(fptr1);
  5945. //DEBUG_INFO("c:%d\n",c);
  5946. rewind(fptr1);
  5947. if(c == EOF)
  5948. {
  5949. DEBUG_INFO("\n End of file reached.");
  5950. TxProfileIsNull=TRUE;
  5951. fclose(fptr1);
  5952. }
  5953. else
  5954. {
  5955. TxProfileIsNull=FALSE;
  5956. while(fscanf(fptr1, "%s", word) != EOF)
  5957. {
  5958. if(strcmp(word, "chargingProfileId") == 0)
  5959. {
  5960. n_chargingProfile = n_chargingProfile + 1;
  5961. }
  5962. }
  5963. rewind(fptr1);
  5964. //search Charging Profile Element
  5965. int i= 0;
  5966. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5967. #if 0
  5968. /***********connectorId****************/
  5969. c = 0;
  5970. loc = strstr(sLineWord, "connectorId");
  5971. memset(sstr ,0, sizeof(sstr) );
  5972. while (loc[strlen("connectorId")+2+c] != ',')
  5973. {
  5974. sstr[c] = loc[strlen("connectorId")+2+c];
  5975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5976. c++;
  5977. }
  5978. sstr[c] = '\0';
  5979. tempconnectorIdInt = atoi(sstr);
  5980. #endif
  5981. //***********validFrom**************/
  5982. c = 0;
  5983. loc = strstr(sLineWord, "validFrom");
  5984. if(loc != NULL)
  5985. {
  5986. memset(sstr ,0, sizeof(sstr) );
  5987. while (loc[3+strlen("validFrom")+c] != '\"')
  5988. {
  5989. sstr[c] = loc[3+strlen("validFrom")+c];
  5990. c++;
  5991. }
  5992. sstr[c] = '\0';
  5993. strcpy(tempvalidFromStr,sstr);
  5994. }
  5995. else
  5996. {
  5997. strcpy(tempvalidFromStr,"");
  5998. }
  5999. //**********startSchedule**********/
  6000. c = 0;
  6001. loc = strstr(sLineWord, "startSchedule");
  6002. memset(sstr ,0, sizeof(sstr) );
  6003. if(loc != NULL)
  6004. {
  6005. while (loc[3+strlen("startSchedule")+c] != '\"')
  6006. {
  6007. sstr[c] = loc[3+strlen("startSchedule")+c];
  6008. c++;
  6009. }
  6010. sstr[c] = '\0';
  6011. strcpy(tempstartScheduleStr, sstr);
  6012. strcpy(TxProfileScheduleStr, sstr);
  6013. }
  6014. else
  6015. {
  6016. strcpy(tempstartScheduleStr, "");
  6017. strcpy(TxProfileScheduleStr, "");
  6018. }
  6019. //**********chargingRateUnit**********/
  6020. c = 0;
  6021. loc = strstr(sLineWord, "chargingRateUnit");
  6022. memset(sstr ,0, sizeof(sstr) );
  6023. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6024. {
  6025. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6026. c++;
  6027. }
  6028. sstr[c] = '\0';
  6029. strcpy(tempchargingRateUnitStr, sstr);
  6030. //**********minChargingRate*******/
  6031. c = 0;
  6032. loc = strstr(sLineWord, "minChargingRate");
  6033. if(loc != NULL)
  6034. {
  6035. memset(sstr ,0, sizeof(sstr) );
  6036. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6037. {
  6038. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6039. c++;
  6040. }
  6041. sstr[c] = '\0';
  6042. tempminChargingRateFloat = atof(sstr);
  6043. }
  6044. else
  6045. {
  6046. tempminChargingRateFloat = 0.0;
  6047. }
  6048. #if 0
  6049. //
  6050. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6051. tp.tm_isdst = -1;
  6052. time_t utc = mktime(&tp);
  6053. time_t t = time(NULL);
  6054. //diff_t = difftime(t, utc);
  6055. #endif
  6056. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6057. //parsing strings to words
  6058. i = 0;
  6059. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6060. loc = loc+3+strlen("chargingSchedulePeriod");
  6061. pch = strtok(loc ,"{");
  6062. while (pch != NULL)
  6063. {
  6064. strcpy(SchedulePeriodList[i], pch);
  6065. pch = strtok (NULL, "{");
  6066. i = i + 1;
  6067. }
  6068. n_SchedulePeriods = i;
  6069. for(int i=0;i<n_SchedulePeriods;i++)
  6070. {
  6071. //*************startPeriod****************/
  6072. c = 0;
  6073. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6074. memset(sstr ,0, sizeof(sstr) );
  6075. while (loc[strlen("startPeriod")+2+c] != ',')
  6076. {
  6077. sstr[c] = loc[strlen("startPeriod")+2+c];
  6078. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6079. c++;
  6080. }
  6081. sstr[c] = '\0';
  6082. tempStartPeriodInt = atoi(sstr);
  6083. //*************limit****************/
  6084. c = 0;
  6085. loc = strstr(SchedulePeriodList[i], "limit");
  6086. memset(sstr ,0, sizeof(sstr) );
  6087. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6088. {
  6089. sstr[c] = loc[strlen("limit")+2+c];
  6090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6091. c++;
  6092. }
  6093. sstr[c] = '\0';
  6094. tempLimitInt = atof(sstr);
  6095. //*************numberPhases****************/
  6096. c = 0;
  6097. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6098. memset(sstr ,0, sizeof(sstr) );
  6099. if(loc != NULL)
  6100. {
  6101. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6102. {
  6103. sstr[c] = loc[strlen("numberPhases")+2+c];
  6104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6105. c++;
  6106. }
  6107. sstr[c] = '\0';
  6108. tempNumberPhasesInt = atoi(sstr);
  6109. }
  6110. else
  6111. {
  6112. tempNumberPhasesInt = 0;
  6113. }
  6114. TxProfile.Duration = durationInt;
  6115. TxProfile.TotalPeriod = n_SchedulePeriods;
  6116. TxProfile.Period[i].Limit = tempLimitInt;
  6117. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6118. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6119. }
  6120. if(MinChargingRate < tempminChargingRateFloat)
  6121. MinChargingRate = tempminChargingRateFloat;
  6122. if(confirmPeriods < n_SchedulePeriods)
  6123. confirmPeriods = n_SchedulePeriods;
  6124. }
  6125. fclose(fptr1);
  6126. }
  6127. }// the end of ACCESS TxProfile
  6128. //CompositeSchedule
  6129. int period=0;
  6130. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6131. {
  6132. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6133. struct tm tp;
  6134. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6135. tp.tm_isdst = -1;
  6136. time_t utc = mktime(&tp);
  6137. time_t t = time(NULL);
  6138. double diff_f = difftime(t, utc);
  6139. int diff_i; // = (int)diff_f;
  6140. int quotient; // = diff_i / 86400;//86400 seconds/day
  6141. //int remainder = diff_i % 86400;
  6142. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6143. {
  6144. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6145. {
  6146. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6147. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6148. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6149. period = period + 1;
  6150. }
  6151. else
  6152. {
  6153. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6154. {
  6155. }
  6156. else
  6157. {
  6158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6159. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6160. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6161. period = period + 1;
  6162. }
  6163. }
  6164. }
  6165. if( diff_f >= 0)
  6166. {
  6167. diff_i = (int)diff_f;
  6168. quotient = diff_i / 86400;//86400 seconds/day
  6169. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6170. {
  6171. 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))
  6172. {
  6173. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6174. {
  6175. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6176. }
  6177. else
  6178. {
  6179. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6180. }
  6181. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6182. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6183. period = period + 1;
  6184. }
  6185. }
  6186. // Check Last Period
  6187. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6188. {
  6189. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6190. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6191. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6192. period = period + 1;
  6193. }
  6194. } // diff_f >= 0
  6195. }
  6196. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6197. {
  6198. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6199. struct tm tp;
  6200. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6201. tp.tm_isdst = -1;
  6202. time_t utc = mktime(&tp);
  6203. time_t t = time(NULL);
  6204. double diff_f = difftime(t, utc);
  6205. int diff_i;// = (int)diff_f;
  6206. int quotient; // = diff_i / 86400;//86400 seconds/day
  6207. //int remainder = diff_i % 86400;
  6208. if(diff_f >= 0)
  6209. {
  6210. diff_i = (int)diff_f;
  6211. quotient = diff_i / 86400;//86400 seconds/day
  6212. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6213. {
  6214. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6215. {
  6216. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6217. {
  6218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6219. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6220. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6221. period = period + 1;
  6222. }
  6223. else
  6224. {
  6225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6226. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6227. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6228. period = period + 1;
  6229. }
  6230. }
  6231. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6232. {
  6233. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6234. {
  6235. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6236. {
  6237. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6238. {
  6239. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6240. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6241. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6242. period = period + 1;
  6243. }
  6244. else
  6245. {
  6246. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6247. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6248. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6249. period = period + 1;
  6250. }
  6251. }
  6252. }
  6253. }
  6254. }
  6255. } // end diff_f >= 0
  6256. }
  6257. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6258. {
  6259. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6260. struct tm tp;
  6261. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6262. tp.tm_isdst = -1;
  6263. time_t utc = mktime(&tp);
  6264. time_t t = time(NULL);
  6265. double diff_f = difftime(t, utc);
  6266. int diff_i; // = (int)diff_f;
  6267. int quotient; // = diff_i / 86400;//86400 seconds/day
  6268. //int remainder = diff_i % 86400;
  6269. if(diff_f >= 0)
  6270. {
  6271. diff_i = (int)diff_f;
  6272. quotient = diff_i / 86400;//86400 seconds/day
  6273. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6274. {
  6275. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6276. {
  6277. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6278. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6279. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6280. period = period + 1;
  6281. }
  6282. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6283. {
  6284. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6285. {
  6286. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6287. {
  6288. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6289. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6290. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6291. period = period + 1;
  6292. }
  6293. }
  6294. }
  6295. }
  6296. } // diff_f >= 0
  6297. }
  6298. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6299. {
  6300. confirmPeriods = 0;
  6301. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6302. //goto end;
  6303. }
  6304. confirmPeriods = period;
  6305. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6306. //---- Define StartSchedule----/
  6307. struct tm *gtime;
  6308. time_t now;
  6309. char buf[28];
  6310. //---Read the current system time---/
  6311. time(&now);
  6312. //---Convert the system time to GMT (now UTC)---/
  6313. gtime = gmtime(&now);
  6314. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6315. // make .conf
  6316. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6317. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6318. //DEBUG_INFO(" debug 11\n");
  6319. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6320. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6321. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6322. }
  6323. else
  6324. {
  6325. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6326. }
  6327. //end:
  6328. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6329. return result;
  6330. }
  6331. int handleGetConfigurationRequest(char *uuid, char *payload)
  6332. {
  6333. mtrace();
  6334. int result = FAIL;
  6335. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6336. //struct json_object *jsonitem;
  6337. int MaxKeySupported = 0;
  6338. int n_keys = 0;
  6339. char requestKey[43][50]={0};
  6340. char search[]="[";
  6341. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6342. //int pos;
  6343. int l, c = 0;
  6344. int i = 0;
  6345. char *delim = "\",\"";
  6346. char * pch;
  6347. strcpy(sstrtemp, stringtrimspace(payload));
  6348. char *loc = strstr(sstrtemp, search);
  6349. //********************* Parsing String ***********************************/
  6350. if(loc == NULL) {
  6351. DEBUG_INFO("no key match in Configuration \n");
  6352. }
  6353. else {
  6354. //pos = loc - payload;
  6355. l = strlen(loc)-4;
  6356. while (c < l)
  6357. {
  6358. sstr[c] = loc[c+2];
  6359. c++;
  6360. }
  6361. sstr[c] = '\0';
  6362. //parsing strings to words
  6363. pch = strtok(sstr,delim);
  6364. if(pch == NULL)
  6365. {
  6366. strcpy(requestKey[0], sstr);
  6367. }
  6368. else
  6369. {
  6370. while (pch != NULL)
  6371. {
  6372. strcpy(requestKey[i], pch);
  6373. pch = strtok (NULL, delim);
  6374. i = i + 1;
  6375. }
  6376. n_keys = i;
  6377. }
  6378. }
  6379. UnknownKeynum = 0;
  6380. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6381. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6382. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6383. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6384. if(n_keys != 0)
  6385. {
  6386. for(int i=0;i<n_keys;i++)
  6387. {
  6388. getKeyValue(requestKey[i]);
  6389. //json_object_put(jsonitem);
  6390. }
  6391. }
  6392. else
  6393. {
  6394. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6395. getKeyValue("");
  6396. }
  6397. processUnkownKey();
  6398. sendGetConfigurationConfirmation(uuid);
  6399. return result;
  6400. }
  6401. static char fnamePlusPath[100]={0};
  6402. static char fnamePWithNoPath[60]={0};
  6403. void checkUploadLog(void)
  6404. {
  6405. FILE *fp;
  6406. /* Open the command for reading. */
  6407. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6408. if (fp == NULL) {
  6409. printf("Failed to run command\n" );
  6410. exit(1);
  6411. }
  6412. int ftppathlen = 0;
  6413. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6414. int i = 0;
  6415. /* Read the output a line at a time - output it. */
  6416. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6417. if(i==0)
  6418. {
  6419. ftppathlen = strlen(fnamePlusPath);
  6420. printf("%s\n", fnamePlusPath);
  6421. fnamePlusPath[ftppathlen]='\0';
  6422. break;
  6423. }
  6424. i= i+1;
  6425. }
  6426. /* close */
  6427. pclose(fp);
  6428. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6429. {
  6430. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6431. {
  6432. fnamePlusPath[k]='\0';
  6433. }
  6434. }
  6435. i=1;
  6436. //char fname[60]={0};
  6437. while(i < ftppathlen)
  6438. {
  6439. int len=ftppathlen-i;
  6440. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6441. {
  6442. printf("compare '/' all right\n");
  6443. break;
  6444. }
  6445. i=i+1;
  6446. }
  6447. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6448. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6449. fnamePWithNoPath[i+1] = '\0';
  6450. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6451. {
  6452. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6453. {
  6454. fnamePWithNoPath[j]='\0';
  6455. }
  6456. }
  6457. FILE* fp1 = fopen(fnamePlusPath, "r");
  6458. if (fp1)
  6459. {
  6460. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6461. // file exists
  6462. fclose(fp1);
  6463. }
  6464. else
  6465. {
  6466. // file doesn't exist
  6467. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6468. }
  6469. }
  6470. static char GetDiagnosticspayloadData[300]={0};
  6471. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6472. {
  6473. mtrace();
  6474. int result = FAIL;
  6475. pthread_t t; // pthread 變數
  6476. system("exec /root/logPackTools 'log' 6");
  6477. #if 0
  6478. //char buffer [128];
  6479. time (&rawtime);
  6480. //printf("%ld\n", rawtime);
  6481. timeinfo = localtime (&rawtime);
  6482. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6483. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6484. if((access(fnamePlusPath,F_OK))!=-1)
  6485. {
  6486. DEBUG_INFO("fnamePlusPath exist.\n");
  6487. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6488. }
  6489. else
  6490. {
  6491. DEBUG_INFO("fnamePlusPath not exist!\n");
  6492. }
  6493. #endif
  6494. checkUploadLog();
  6495. memset(GetDiagnosticspayloadData, 0, 300);
  6496. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6497. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6498. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6499. return result;
  6500. }
  6501. void* GetDiagnosticsProcess(void* data)
  6502. {
  6503. pthread_detach(pthread_self());
  6504. mtrace();
  6505. int retriesInt=0, retryIntervalInt=0;
  6506. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6507. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6508. 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};
  6509. int port=0;
  6510. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6511. int c = 0;
  6512. char *loc;
  6513. int isSuccess = FALSE;
  6514. char ftpbuf[200]={0};
  6515. //char temp[100]={0};
  6516. char * pch;
  6517. // [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"}]
  6518. char str[300]={ 0 };
  6519. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6520. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6521. DEBUG_INFO("GetDiagnosticsProcess\n");
  6522. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6523. //****************location*******************/
  6524. c = 0;
  6525. memset(sstr ,0, sizeof(sstr) );
  6526. loc = strstr(str, "location");
  6527. while (loc[3+strlen("location")+c] != '\"')
  6528. {
  6529. sstr[c] = loc[3+strlen("location")+c];
  6530. c++;
  6531. }
  6532. sstr[c] = '\0';
  6533. strcpy(locationstr,sstr);
  6534. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6535. if(strcmp(locationstr,"")==0)
  6536. {
  6537. DEBUG_INFO("location is <Empty>!\n");
  6538. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6539. goto end;
  6540. }
  6541. //****************retries*******************/
  6542. c = 0;
  6543. loc = strstr(str, "retries");
  6544. if(loc == NULL)
  6545. {
  6546. retriesIsNULL = TRUE;
  6547. }
  6548. else
  6549. {
  6550. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6551. {
  6552. sstr[c] = loc[strlen("retries")+2+c];
  6553. c++;
  6554. }
  6555. sstr[c] = '\0';
  6556. retriesInt = atoi(sstr);
  6557. }
  6558. if(retriesIsNULL == TRUE)
  6559. {
  6560. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6561. }
  6562. //****************retryInterval*******************/
  6563. c = 0;
  6564. loc = strstr(str, "retryInterval");
  6565. if(loc == NULL)
  6566. {
  6567. retryIntervalIsNULL = TRUE;
  6568. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6569. }
  6570. else
  6571. {
  6572. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6573. {
  6574. sstr[c] = loc[strlen("retryInterval")+2+c];
  6575. c++;
  6576. }
  6577. sstr[c] = '\0';
  6578. retryIntervalInt = atoi(sstr);
  6579. }
  6580. //****************startTime*******************/
  6581. c = 0;
  6582. memset(sstr ,0, sizeof(sstr) );
  6583. loc = strstr(str, "startTime");
  6584. if(loc == NULL)
  6585. {
  6586. startTimeIsNULL = TRUE;
  6587. }
  6588. else
  6589. {
  6590. while (loc[3+strlen("startTime")+c] != '\"')
  6591. {
  6592. sstr[c] = loc[3+strlen("startTime")+c];
  6593. c++;
  6594. }
  6595. sstr[c] = '\0';
  6596. strcpy(startTimestr,sstr);
  6597. }
  6598. //****************stopTime*******************/
  6599. c = 0;
  6600. memset(sstr ,0, sizeof(sstr) );
  6601. loc = strstr(str, "stopTime");
  6602. if(loc == NULL)
  6603. {
  6604. stopTimeIsNULL = TRUE;
  6605. }
  6606. else
  6607. {
  6608. while (loc[3+strlen("stopTime")+c] != '\"')
  6609. {
  6610. sstr[c] = loc[3+strlen("stopTime")+c];
  6611. c++;
  6612. }
  6613. sstr[c] = '\0';
  6614. strcpy(stopTimestr,sstr);
  6615. }
  6616. memset(protocol, 0, sizeof(protocol));
  6617. memset(user, 0, sizeof(user) );
  6618. memset(password, 0, sizeof(password));
  6619. memset(host, 0, sizeof(host));
  6620. memset(path, 0, sizeof(path));
  6621. memset(ftppath, 0, sizeof(ftppath));
  6622. memset(host1, 0, sizeof(host1));
  6623. memset(path1, 0, sizeof(path1));
  6624. /*location: ftp://user:password@host:port/path*/
  6625. #if 0
  6626. time_t rawtime;
  6627. struct tm * timeinfo;
  6628. //char buffer [128];
  6629. time (&rawtime);
  6630. //printf("%ld\n", rawtime);
  6631. timeinfo = localtime (&rawtime);
  6632. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6633. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6634. #endif
  6635. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6636. if((access(fnamePlusPath,F_OK))!=-1)
  6637. {
  6638. DEBUG_INFO("fnamePlusPath exist.\n");
  6639. }
  6640. else
  6641. {
  6642. DEBUG_INFO("fnamePlusPath not exist!\n");
  6643. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6644. goto end;
  6645. }
  6646. pch=strchr(locationstr,'@');
  6647. if(pch==NULL)
  6648. {
  6649. sscanf(locationstr,
  6650. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6651. protocol, host, &port, path);
  6652. strcpy(user,"anonymous");
  6653. strcpy(password,"");
  6654. }
  6655. else
  6656. {
  6657. //DEBUG_INFO("pch=%s\n", pch);
  6658. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6659. protocol, user, password, host, &port, path);
  6660. }
  6661. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6662. {
  6663. DEBUG_INFO("protocol is not ftp/http ! \n");
  6664. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6665. goto end;
  6666. }
  6667. if(strncmp(locationstr,"http", 4) == 0)
  6668. {
  6669. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6670. sprintf(ftppath,"/%s", path);
  6671. do{
  6672. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6673. sleep(retryIntervalInt);
  6674. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6675. if(!isSuccess)
  6676. {
  6677. DEBUG_INFO("Diagnostics fail.\n");
  6678. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6679. }
  6680. else
  6681. {
  6682. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6683. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6684. }
  6685. }
  6686. else
  6687. {
  6688. sscanf(host,"%[^/]%s",host1, path1);
  6689. sprintf(ftppath,"%s", path1);
  6690. int ftppathlen=strlen(ftppath);
  6691. int i=1;
  6692. char filenametemp[50];
  6693. while(i < ftppathlen)
  6694. {
  6695. int len=ftppathlen-i;
  6696. if(ftppath[len]== 47) // '/' ascll code: 47
  6697. {
  6698. DEBUG_INFO("find '/' all right\n");
  6699. break;
  6700. }
  6701. i=i+1;
  6702. }
  6703. memset(filenametemp, 0, sizeof(filenametemp));
  6704. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6705. filenametemp[i+1] = 0;
  6706. memset(ftpbuf, 0, sizeof(ftpbuf));
  6707. if(port == 0)
  6708. port = 21;
  6709. do{
  6710. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6711. sleep(retryIntervalInt);
  6712. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6713. if(!isSuccess)
  6714. {
  6715. DEBUG_INFO("Diagnostics fail.\n");
  6716. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6717. }
  6718. else
  6719. {
  6720. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6721. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6722. }
  6723. }
  6724. end:
  6725. DiagnosticsStatusNotificationStatus = 0; //Idle
  6726. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6727. }
  6728. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6729. {
  6730. mtrace();
  6731. int result = FAIL;
  6732. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6733. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6734. {
  6735. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6736. localversion = -1;
  6737. }
  6738. else
  6739. {
  6740. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6741. OCPP_getListVerion();
  6742. }
  6743. //from db.OCPP_getListVerion
  6744. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6745. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6746. sendGetLocalListVersionConfirmation(uuid,"");
  6747. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6748. return result;
  6749. }
  6750. int handleRemoteStartRequest(char *uuid, char *payload)
  6751. {
  6752. mtrace();
  6753. int result = FAIL;
  6754. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6755. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6756. int tempIndex = 0;
  6757. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6758. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6759. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6760. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6761. int chargingSchedulePeriodCount = 0;
  6762. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6763. int c = 0;
  6764. char *loc;
  6765. char comfirmstr[20]={0};
  6766. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6767. if(server_pending == TRUE)
  6768. {
  6769. return 0;
  6770. }
  6771. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6772. strcpy(sstrtemp, stringtrimspace(payload));
  6773. //**********connectorId****************/
  6774. c = 0;
  6775. memset(sstr ,0, sizeof(sstr) );
  6776. loc = strstr(sstrtemp, "connectorId");
  6777. if(loc == NULL)
  6778. {
  6779. connectorIdIsNULL = TRUE;
  6780. }
  6781. else
  6782. {
  6783. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6784. {
  6785. sstr[c] = loc[strlen("connectorId")+2+c];
  6786. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6787. c++;
  6788. }
  6789. sstr[c] = '\0';
  6790. connectorIdInt = atoi(sstr);
  6791. }
  6792. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6793. {
  6794. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6795. goto end;
  6796. }
  6797. //****************idTag*******************/
  6798. c = 0;
  6799. memset(sstr ,0, sizeof(sstr) );
  6800. loc = strstr(sstrtemp, "idTag");
  6801. while (loc[3+strlen("idTag")+c] != '\"')
  6802. {
  6803. sstr[c] = loc[3+strlen("idTag")+c];
  6804. c++;
  6805. }
  6806. sstr[c] = '\0';
  6807. strcpy(idTagstr,sstr);
  6808. //****************chargingProfile*******************/
  6809. c = 0;
  6810. memset(sstr ,0, sizeof(sstr) );
  6811. loc = strstr(sstrtemp, "chargingProfile");
  6812. if(loc == NULL)
  6813. {
  6814. chargingProfileIsNULL = TRUE;
  6815. }
  6816. else
  6817. {
  6818. //****************chargingProfileId*******************/
  6819. c=0;
  6820. loc = strstr(sstrtemp, "chargingProfileId");
  6821. memset(sstr ,0, sizeof(sstr) );
  6822. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6823. {
  6824. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6826. c++;
  6827. }
  6828. sstr[c] = '\0';
  6829. chargingProfileIdInt = atoi(sstr);
  6830. //****************transactionId*******************/
  6831. loc = strstr(sstrtemp, "transactionId");
  6832. if(loc == NULL)
  6833. {
  6834. transactionIdIsNULL = TRUE;
  6835. }
  6836. else
  6837. {
  6838. c=0;
  6839. memset(sstr ,0, sizeof(sstr) );
  6840. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6841. {
  6842. sstr[c] = loc[strlen("transactionId")+2+c];
  6843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6844. c++;
  6845. }
  6846. sstr[c] = '\0';
  6847. transactionIdInt = atoi(sstr);
  6848. }
  6849. //****************stackLevel*******************/
  6850. c=0;
  6851. loc = strstr(sstrtemp, "stackLevel");
  6852. memset(sstr ,0, sizeof(sstr) );
  6853. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6854. {
  6855. sstr[c] = loc[strlen("stackLevel")+2+c];
  6856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6857. c++;
  6858. }
  6859. sstr[c] = '\0';
  6860. stackLevelInt = atoi(sstr);
  6861. //****************chargingProfilePurpose*******************/
  6862. c = 0;
  6863. memset(sstr ,0, sizeof(sstr) );
  6864. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6865. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6866. {
  6867. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6868. c++;
  6869. }
  6870. sstr[c] = '\0';
  6871. strcpy(chargingProfilePurposestr,sstr);
  6872. //****************chargingProfileKind*******************/
  6873. c = 0;
  6874. memset(sstr ,0, sizeof(sstr) );
  6875. loc = strstr(sstrtemp, "chargingProfileKind");
  6876. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6877. {
  6878. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6879. c++;
  6880. }
  6881. sstr[c] = '\0';
  6882. strcpy(chargingProfileKindstr,sstr);
  6883. //****************recurrencyKind*******************/
  6884. loc = strstr(sstrtemp, "recurrencyKind");
  6885. if(loc == NULL)
  6886. {
  6887. recurrencyKindIsNULL = TRUE;
  6888. }
  6889. else
  6890. {
  6891. c = 0;
  6892. memset(sstr ,0, sizeof(sstr) );
  6893. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6894. {
  6895. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6896. c++;
  6897. }
  6898. sstr[c] = '\0';
  6899. strcpy(recurrencyKindstr,sstr);
  6900. }
  6901. //****************validFrom*******************/
  6902. loc = strstr(sstrtemp, "validFrom");
  6903. if(loc == NULL)
  6904. {
  6905. validFromIsNULL = TRUE;
  6906. }
  6907. else
  6908. {
  6909. c = 0;
  6910. memset(sstr ,0, sizeof(sstr) );
  6911. while (loc[3+strlen("validFrom")+c] != '\"')
  6912. {
  6913. sstr[c] = loc[3+strlen("validFrom")+c];
  6914. c++;
  6915. }
  6916. sstr[c] = '\0';
  6917. strcpy(validFromstr,sstr);
  6918. }
  6919. //****************validTo*******************/
  6920. loc = strstr(sstrtemp, "validTo");
  6921. if(loc == NULL)
  6922. {
  6923. validToIsNULL = TRUE;
  6924. }
  6925. else
  6926. {
  6927. c = 0;
  6928. memset(sstr ,0, sizeof(sstr) );
  6929. while (loc[3+strlen("validTo")+c] != '\"')
  6930. {
  6931. sstr[c] = loc[3+strlen("validTo")+c];
  6932. c++;
  6933. }
  6934. sstr[c] = '\0';
  6935. strcpy(validTostr,sstr);
  6936. }
  6937. //****************chargingSchedule*******************/
  6938. loc = strstr(sstrtemp, "chargingSchedule");
  6939. if(loc != NULL)
  6940. {
  6941. //****************duration*******************/
  6942. loc = strstr(sstrtemp, "duration");
  6943. if(loc == NULL)
  6944. {
  6945. durationIsNULL = TRUE;
  6946. }
  6947. else
  6948. {
  6949. c=0;
  6950. memset(sstr ,0, sizeof(sstr) );
  6951. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6952. {
  6953. sstr[c] = loc[strlen("duration")+2+c];
  6954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6955. c++;
  6956. }
  6957. sstr[c] = '\0';
  6958. durationInt = atoi(sstr);
  6959. }
  6960. //****************startSchedule******************/
  6961. loc = strstr(sstrtemp, "startSchedule");
  6962. if(loc == NULL)
  6963. {
  6964. startScheduleIsNULL = TRUE;
  6965. }
  6966. else
  6967. {
  6968. c = 0;
  6969. memset(sstr ,0, sizeof(sstr) );
  6970. while (loc[3+strlen("startSchedule")+c] != '\"')
  6971. {
  6972. sstr[c] = loc[3+strlen("startSchedule")+c];
  6973. c++;
  6974. }
  6975. sstr[c] = '\0';
  6976. strcpy(startSchedulestr,sstr);
  6977. }
  6978. //****************chargingRateUnit*******************/
  6979. c = 0;
  6980. memset(sstr ,0, sizeof(sstr) );
  6981. loc = strstr(sstrtemp, "chargingRateUnit");
  6982. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6983. {
  6984. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6985. c++;
  6986. }
  6987. sstr[c] = '\0';
  6988. strcpy(chargingRateUnitstr,sstr);
  6989. //****************minChargingRate*******************/
  6990. loc = strstr(sstrtemp, "minChargingRate");
  6991. if(loc == NULL)
  6992. {
  6993. minChargingRateIsNULL = TRUE;
  6994. }
  6995. else
  6996. {
  6997. c=0;
  6998. memset(sstr ,0, sizeof(sstr) );
  6999. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7000. {
  7001. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. minChargingRateflaot = atof(sstr);
  7007. }
  7008. //****************chargingSchedulePeriod count*******************/
  7009. int what_len = strlen("startPeriod");
  7010. char *where = sstrtemp;
  7011. while ((where = strstr(where, "startPeriod"))) {
  7012. where += what_len;
  7013. chargingSchedulePeriodCount++;
  7014. }
  7015. where = sstrtemp;
  7016. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7017. {
  7018. //****************startPeriod*******************/
  7019. c=0;
  7020. loc = strstr(where, "startPeriod");
  7021. memset(sstr ,0, sizeof(sstr) );
  7022. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7023. {
  7024. sstr[c] = loc[strlen("startPeriod")+2+c];
  7025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7026. c++;
  7027. }
  7028. sstr[c] = '\0';
  7029. startPeriodInt[periodNums] = atoi(sstr);
  7030. //****************limit*******************/
  7031. c=0;
  7032. loc = strstr(where, "limit");
  7033. memset(sstr ,0, sizeof(sstr) );
  7034. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7035. {
  7036. sstr[c] = loc[strlen("limit")+2+c];
  7037. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7038. c++;
  7039. }
  7040. sstr[c] = '\0';
  7041. limitflaot[periodNums] = atof(sstr);
  7042. //****************numberPhases*******************/
  7043. loc = strstr(where, "numberPhases");
  7044. if(loc == NULL)
  7045. {
  7046. numberPhasesIsNULL = TRUE;
  7047. }
  7048. else
  7049. {
  7050. c=0;
  7051. memset(sstr ,0, sizeof(sstr) );
  7052. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7053. {
  7054. sstr[c] = loc[strlen("numberPhases")+2+c];
  7055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7056. c++;
  7057. }
  7058. sstr[c] = '\0';
  7059. numberPhasesInt[periodNums] = atoi(sstr);
  7060. }
  7061. where = loc;
  7062. } // END FOR chargingSchedulePeriodCount
  7063. }// END IF chargingSchedule
  7064. } // END chargingProfile
  7065. /*
  7066. enum _SYSTEM_STATUS
  7067. {
  7068. S_BOOTING = 0,
  7069. S_IDLE, = 1
  7070. S_AUTHORIZING, =2
  7071. S_REASSIGN_CHECK, =3
  7072. S_REASSIGN, =4
  7073. S_PRECHARGE, =5
  7074. S_PREPARING_FOR_EV, =6
  7075. S_PREPARING_FOR_EVSE, =7
  7076. S_CHARGING, =8
  7077. S_TERMINATING, =9
  7078. S_COMPLETE, =10
  7079. S_ALARM, =11
  7080. S_FAULT =12
  7081. }
  7082. */
  7083. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7084. {
  7085. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7086. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7087. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7088. //check Transaction active
  7089. if(gunType[connectorIdInt -1] == 'J')
  7090. {
  7091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7092. {
  7093. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7094. }
  7095. else
  7096. {
  7097. tempIndex = connectorIdInt -1;
  7098. }
  7099. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7100. {
  7101. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7102. {
  7103. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7104. {
  7105. //Reserved
  7106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7107. }
  7108. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7109. {
  7110. //Reserved
  7111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7113. goto end;
  7114. }
  7115. else
  7116. {
  7117. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7118. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7119. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7120. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7121. {
  7122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7123. goto end;
  7124. }
  7125. }//END FOR ELSE
  7126. }
  7127. }// END FOR CHAdeMO_QUANTITY
  7128. }
  7129. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7130. {
  7131. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7132. {
  7133. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7134. }
  7135. else
  7136. {
  7137. tempIndex = connectorIdInt -1;
  7138. }
  7139. for (int index = 0; index < CCS_QUANTITY; index++)
  7140. {
  7141. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7142. {
  7143. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7144. {
  7145. //Reserved
  7146. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7147. }
  7148. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7149. {
  7150. //Reserved
  7151. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7152. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7153. goto end;
  7154. }
  7155. else
  7156. {
  7157. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7158. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7159. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7160. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7161. {
  7162. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7163. goto end;
  7164. }
  7165. }// END FOR ELSE
  7166. }
  7167. }// END FOR CCS_QUANTITY
  7168. }
  7169. else if(gunType[connectorIdInt -1] == 'G')
  7170. {
  7171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7172. {
  7173. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7174. }
  7175. else
  7176. {
  7177. tempIndex = connectorIdInt -1;
  7178. }
  7179. for (int index = 0; index < GB_QUANTITY; index++)
  7180. {
  7181. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7182. {
  7183. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7184. {
  7185. //Reserved
  7186. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7187. }
  7188. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7189. {
  7190. //Reserved
  7191. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7192. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7193. goto end;
  7194. }
  7195. else
  7196. {
  7197. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7198. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7199. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7200. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7201. {
  7202. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7203. goto end;
  7204. }
  7205. }// END FOR ELSE
  7206. }
  7207. } // END FOR GB_QUANTITY
  7208. }
  7209. else
  7210. {
  7211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7212. {
  7213. tempIndex = 2;
  7214. }
  7215. else
  7216. {
  7217. tempIndex = connectorIdInt -1;
  7218. }
  7219. for (int index = 0; index < AC_QUANTITY; index++)
  7220. {
  7221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7222. {
  7223. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7224. {
  7225. //Reserved
  7226. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7227. }
  7228. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7229. {
  7230. //Reserved
  7231. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7232. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7233. goto end;
  7234. }
  7235. else
  7236. {
  7237. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7238. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7239. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7240. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7241. {
  7242. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7243. goto end;
  7244. }
  7245. }//END FOR ELSE
  7246. }
  7247. }// END FOR AC_QUANTITY
  7248. }
  7249. if(chargingProfileIsNULL == FALSE)
  7250. {
  7251. //ChargingProfile
  7252. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7253. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7254. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7255. if(recurrencyKindIsNULL == FALSE) //OPTION
  7256. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7258. if(transactionIdIsNULL == FALSE) // OPTION
  7259. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7260. if(validFromIsNULL == FALSE) // OPTION
  7261. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7262. if(validToIsNULL == FALSE) //OPTION
  7263. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7264. //ChargingSchedule
  7265. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7266. if(durationIsNULL == FALSE) //OPTION
  7267. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7268. if(minChargingRateIsNULL == FALSE) //OPTION
  7269. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7270. if(startScheduleIsNULL == FALSE) //OPTION
  7271. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7272. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7273. {
  7274. //ChargingSchedulePeriod
  7275. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7276. if(numberPhasesIsNULL == FALSE)
  7277. {
  7278. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7279. }
  7280. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7281. }
  7282. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7283. {
  7284. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7285. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7286. //memset idTag
  7287. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7288. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7289. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7290. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7291. }
  7292. else
  7293. {
  7294. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7295. }
  7296. }
  7297. else
  7298. {
  7299. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7300. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7301. //memset idTag
  7302. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7303. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7304. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7305. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7306. }
  7307. }
  7308. else
  7309. {
  7310. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7311. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7312. }
  7313. end:
  7314. if(connectorIdIsNULL == FALSE)
  7315. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7316. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7317. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7318. //OCPP send RemoteStartConfirmation by first.
  7319. sendRemoteStartConfirmation(uuid, comfirmstr);
  7320. return result;
  7321. }
  7322. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7323. {
  7324. mtrace();
  7325. int result = FAIL;
  7326. int match = FALSE;
  7327. int GunNO = 0;
  7328. int tempIndex = 0;
  7329. int transactionIdInt=0;
  7330. int transactionIdIsNULL= FALSE;
  7331. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7332. int c = 0;
  7333. char *loc;
  7334. char comfirmstr[20];
  7335. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7336. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7337. if(server_pending == TRUE)
  7338. {
  7339. return 0;
  7340. }
  7341. strcpy(sstrtemp, stringtrimspace(payload));
  7342. c=0;
  7343. loc = strstr(sstrtemp, "transactionId");
  7344. if(loc == NULL)
  7345. {
  7346. transactionIdIsNULL= TRUE;
  7347. }
  7348. else
  7349. {
  7350. memset(sstr ,0, sizeof(sstr) );
  7351. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7352. {
  7353. sstr[c] = loc[strlen("transactionId")+2+c];
  7354. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7355. c++;
  7356. }
  7357. sstr[c] = '\0';
  7358. transactionIdInt = atoi(sstr);
  7359. }
  7360. if(transactionIdIsNULL == FALSE)
  7361. {
  7362. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7363. {
  7364. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7365. {
  7366. //check Transaction active
  7367. if(gunType[gun_index] == 'J')
  7368. {
  7369. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7370. {
  7371. tempIndex = ((gun_index==2) ? 1: 0);
  7372. }
  7373. else
  7374. {
  7375. tempIndex = gun_index;
  7376. }
  7377. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7378. {
  7379. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7380. {
  7381. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7382. {
  7383. match = TRUE;
  7384. GunNO = gun_index;
  7385. }
  7386. }
  7387. }// END FOR CHAdeMO_QUANTITY
  7388. }
  7389. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7390. {
  7391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7392. {
  7393. tempIndex = ((gun_index==2) ? 1: 0);
  7394. }
  7395. else
  7396. {
  7397. tempIndex = gun_index;
  7398. }
  7399. for (int index = 0; index < CCS_QUANTITY; index++)
  7400. {
  7401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7402. {
  7403. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7404. {
  7405. match = TRUE;
  7406. GunNO = gun_index;
  7407. }
  7408. }
  7409. }// END FOR CCS_QUANTITY
  7410. }
  7411. else if(gunType[gun_index] == 'G')
  7412. {
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7414. {
  7415. tempIndex = ((gun_index==2) ? 1: 0);
  7416. }
  7417. else
  7418. {
  7419. tempIndex = gun_index;
  7420. }
  7421. for (int index = 0; index < GB_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7424. {
  7425. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7426. {
  7427. match = TRUE;
  7428. GunNO = gun_index;
  7429. }
  7430. }
  7431. }// END FOR GB_QUANTITY
  7432. }
  7433. else
  7434. {
  7435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7436. {
  7437. tempIndex = 2;
  7438. }
  7439. else
  7440. {
  7441. tempIndex = gun_index;
  7442. }
  7443. for (int index = 0; index < AC_QUANTITY; index++)
  7444. {
  7445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7446. {
  7447. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7448. {
  7449. match = TRUE;
  7450. GunNO = gun_index;
  7451. }
  7452. }
  7453. }// END FOR CHAdeMO_QUANTITY
  7454. } // END FOR AC ELSE
  7455. }// CHECK IF ResponseTransactionId == transactionIdInt
  7456. }//END FOR
  7457. if( match == TRUE)
  7458. {
  7459. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7460. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7461. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7462. }
  7463. else
  7464. {
  7465. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7466. }
  7467. }
  7468. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7469. return result;
  7470. }
  7471. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7472. {
  7473. mtrace();
  7474. int result = FAIL;
  7475. int connectorIdInt=0, reservationIdInt=0;
  7476. int tempIndex = 0;
  7477. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7478. char comfirmstr[20]={0};
  7479. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7480. int c = 0;
  7481. char *loc;
  7482. //char *ptr;
  7483. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7484. strcpy(sstrtemp, stringtrimspace(payload));
  7485. //***(1)connectorId ****/
  7486. c=0;
  7487. loc = strstr(sstrtemp, "connectorId");
  7488. memset(sstr ,0, sizeof(sstr) );
  7489. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7490. {
  7491. sstr[c] = loc[strlen("connectorId")+2+c];
  7492. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7493. c++;
  7494. }
  7495. sstr[c] = '\0';
  7496. connectorIdInt = atoi(sstr);
  7497. //***(2)expiryDate ****/
  7498. loc = strstr(sstrtemp, "expiryDate");
  7499. memset(sstr ,0, sizeof(sstr) );
  7500. c = 0;
  7501. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7502. {
  7503. sstr[c] = loc[3+strlen("expiryDate")+c];
  7504. c++;
  7505. }
  7506. sstr[c] = '\0';
  7507. strcpy(expiryDatestr, sstr);
  7508. //***(3)idTag ****/
  7509. loc = strstr(sstrtemp, "idTag");
  7510. memset(sstr ,0, sizeof(sstr) );
  7511. c = 0;
  7512. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7513. {
  7514. sstr[c] = loc[3+strlen("idTag")+c];
  7515. c++;
  7516. }
  7517. sstr[c] = '\0';
  7518. strcpy(idTagstr, sstr);
  7519. //***(4)parentIdTag ****/
  7520. loc = strstr(sstrtemp, "parentIdTag");
  7521. memset(sstr ,0, sizeof(sstr) );
  7522. c = 0;
  7523. if(loc == NULL)
  7524. {
  7525. strcpy(parentIdTagstr, "");
  7526. }
  7527. else
  7528. {
  7529. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7530. {
  7531. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7532. c++;
  7533. }
  7534. sstr[c] = '\0';
  7535. strcpy(parentIdTagstr, sstr);
  7536. }
  7537. //***(5)reservationId ****/
  7538. c=0;
  7539. loc = strstr(sstrtemp, "reservationId");
  7540. memset(sstr ,0, sizeof(sstr) );
  7541. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7542. {
  7543. sstr[c] = loc[strlen("reservationId")+2+c];
  7544. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7545. c++;
  7546. }
  7547. sstr[c] = '\0';
  7548. reservationIdInt = atoi(sstr);
  7549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7550. /*
  7551. enum SYSTEM_STATUS
  7552. {
  7553. SYS_MODE_BOOTING = 0,
  7554. SYS_MODE_IDLE = 1,
  7555. SYS_MODE_AUTHORIZING = 2,
  7556. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7557. SYS_MODE_REASSIGN = 4,
  7558. SYS_MODE_PREPARING = 5,
  7559. SYS_MODE_PREPARE_FOR_EV = 6,
  7560. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7561. SYS_MODE_CHARGING = 8,
  7562. SYS_MODE_TERMINATING = 9,
  7563. SYS_MODE_COMPLETE = 10,
  7564. SYS_MODE_ALARM = 11,
  7565. SYS_MODE_FAULT = 12,
  7566. SYS_MODE_RESERVATION = 13,
  7567. SYS_MODE_BOOKING = 14,
  7568. SYS_MODE_MAINTAIN = 15,
  7569. SYS_MODE_DEBUG = 16,
  7570. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7571. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7572. SYS_MODE_UPDATE = 19
  7573. };
  7574. */
  7575. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7576. {
  7577. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7578. goto end;
  7579. }
  7580. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7581. {
  7582. //check Transaction active
  7583. if(gunType[connectorIdInt -1] == 'J')
  7584. {
  7585. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7586. {
  7587. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7588. }
  7589. else
  7590. {
  7591. tempIndex = connectorIdInt -1;
  7592. }
  7593. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7594. {
  7595. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7596. {
  7597. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7598. {
  7599. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7600. {
  7601. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7602. {
  7603. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7605. }
  7606. 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'))
  7607. {
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7609. }
  7610. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7611. {
  7612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7613. }
  7614. else
  7615. {
  7616. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7617. }
  7618. }
  7619. 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
  7620. {
  7621. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7622. }
  7623. }
  7624. else
  7625. {
  7626. //replace reservation
  7627. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7629. }
  7630. }
  7631. } // END FOR CHAdeMO_QUANTITY
  7632. }
  7633. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7634. {
  7635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7636. {
  7637. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7638. }
  7639. else
  7640. {
  7641. tempIndex = connectorIdInt -1;
  7642. }
  7643. for (int index = 0; index < CCS_QUANTITY; index++)
  7644. {
  7645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7646. {
  7647. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7648. {
  7649. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7650. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7651. {
  7652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7653. {
  7654. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7656. }
  7657. 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'))
  7658. {
  7659. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7660. }
  7661. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7662. {
  7663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7664. }
  7665. else
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7668. }
  7669. }
  7670. 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
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7673. }
  7674. }
  7675. else
  7676. {
  7677. //replace reservation
  7678. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7680. }
  7681. }
  7682. } // END FOR CCS_QUANTITY
  7683. }
  7684. else if(gunType[connectorIdInt -1] == 'G')
  7685. {
  7686. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7687. {
  7688. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7689. }
  7690. else
  7691. {
  7692. tempIndex = connectorIdInt -1;
  7693. }
  7694. for (int index = 0; index < GB_QUANTITY; index++)
  7695. {
  7696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7697. {
  7698. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7699. {
  7700. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7701. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7704. {
  7705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7707. }
  7708. else if((ShmSysConfigAndInfo->SysInfo.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'))
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7711. }
  7712. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. }
  7716. else
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7719. }
  7720. }
  7721. else if((ShmSysConfigAndInfo->SysInfo.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
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7724. }
  7725. }
  7726. else
  7727. {
  7728. //replace reservation
  7729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7731. }
  7732. }
  7733. }// END FOR GB_QUANTITY
  7734. }
  7735. else
  7736. {
  7737. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7738. {
  7739. tempIndex = 2;
  7740. }
  7741. else
  7742. {
  7743. tempIndex = (connectorIdInt -1);
  7744. }
  7745. for (int index = 0; index < AC_QUANTITY; index++)
  7746. {
  7747. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7748. {
  7749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7750. {
  7751. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7752. {
  7753. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7754. {
  7755. 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))
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7758. }
  7759. else
  7760. {
  7761. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7762. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7763. }
  7764. }
  7765. 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'))
  7766. {
  7767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7768. }
  7769. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7770. {
  7771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7772. }
  7773. else
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7776. }
  7777. }
  7778. 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
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7781. }
  7782. }
  7783. else
  7784. {
  7785. //replace reservation
  7786. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7788. }
  7789. }
  7790. } // END FOR AC_QUANTITY
  7791. }
  7792. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7793. }
  7794. else if(connectorIdInt == 0)
  7795. {
  7796. //check Transaction active
  7797. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7798. {
  7799. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7800. {
  7801. 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'))
  7802. {
  7803. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7804. goto end;
  7805. }
  7806. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7807. {
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7809. goto end;
  7810. }
  7811. 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
  7812. {
  7813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7814. goto end;
  7815. }
  7816. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7817. {
  7818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7819. goto end;
  7820. }
  7821. }
  7822. }// END FOR CHAdeMO_QUANTITY
  7823. for (int index = 0; index < CCS_QUANTITY; index++)
  7824. {
  7825. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7826. {
  7827. 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'))
  7828. {
  7829. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7830. goto end;
  7831. }
  7832. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7833. {
  7834. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7835. goto end;
  7836. }
  7837. 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
  7838. {
  7839. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7840. goto end;
  7841. }
  7842. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7843. {
  7844. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7845. goto end;
  7846. }
  7847. }
  7848. } // END FOR CCS_QUANTITY
  7849. for (int index = 0; index < GB_QUANTITY; index++)
  7850. {
  7851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7852. {
  7853. 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'))
  7854. {
  7855. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7856. goto end;
  7857. }
  7858. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7859. {
  7860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7861. goto end;
  7862. }
  7863. 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
  7864. {
  7865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7866. goto end;
  7867. }
  7868. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7871. goto end;
  7872. }
  7873. }
  7874. } // END FOR GB_QUANTITY
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7878. {
  7879. 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'))
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7882. goto end;
  7883. }
  7884. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7885. {
  7886. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7887. goto end;
  7888. }
  7889. 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
  7890. {
  7891. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7892. goto end;
  7893. }
  7894. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7895. {
  7896. 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))
  7897. {
  7898. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7899. goto end;
  7900. }
  7901. }
  7902. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7903. {
  7904. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7905. goto end;
  7906. }
  7907. }
  7908. }// END FOR AC_QUANTITY
  7909. //The connectorId is 0
  7910. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7912. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7913. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7914. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7915. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7916. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7917. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7918. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7919. result = TRUE;
  7920. return result;
  7921. }
  7922. else
  7923. {
  7924. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7925. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7926. }
  7927. if(strcmp(comfirmstr,"Accepted") == 0)
  7928. {
  7929. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7930. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7931. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7932. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7933. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7934. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7935. result = TRUE;
  7936. return result;
  7937. }
  7938. end:
  7939. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7940. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7941. return result;
  7942. }
  7943. int handleResetRequest(char *uuid, char *payload)
  7944. {
  7945. mtrace();
  7946. int result = FAIL;
  7947. char sstr[10]={0},sstrtemp[30]={ 0 };
  7948. char typestr[10]={0};
  7949. char comfirmstr[20]={0};
  7950. int c = 0;
  7951. char *loc;
  7952. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7953. DEBUG_INFO("handleResetRequest ...\n");
  7954. strcpy(sstrtemp, stringtrimspace(payload));
  7955. loc = strstr(sstrtemp, "type");
  7956. memset(sstr ,0, sizeof(sstr) );
  7957. c = 0;
  7958. while (loc[3+strlen("type")+c] != '\"')
  7959. {
  7960. sstr[c] = loc[3+strlen("type")+c];
  7961. c++;
  7962. }
  7963. sstr[c] = '\0';
  7964. strcpy(typestr,sstr);
  7965. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7966. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7967. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7968. {
  7969. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7970. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7971. result = TRUE;
  7972. return result;
  7973. }
  7974. else
  7975. {
  7976. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7977. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7978. goto errorend;
  7979. }
  7980. errorend:
  7981. sendResetConfirmation(uuid, comfirmstr);
  7982. return result;
  7983. }
  7984. int handleSendLocalListRequest(char *uuid, char *payload)
  7985. {
  7986. mtrace();
  7987. int result = FAIL;
  7988. int listVersionInt;
  7989. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7990. char listsearch[]="listVersion";
  7991. char updateTypesearch[]="updateType";
  7992. char localAuthorizationListsearch[]="localAuthorizationList";
  7993. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7994. char CardList[500][160]={0};
  7995. char updateTypestr[15]={0};
  7996. char idTagstr[20]={0};
  7997. char parentIdTag[20]={0};
  7998. char expiryDate[30]={0};
  7999. char idTagstatus[16]={0};
  8000. int c = 0;
  8001. int i = 0;
  8002. char *delim1 = "}";
  8003. char * pch;
  8004. char *loc;
  8005. //char *ptr;
  8006. char comfirmstr[20];
  8007. //int n_localAuthorizations = 0;
  8008. int checkState_Faulted = FALSE;
  8009. DEBUG_INFO("handleSendLocalListRequest\n");
  8010. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8011. {
  8012. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8013. goto end;
  8014. }
  8015. //check Charge Point state
  8016. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8017. {
  8018. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8019. {
  8020. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8021. }
  8022. }
  8023. for (int index = 0; index < CCS_QUANTITY; index++)
  8024. {
  8025. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8026. {
  8027. checkState_Faulted = TRUE; //OCPP Status
  8028. }
  8029. }
  8030. for (int index = 0; index < GB_QUANTITY; index++)
  8031. {
  8032. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8033. {
  8034. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8035. }
  8036. }
  8037. //check Charge Point state
  8038. for (int index = 0; index < AC_QUANTITY; index++)
  8039. {
  8040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8041. {
  8042. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8043. }
  8044. }
  8045. if(checkState_Faulted == TRUE)
  8046. {
  8047. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8048. goto end;
  8049. }
  8050. //Filter payload space
  8051. strcpy(sstrtemp, stringtrimspace(payload));
  8052. //listVersion
  8053. c = 0;
  8054. loc = strstr(sstrtemp, listsearch);
  8055. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8056. {
  8057. sstr[c] = loc[strlen("listVersion")+2+c];
  8058. c++;
  8059. }
  8060. sstr[c] = '\0';
  8061. listVersionInt = atoi(sstr);
  8062. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8063. //updateType
  8064. loc = strstr(sstrtemp, updateTypesearch);
  8065. c = 0;
  8066. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8067. {
  8068. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8069. c++;
  8070. }
  8071. sstr[c] = '\0';
  8072. strcpy(updateTypestr, sstr);
  8073. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8074. //localAuthorizationList
  8075. memset(sstr ,0, sizeof(sstr) );
  8076. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8077. if(loc != NULL) // localAuthorizationList is not NULL
  8078. {
  8079. //Check UpdateType
  8080. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8081. {
  8082. //Local list full update
  8083. printf("Local list full update.\n");
  8084. OCPP_getListVerion();
  8085. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8086. {
  8087. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8088. goto end;
  8089. }
  8090. OCPP_cleanLocalList();
  8091. }
  8092. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8093. {
  8094. //Local list different update
  8095. printf("Local list different update.\n");
  8096. OCPP_getListVerion();
  8097. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8098. {
  8099. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8100. goto end;
  8101. }
  8102. }
  8103. else
  8104. {
  8105. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8106. goto end;
  8107. }
  8108. c = 0;
  8109. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8110. {
  8111. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8112. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8113. c++;
  8114. }
  8115. sstr[c] = '\0';
  8116. //DEBUG_INFO("sstr=%s\n", sstr);
  8117. //parsing strings to words
  8118. i = 0;
  8119. pch = strtok(sstr,delim1);
  8120. while (pch != NULL)
  8121. {
  8122. strcpy(CardList[i], pch);
  8123. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8124. pch = strtok (NULL, delim1);
  8125. i = i + 1;
  8126. }
  8127. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8128. //local Authorizations List Numbers
  8129. //n_localAuthorizations = i;
  8130. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8131. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8132. c= 0;
  8133. while(c < i) // i is CardList Number
  8134. {
  8135. //Search "IdToken"
  8136. memset(sstr ,0, sizeof(sstr) );
  8137. loc = strstr(CardList[c], "idTag");
  8138. int j = 0;
  8139. while (loc[3+strlen("idTag")+j] != '\"')
  8140. {
  8141. sstr[j] = loc[3+strlen("idTag")+j];
  8142. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8143. j++;
  8144. }
  8145. sstr[j] = '\0';
  8146. strcpy(idTagstr, sstr);
  8147. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8148. //Search "expiryDate"
  8149. memset(sstr ,0, sizeof(sstr) );
  8150. loc = strstr(CardList[c], "expiryDate");
  8151. j = 0;
  8152. if(loc != NULL)
  8153. {
  8154. while (loc[3+strlen("expiryDate")+j] != '\"')
  8155. {
  8156. sstr[j] = loc[3+strlen("expiryDate")+j];
  8157. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8158. j++;
  8159. }
  8160. sstr[j] = '\0';
  8161. strcpy(expiryDate, sstr);
  8162. }
  8163. else
  8164. {
  8165. strcpy(expiryDate, "");
  8166. }
  8167. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8168. //Search "parentIdTag"
  8169. memset(sstr ,0, sizeof(sstr) );
  8170. loc = strstr(CardList[c], "parentIdTag");
  8171. j = 0;
  8172. if(loc != NULL)
  8173. {
  8174. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8175. {
  8176. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8177. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8178. j++;
  8179. }
  8180. sstr[j] = '\0';
  8181. strcpy(parentIdTag, sstr);
  8182. }
  8183. else
  8184. {
  8185. strcpy(parentIdTag, "");
  8186. }
  8187. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8188. //Search "status"
  8189. memset(sstr ,0, sizeof(sstr) );
  8190. loc = strstr(CardList[c], "status");
  8191. j = 0;
  8192. while (loc[3+strlen("status")+j] != '\"')
  8193. {
  8194. sstr[j] = loc[3+strlen("status")+j];
  8195. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8196. j++;
  8197. }
  8198. sstr[j] = '\0';
  8199. strcpy(idTagstatus, sstr);
  8200. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8201. OCPP_getIdTag(idTagstr);
  8202. //OCPP_getIdTag("test"); For Test
  8203. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8204. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8205. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8206. {
  8207. //Local list full update
  8208. DEBUG_INFO("Local list full update.\n");
  8209. // update list
  8210. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8211. //DEBUG_INFO("Local list full update. 1\n");
  8212. //OCPP_get_TableAuthlocalAllData();
  8213. //DEBUG_INFO("Local list full update. 2\n");
  8214. }
  8215. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8216. {
  8217. #if 0
  8218. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8219. {
  8220. //OCPP_deleteIdTag(idTagstr);
  8221. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8222. }
  8223. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8224. {
  8225. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8226. }
  8227. #endif
  8228. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8229. }
  8230. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8231. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8232. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8233. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8234. c++;
  8235. }
  8236. }
  8237. else
  8238. {
  8239. //Check UpdateType
  8240. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8241. {
  8242. //Local list full update
  8243. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8244. OCPP_cleanLocalList();
  8245. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8246. goto end;
  8247. }
  8248. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8249. {
  8250. //Local list different update
  8251. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8252. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8253. goto end;
  8254. }
  8255. }
  8256. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8257. end:
  8258. sendSendLocalListConfirmation(uuid, comfirmstr);
  8259. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8260. return result;
  8261. }
  8262. #define MAX 200
  8263. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8264. {
  8265. mtrace();
  8266. int result = FAIL;
  8267. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8268. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8269. char chargingProfilePurposeStr[30]={0};
  8270. char chargingProfileKindStr[16]={0};
  8271. char recurrencyKindStr[10]={0};
  8272. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8273. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8274. int chargingSchedulePeriodCount = 0;
  8275. //int updateflag = FALSE;
  8276. char comfirmstr[20]={0};
  8277. int meet= FALSE;
  8278. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8279. int c = 0;
  8280. char *loc;
  8281. FILE *fptr1;//, *fptr2;
  8282. //int lno=0;//, linectr = 0;
  8283. //int modifyflag = FALSE;
  8284. char filename[MAX]={0};
  8285. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8286. //int resultRename=0;
  8287. char rmFileCmd[50]={0};
  8288. char tempchargingProfilePurposeStr[30]={0};
  8289. char word[1600]={0};
  8290. int n_chargingProfile = 0;
  8291. //[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}}}]
  8292. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8293. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8294. //Filter string space
  8295. strcpy(sstrtemp, stringtrimspace(payload));
  8296. //*********************connectorId***************************/
  8297. loc = strstr(sstrtemp, "connectorId");
  8298. c = 0;
  8299. memset(sstr ,0, sizeof(sstr) );
  8300. while (loc[strlen("connectorId")+2+c] != ',')
  8301. {
  8302. sstr[c] = loc[strlen("connectorId")+2+c];
  8303. c++;
  8304. }
  8305. sstr[c] = '\0';
  8306. connectorIdInt = atoi(sstr);
  8307. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8308. {
  8309. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8310. }
  8311. else
  8312. {
  8313. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8314. }
  8315. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8316. //*********************chargingProfileId***************************/
  8317. loc = strstr(sstrtemp, "chargingProfileId");
  8318. c = 0;
  8319. memset(sstr ,0, sizeof(sstr) );
  8320. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8321. {
  8322. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8323. c++;
  8324. }
  8325. sstr[c] = '\0';
  8326. chargingProfileIdInt = atoi(sstr);
  8327. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8328. {
  8329. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8330. }
  8331. else
  8332. {
  8333. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8334. }
  8335. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8336. //*********************transactionId***************************/
  8337. loc = strstr(sstrtemp, "transactionId");
  8338. if(loc != NULL)
  8339. {
  8340. c = 0;
  8341. memset(sstr ,0, sizeof(sstr) );
  8342. while (loc[strlen("transactionId")+2+c] != ',')
  8343. {
  8344. sstr[c] = loc[strlen("transactionId")+2+c];
  8345. c++;
  8346. }
  8347. sstr[c] = '\0';
  8348. transactionIdInt = atoi(sstr);
  8349. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8350. {
  8351. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8352. }
  8353. else
  8354. {
  8355. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8356. }
  8357. }
  8358. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8359. //*********************stackLevel***************************/
  8360. loc = strstr(sstrtemp, "stackLevel");
  8361. c = 0;
  8362. memset(sstr ,0, sizeof(sstr) );
  8363. while (loc[strlen("stackLevel")+2+c] != ',')
  8364. {
  8365. sstr[c] = loc[strlen("stackLevel")+2+c];
  8366. c++;
  8367. }
  8368. sstr[c] = '\0';
  8369. stackLevelInt = atoi(sstr);
  8370. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8371. {
  8372. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8373. }
  8374. else
  8375. {
  8376. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8377. }
  8378. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8379. //*********************chargingProfilePurpose***************************/
  8380. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8381. c = 0;
  8382. memset(sstr ,0, sizeof(sstr) );
  8383. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8384. {
  8385. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8386. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8387. c++;
  8388. }
  8389. sstr[c] = '\0';
  8390. strcpy(chargingProfilePurposeStr,sstr);
  8391. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8392. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8393. {
  8394. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8395. }
  8396. else
  8397. {
  8398. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8399. }
  8400. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8401. //*********************chargingProfileKind***************************/
  8402. loc = strstr(sstrtemp, "chargingProfileKind");
  8403. c = 0;
  8404. memset(sstr ,0, sizeof(sstr) );
  8405. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8406. {
  8407. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8409. c++;
  8410. }
  8411. sstr[c] = '\0';
  8412. strcpy(chargingProfileKindStr,sstr);
  8413. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8414. {
  8415. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8416. }
  8417. else
  8418. {
  8419. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8420. }
  8421. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8422. //*********************recurrencyKind***************************/
  8423. loc = strstr(sstrtemp, "recurrencyKind");
  8424. if(loc != NULL)
  8425. {
  8426. c = 0;
  8427. memset(sstr ,0, sizeof(sstr) );
  8428. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8429. {
  8430. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8431. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8432. c++;
  8433. }
  8434. sstr[c] = '\0';
  8435. strcpy(recurrencyKindStr,sstr);
  8436. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8437. {
  8438. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8439. }
  8440. else
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8443. }
  8444. }
  8445. else
  8446. {
  8447. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8448. {
  8449. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8450. }
  8451. else
  8452. {
  8453. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8454. }
  8455. }
  8456. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8457. //*********************validFrom***************************/
  8458. loc = strstr(sstrtemp, "validFrom");
  8459. if(loc != NULL)
  8460. {
  8461. c = 0;
  8462. memset(sstr ,0, sizeof(sstr) );
  8463. while (loc[3+strlen("validFrom")+c] != '\"')
  8464. {
  8465. sstr[c] = loc[3+strlen("validFrom")+c];
  8466. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8467. c++;
  8468. }
  8469. sstr[c] = '\0';
  8470. strcpy(validFromStr,sstr);
  8471. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8472. {
  8473. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8474. }
  8475. else
  8476. {
  8477. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8478. }
  8479. }
  8480. else
  8481. {
  8482. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8483. {
  8484. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8485. }
  8486. else
  8487. {
  8488. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8489. }
  8490. }
  8491. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8492. //*********************validTo***************************/
  8493. loc = strstr(sstrtemp, "validTo");
  8494. if(loc != NULL)
  8495. {
  8496. c = 0;
  8497. memset(sstr ,0, sizeof(sstr) );
  8498. while (loc[3+strlen("validTo")+c] != '\"')
  8499. {
  8500. sstr[c] = loc[3+strlen("validTo")+c];
  8501. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8502. c++;
  8503. }
  8504. sstr[c] = '\0';
  8505. strcpy(validToStr,sstr);
  8506. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8507. {
  8508. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8509. }
  8510. else
  8511. {
  8512. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8513. }
  8514. }
  8515. else
  8516. {
  8517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8518. {
  8519. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8520. }
  8521. else
  8522. {
  8523. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8524. }
  8525. }
  8526. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8527. //*********************duration***************************/
  8528. loc = strstr(sstrtemp, "duration");
  8529. if(loc != NULL)
  8530. {
  8531. c = 0;
  8532. memset(sstr ,0, sizeof(sstr) );
  8533. while (loc[strlen("duration")+2+c] != ',')
  8534. {
  8535. sstr[c] = loc[strlen("duration")+2+c];
  8536. c++;
  8537. }
  8538. sstr[c] = '\0';
  8539. durationInt = atoi(sstr);
  8540. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8541. {
  8542. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8543. }
  8544. else
  8545. {
  8546. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8547. }
  8548. }
  8549. else
  8550. {
  8551. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8552. {
  8553. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8554. }
  8555. else
  8556. {
  8557. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8558. }
  8559. }
  8560. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8561. //*********************startSchedule***************************/
  8562. loc = strstr(sstrtemp, "startSchedule");
  8563. if(loc != NULL)
  8564. {
  8565. c = 0;
  8566. memset(sstr ,0, sizeof(sstr) );
  8567. while (loc[3+strlen("startSchedule")+c] != '\"')
  8568. {
  8569. sstr[c] = loc[3+strlen("startSchedule")+c];
  8570. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8571. c++;
  8572. }
  8573. sstr[c] = '\0';
  8574. strcpy(startScheduleStr,sstr);
  8575. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8576. {
  8577. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8578. }
  8579. else
  8580. {
  8581. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8582. }
  8583. }
  8584. else
  8585. {
  8586. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8587. {
  8588. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8589. }
  8590. else
  8591. {
  8592. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8593. }
  8594. }
  8595. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8596. //*********************chargingRateUnit***************************/
  8597. loc = strstr(sstrtemp, "chargingRateUnit");
  8598. if(loc != NULL)
  8599. {
  8600. c = 0;
  8601. memset(sstr ,0, sizeof(sstr) );
  8602. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8603. {
  8604. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8605. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8606. c++;
  8607. }
  8608. sstr[c] = '\0';
  8609. strcpy(chargingRateUnitStr,sstr);
  8610. #if 0
  8611. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8612. {
  8613. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8614. goto end;
  8615. }
  8616. #endif
  8617. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8618. {
  8619. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8620. }
  8621. else
  8622. {
  8623. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8624. }
  8625. }
  8626. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8627. //****************chargingSchedulePeriod count start*******************/
  8628. int what_len = strlen("startPeriod");
  8629. char tempChargingProfile[1600]={0};
  8630. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8631. char *where = tempChargingProfile;
  8632. if (what_len)
  8633. {
  8634. while ((where = strstr(where, "startPeriod"))) {
  8635. where += what_len;
  8636. chargingSchedulePeriodCount++;
  8637. }
  8638. }
  8639. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8640. {
  8641. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8642. goto end;
  8643. }
  8644. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8645. //where = payload;
  8646. int templength = 0;
  8647. //int searchstart = 0;
  8648. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8649. {
  8650. //****************startPeriod*******************/
  8651. c=0;
  8652. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8653. memset(sstr ,0, sizeof(sstr) );
  8654. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8655. {
  8656. sstr[c] = loc[strlen("startPeriod")+2+c];
  8657. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8658. c++;
  8659. }
  8660. sstr[c] = '\0';
  8661. startPeriodInt[periodNums] = atoi(sstr);
  8662. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8663. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8664. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8665. {
  8666. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8667. }
  8668. else
  8669. {
  8670. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8671. }
  8672. templength = strlen("startPeriod")+2+c;
  8673. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8674. //****************limit*******************/
  8675. c=0;
  8676. loc = strstr(tempChargingProfile + templength, "limit");
  8677. memset(sstr ,0, sizeof(sstr) );
  8678. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8679. {
  8680. sstr[c] = loc[strlen("limit")+2+c];
  8681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8682. c++;
  8683. }
  8684. sstr[c] = '\0';
  8685. limitflaot[periodNums] = atof(sstr);
  8686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8687. {
  8688. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8689. }
  8690. else
  8691. {
  8692. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8693. }
  8694. templength = templength + strlen("limit")+2+c;
  8695. //****************numberPhases*******************/
  8696. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8697. if(loc != NULL)
  8698. {
  8699. c=0;
  8700. memset(sstr ,0, sizeof(sstr) );
  8701. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8702. {
  8703. sstr[c] = loc[strlen("numberPhases")+2+c];
  8704. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8705. c++;
  8706. }
  8707. sstr[c] = '\0';
  8708. numberPhasesInt[periodNums] = atoi(sstr);
  8709. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8710. {
  8711. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8712. }
  8713. else
  8714. {
  8715. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8716. }
  8717. templength = templength + strlen("numberPhases")+2+c;
  8718. }
  8719. //where = loc;
  8720. }
  8721. //****************chargingSchedulePeriod count end*******************/
  8722. //*********************minChargingRate***************************/
  8723. loc = strstr(sstrtemp, "minChargingRate");
  8724. if(loc != NULL)
  8725. {
  8726. c = 0;
  8727. memset(sstr ,0, sizeof(sstr) );
  8728. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8729. {
  8730. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8731. c++;
  8732. }
  8733. sstr[c] = '\0';
  8734. minChargingRateFloat = atof(sstr);
  8735. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8736. {
  8737. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8738. }
  8739. else
  8740. {
  8741. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8742. }
  8743. }
  8744. else
  8745. {
  8746. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8747. {
  8748. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8749. }
  8750. else
  8751. {
  8752. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8753. }
  8754. }
  8755. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8756. {
  8757. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8758. if(connectorIdInt != 0)
  8759. {
  8760. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8761. goto end;
  8762. }
  8763. strcpy(filename, ChargePointMaxProfile_JSON );
  8764. fptr1 = fopen(filename, "r");
  8765. if (!fptr1)
  8766. {
  8767. //file not exist
  8768. DEBUG_INFO("Unable to open the input file!!\n");
  8769. fptr1 = fopen(filename, "w+");
  8770. }
  8771. else
  8772. {
  8773. //Check Charging Profile Count
  8774. while(fscanf(fptr1, "%s", word) != EOF)
  8775. {
  8776. //DEBUG_INFO("word=%s\n",word);
  8777. if(strstr(word, "chargingProfileId")!= NULL)
  8778. {
  8779. //DEBUG_INFO("test chargingProfileId \n");
  8780. n_chargingProfile = n_chargingProfile + 1;
  8781. //DEBUG_INFO("chargingProfileId Found\n");
  8782. }
  8783. }
  8784. }
  8785. fclose(fptr1);
  8786. }
  8787. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8788. {
  8789. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8790. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8791. {
  8792. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8793. goto end;
  8794. }
  8795. memset(filename, 0, sizeof filename);
  8796. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8797. fptr1 = fopen(filename, "r");
  8798. if (!fptr1)
  8799. {
  8800. //file not exist
  8801. //DEBUG_INFO("Unable to open the input file!!\n");
  8802. fptr1 = fopen(filename, "w+");
  8803. }
  8804. else
  8805. {
  8806. //Check Charging Profile Count
  8807. while(fscanf(fptr1, "%s", word) != EOF)
  8808. {
  8809. //DEBUG_INFO("word=%s\n",word);
  8810. if(strstr(word, "chargingProfileId")!= NULL)
  8811. {
  8812. //DEBUG_INFO("test chargingProfileId \n");
  8813. n_chargingProfile = n_chargingProfile + 1;
  8814. //DEBUG_INFO("chargingProfileId Found\n");
  8815. }
  8816. }
  8817. }
  8818. fclose(fptr1);
  8819. }
  8820. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8821. {
  8822. //printf("set chargingProfile 1-4\n");
  8823. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8824. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8825. if(connectorIdInt == 0)
  8826. {
  8827. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8828. goto end;
  8829. }
  8830. int tempIndex = 0;
  8831. //check Transaction active
  8832. if(gunType[connectorIdInt -1] == 'J')
  8833. {
  8834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8835. {
  8836. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8837. }
  8838. else
  8839. {
  8840. tempIndex = connectorIdInt -1;
  8841. }
  8842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8843. {
  8844. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8845. {
  8846. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8847. {
  8848. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8849. {
  8850. meet = TRUE;
  8851. break;
  8852. }
  8853. }
  8854. }
  8855. }
  8856. }
  8857. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8858. {
  8859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8860. {
  8861. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8862. }
  8863. else
  8864. {
  8865. tempIndex = connectorIdInt -1;
  8866. }
  8867. for (int index = 0; index < CCS_QUANTITY; index++)
  8868. {
  8869. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8870. {
  8871. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8872. {
  8873. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8874. {
  8875. meet = TRUE;
  8876. break;
  8877. }
  8878. }
  8879. }
  8880. }
  8881. }
  8882. else if(gunType[connectorIdInt -1] == 'G')
  8883. {
  8884. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8885. {
  8886. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8887. }
  8888. else
  8889. {
  8890. tempIndex = connectorIdInt -1;
  8891. }
  8892. for (int index = 0; index < GB_QUANTITY; index++)
  8893. {
  8894. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8895. {
  8896. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8897. {
  8898. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8899. {
  8900. meet = TRUE;
  8901. break;
  8902. }
  8903. }
  8904. }
  8905. }
  8906. }
  8907. else
  8908. {
  8909. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8910. {
  8911. tempIndex = 2;
  8912. }
  8913. else
  8914. {
  8915. tempIndex = (connectorIdInt -1);
  8916. }
  8917. for (int index = 0; index < AC_QUANTITY; index++)
  8918. {
  8919. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8920. {
  8921. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8922. {
  8923. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8924. {
  8925. meet = TRUE;
  8926. break;
  8927. }
  8928. }
  8929. }
  8930. }
  8931. }
  8932. //check Transaction active
  8933. if(meet == FALSE)
  8934. {
  8935. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8936. goto end;
  8937. }
  8938. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8939. {
  8940. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8941. goto end;
  8942. }
  8943. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8944. fptr1 = fopen(filename, "r");
  8945. if (!fptr1)
  8946. {
  8947. //file not exist
  8948. DEBUG_INFO("Unable to open the input file!!\n");
  8949. fptr1 = fopen(filename, "w+");
  8950. }
  8951. else
  8952. {
  8953. //Check Charging Profile Count
  8954. while(fscanf(fptr1, "%s", word) != EOF)
  8955. {
  8956. //DEBUG_INFO("word=%s\n",word);
  8957. if(strstr(word, "chargingProfileId")!= NULL)
  8958. {
  8959. //DEBUG_INFO("test chargingProfileId \n");
  8960. n_chargingProfile = n_chargingProfile + 1;
  8961. //DEBUG_INFO("chargingProfileId Found\n");
  8962. }
  8963. }
  8964. }
  8965. fclose(fptr1);
  8966. }
  8967. // Check ChargeProfileMaxStackLevel
  8968. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8969. {
  8970. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8971. goto end;
  8972. }
  8973. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8974. {
  8975. int i = 0;
  8976. char fnametemp[200]={0};
  8977. n_chargingProfile = 0;
  8978. //Check ChargePointMaxProfile.json exit
  8979. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8980. {
  8981. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8982. //Check Charging Profile Count
  8983. while(fscanf(fptr1, "%s", word) != EOF)
  8984. {
  8985. //DEBUG_INFO("word=%s\n",word);
  8986. if(strstr(word, "chargingProfileId")!= NULL)
  8987. {
  8988. //DEBUG_INFO("test chargingProfileId \n");
  8989. n_chargingProfile = n_chargingProfile + 1;
  8990. i = i + 1;
  8991. //DEBUG_INFO("chargingProfileId Found\n");
  8992. }
  8993. memset(word, 0, sizeof word);
  8994. }
  8995. fclose(fptr1);
  8996. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8997. }
  8998. //Check TxDefaultProfile_0.json exit
  8999. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9000. {
  9001. i = 0;
  9002. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9003. //Check Charging Profile Count
  9004. while(fscanf(fptr1, "%s", word) != EOF)
  9005. {
  9006. //DEBUG_INFO("word=%s\n",word);
  9007. if(strstr(word, "chargingProfileId")!= NULL)
  9008. {
  9009. //DEBUG_INFO("test chargingProfileId \n");
  9010. n_chargingProfile = n_chargingProfile + 1;
  9011. i = i + 1;
  9012. //DEBUG_INFO("chargingProfileId Found\n");
  9013. }
  9014. memset(word, 0, sizeof word);
  9015. }
  9016. fclose(fptr1);
  9017. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9018. }
  9019. //Check TxDefaultProfile_%d.json
  9020. for(int j=1; j <= gunTotalNumber; j++)
  9021. {
  9022. memset(fnametemp, 0, sizeof fnametemp);
  9023. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9024. if((access(fnametemp,F_OK))!=-1)
  9025. {
  9026. i = 0;
  9027. fptr1 = fopen(fnametemp, "r");
  9028. //Check Charging Profile Count
  9029. while(fscanf(fptr1, "%s", word) != EOF)
  9030. {
  9031. //DEBUG_INFO("word=%s\n",word);
  9032. if(strstr(word, "chargingProfileId")!= NULL)
  9033. {
  9034. //DEBUG_INFO("test chargingProfileId \n");
  9035. n_chargingProfile = n_chargingProfile + 1;
  9036. i = i + 1;
  9037. //DEBUG_INFO("chargingProfileId Found\n");
  9038. }
  9039. memset(word, 0, sizeof word);
  9040. }
  9041. fclose(fptr1);
  9042. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9043. }
  9044. }
  9045. //Check TxProfile_%d.json
  9046. for(int j=1; j <= gunTotalNumber; j++)
  9047. {
  9048. memset(fnametemp, 0, sizeof fnametemp);
  9049. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9050. if((access(fnametemp,F_OK))!=-1)
  9051. {
  9052. i = 0;
  9053. fptr1 = fopen(fnametemp, "r");
  9054. //Check Charging Profile Count
  9055. while(fscanf(fptr1, "%s", word) != EOF)
  9056. {
  9057. //DEBUG_INFO("word=%s\n",word);
  9058. if(strstr(word, "chargingProfileId")!= NULL)
  9059. {
  9060. //DEBUG_INFO("test chargingProfileId \n");
  9061. n_chargingProfile = n_chargingProfile + 1;
  9062. i = i + 1;
  9063. //DEBUG_INFO("chargingProfileId Found\n");
  9064. }
  9065. memset(word, 0, sizeof word);
  9066. }
  9067. fclose(fptr1);
  9068. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9069. }
  9070. }
  9071. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9072. {
  9073. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9074. goto end;
  9075. }
  9076. }
  9077. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9078. //**********************************Write to File********************************************************/
  9079. FILE *infile;
  9080. FILE *outfile;
  9081. // open file for writing
  9082. infile = fopen (filename, "r");
  9083. outfile = fopen (tempfile, "w");
  9084. int d =0;
  9085. d = fgetc(infile);
  9086. //DEBUG_INFO("d:%d\n",d);
  9087. rewind(infile);
  9088. //*检测到文件结束标识返回1,否则返回0。*/
  9089. if(d == EOF)
  9090. {
  9091. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9092. fprintf(outfile,"%s\n",payload);
  9093. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9094. fclose(infile);
  9095. fclose(outfile);
  9096. sprintf(rmFileCmd,"rm -f %s",filename);
  9097. system(rmFileCmd);
  9098. rename(tempfile, filename);
  9099. sleep(1);
  9100. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9101. //system(rmFileCmd);
  9102. }
  9103. else
  9104. {
  9105. char buf[1000]={0};
  9106. int ChargingProfileAdded = FALSE;
  9107. while (fgets(buf, sizeof(buf), infile) != NULL)
  9108. {
  9109. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9110. //*************************tempconnectorIdInt*********************************/
  9111. loc = strstr(buf, "connectorId");
  9112. c = 0;
  9113. memset(sstr ,0, sizeof(sstr) );
  9114. while (loc[strlen("connectorId")+2+c] != ',')
  9115. {
  9116. sstr[c] = loc[strlen("connectorId")+2+c];
  9117. c++;
  9118. }
  9119. sstr[c] = '\0';
  9120. tempconnectorIdInt = atoi(sstr);
  9121. //*************************tempchargingProfileIdInt*********************************/
  9122. loc = strstr(buf, "chargingProfileId");
  9123. c = 0;
  9124. memset(sstr ,0, sizeof(sstr) );
  9125. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9126. {
  9127. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9128. c++;
  9129. }
  9130. sstr[c] = '\0';
  9131. tempchargingProfileIdInt = atoi(sstr);
  9132. //*************************tempstackLevelInt*********************************/
  9133. loc = strstr(buf, "stackLevel");
  9134. c = 0;
  9135. memset(sstr ,0, sizeof(sstr) );
  9136. while (loc[strlen("stackLevel")+2+c] != ',')
  9137. {
  9138. sstr[c] = loc[strlen("stackLevel")+2+c];
  9139. c++;
  9140. }
  9141. sstr[c] = '\0';
  9142. tempstackLevelInt = atoi(sstr);
  9143. //*************************tempchargingProfilePurposeStr*********************************/
  9144. loc = strstr(payload, "chargingProfilePurpose");
  9145. c = 0;
  9146. memset(sstr ,0, sizeof(sstr) );
  9147. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9148. {
  9149. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9150. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9151. c++;
  9152. }
  9153. sstr[c] = '\0';
  9154. strcpy(tempchargingProfilePurposeStr,sstr);
  9155. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9156. {
  9157. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9158. {
  9159. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9160. if(ChargingProfileAdded == FALSE)
  9161. {
  9162. fprintf(outfile,"%s\n",payload);
  9163. ChargingProfileAdded = TRUE;
  9164. }
  9165. }
  9166. else
  9167. {
  9168. if(tempstackLevelInt < stackLevelInt)
  9169. {
  9170. if(ChargingProfileAdded == FALSE)
  9171. {
  9172. fprintf(outfile,"%s\n",payload);
  9173. ChargingProfileAdded = TRUE;
  9174. fprintf(outfile,"%s\n",buf);
  9175. }
  9176. else
  9177. {
  9178. fprintf(outfile,"%s\n",buf);
  9179. }
  9180. }
  9181. else
  9182. {
  9183. if(ChargingProfileAdded == FALSE)
  9184. {
  9185. fprintf(outfile,"%s\n",buf);
  9186. fprintf(outfile,"%s\n",payload);
  9187. ChargingProfileAdded = TRUE;
  9188. }
  9189. else
  9190. {
  9191. fprintf(outfile,"%s\n",buf);
  9192. }
  9193. }
  9194. }
  9195. }
  9196. else
  9197. {
  9198. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9199. {
  9200. if(ChargingProfileAdded == FALSE)
  9201. {
  9202. fprintf(outfile,"%s\n",payload);
  9203. ChargingProfileAdded = TRUE;
  9204. fprintf(outfile,"%s\n",buf);
  9205. }
  9206. else
  9207. {
  9208. fprintf(outfile,"%s\n",buf);
  9209. }
  9210. }
  9211. else if(tempstackLevelInt < stackLevelInt)
  9212. {
  9213. if(ChargingProfileAdded == FALSE)
  9214. {
  9215. fprintf(outfile,"%s\n",payload);
  9216. ChargingProfileAdded = TRUE;
  9217. fprintf(outfile,"%s\n",buf);
  9218. }
  9219. else
  9220. {
  9221. fprintf(outfile,"%s\n",buf);
  9222. }
  9223. }
  9224. else
  9225. {
  9226. if(ChargingProfileAdded == FALSE)
  9227. {
  9228. fprintf(outfile,"%s\n",buf);
  9229. fprintf(outfile,"%s\n",payload);
  9230. ChargingProfileAdded = TRUE;
  9231. }
  9232. else
  9233. {
  9234. fprintf(outfile,"%s\n",buf);
  9235. }
  9236. }
  9237. }
  9238. } // end of while loop
  9239. fclose(infile);
  9240. fclose(outfile);
  9241. sprintf(rmFileCmd,"rm -f %s",filename);
  9242. system(rmFileCmd);
  9243. rename(tempfile, filename);
  9244. sleep(1);
  9245. result = TRUE;
  9246. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9247. }
  9248. end:
  9249. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9250. return result;
  9251. return result;
  9252. }
  9253. int handleTriggerMessageRequest(char *uuid, char *payload)
  9254. {
  9255. mtrace();
  9256. int result = FAIL;
  9257. int connectorIdIsNULL = FALSE;
  9258. int connectorIdInt =0;
  9259. char sstr[40]={0},sstrtemp[100]={ 0 };
  9260. char requestedMessagestr[40]={0};
  9261. char comfirmstr[20]={0};
  9262. int c = 0;
  9263. char *loc;
  9264. DEBUG_INFO("handleTriggerMessageRequest\n");
  9265. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9266. strcpy(sstrtemp, stringtrimspace(payload));
  9267. c = 0;
  9268. loc = strstr(sstrtemp, "requestedMessage");
  9269. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9270. {
  9271. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9272. c++;
  9273. }
  9274. sstr[c] = '\0';
  9275. strcpy(requestedMessagestr, sstr);
  9276. c = 0;
  9277. loc = strstr(sstrtemp, "connectorId");
  9278. if(loc == NULL)
  9279. {
  9280. connectorIdIsNULL = TRUE;
  9281. }
  9282. else
  9283. {
  9284. memset(sstr ,0, sizeof(sstr) );
  9285. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9286. {
  9287. sstr[c] = loc[strlen("connectorId")+2+c];
  9288. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9289. c++;
  9290. }
  9291. sstr[c] = '\0';
  9292. connectorIdInt = atoi(sstr);
  9293. }
  9294. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9295. {
  9296. //connectorIdInt = json_object_get_int(connectorId);
  9297. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9298. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9299. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9300. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9301. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9302. }
  9303. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9304. {
  9305. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9306. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9307. return TRUE;
  9308. }
  9309. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9310. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9311. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9312. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9313. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9314. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9315. {
  9316. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9317. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9318. return TRUE;
  9319. }
  9320. else
  9321. {
  9322. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9323. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9324. }
  9325. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9326. {
  9327. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9328. {
  9329. FirmwareStatusNotificationStatus = 3;
  9330. }
  9331. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9332. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9333. }
  9334. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9335. {
  9336. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9337. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9338. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9339. }
  9340. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9341. {
  9342. sendBootNotificationRequest();
  9343. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9344. }
  9345. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9346. {
  9347. sendHeartbeatRequest(connectorIdInt);
  9348. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9349. }
  9350. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9351. {
  9352. if(connectorIdIsNULL == FALSE)
  9353. {
  9354. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9355. {
  9356. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9357. sendMeterValuesRequest(connectorIdInt -1);
  9358. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9359. }
  9360. }
  9361. else
  9362. {
  9363. for(int idx=0;idx< gunTotalNumber;idx++)
  9364. {
  9365. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9366. sendMeterValuesRequest(idx);
  9367. }
  9368. }
  9369. }
  9370. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9371. {
  9372. if(connectorIdIsNULL == FALSE)
  9373. {
  9374. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9375. {
  9376. sendStatusNotificationRequest(connectorIdInt -1);
  9377. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9378. }
  9379. }
  9380. else
  9381. {
  9382. for(int idx=0;idx< gunTotalNumber;idx++)
  9383. sendStatusNotificationRequest(idx);
  9384. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9385. }
  9386. }
  9387. return result;
  9388. }
  9389. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9390. {
  9391. mtrace();
  9392. int result = FAIL;
  9393. char sstr[6]={0},sstrtemp[50]={ 0 };
  9394. int connectorIdInt =0;
  9395. char comfirmstr[20]={0};
  9396. int c = 0;
  9397. int tempIndex = 0;
  9398. char *loc;
  9399. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9400. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9401. strcpy(sstrtemp, stringtrimspace(payload));
  9402. c = 0;
  9403. loc = strstr(sstrtemp, "connectorId");
  9404. memset(sstr ,0, sizeof(sstr) );
  9405. while (loc[strlen("connectorId")+2+c] != '}')
  9406. {
  9407. sstr[c] = loc[strlen("connectorId")+2+c];
  9408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9409. c++;
  9410. }
  9411. sstr[c] = '\0';
  9412. connectorIdInt = atoi(sstr);
  9413. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9414. if(gunTotalNumber == 0)
  9415. {
  9416. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9417. goto end;
  9418. }
  9419. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9420. {
  9421. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9422. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9423. goto end;
  9424. }
  9425. else
  9426. {
  9427. //check Transaction active
  9428. if(gunType[connectorIdInt-1] == 'J')
  9429. {
  9430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9431. {
  9432. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9433. }
  9434. else
  9435. {
  9436. tempIndex = connectorIdInt -1;
  9437. }
  9438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9439. {
  9440. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9441. {
  9442. //stop Transaction
  9443. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9444. }
  9445. }
  9446. }
  9447. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9448. {
  9449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9450. {
  9451. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9452. }
  9453. else
  9454. {
  9455. tempIndex = connectorIdInt -1;
  9456. }
  9457. for (int index = 0; index < CCS_QUANTITY; index++)
  9458. {
  9459. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9460. {
  9461. //stop Transaction
  9462. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9463. }
  9464. }
  9465. }
  9466. else if(gunType[connectorIdInt-1] == 'G')
  9467. {
  9468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9469. {
  9470. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9471. }
  9472. else
  9473. {
  9474. tempIndex = connectorIdInt -1;
  9475. }
  9476. for (int index = 0; index < GB_QUANTITY; index++)
  9477. {
  9478. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9479. {
  9480. //stop Transaction
  9481. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9482. }
  9483. }
  9484. }
  9485. else
  9486. {
  9487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9488. {
  9489. tempIndex = 2;
  9490. }
  9491. else
  9492. {
  9493. tempIndex = connectorIdInt-1;
  9494. }
  9495. for (int index = 0; index < AC_QUANTITY; index++)
  9496. {
  9497. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9498. {
  9499. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9500. }
  9501. }
  9502. }
  9503. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9504. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9505. result = TRUE;
  9506. return result;
  9507. }
  9508. end:
  9509. //json_object_put(obj); --- remove temporally
  9510. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9511. return result;
  9512. }
  9513. static char UpdateFirmwarepayloadData[300]={0};
  9514. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9515. {
  9516. mtrace();
  9517. int result = FAIL;
  9518. pthread_t t;
  9519. sendUpdateFirmwareConfirmation(uuid);
  9520. memset(UpdateFirmwarepayloadData, 0, 300);
  9521. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9522. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9523. ////pthread_join(t, NULL); //
  9524. //pthread_detach(t);
  9525. //sendUpdateFirmwareConfirmation(uuid);
  9526. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9527. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9528. return result;
  9529. }
  9530. void *UpdateFirmwareProcess(void *data)
  9531. {
  9532. pthread_detach(pthread_self());
  9533. mtrace();
  9534. int retriesInt =0, retryIntervalInt=0;
  9535. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9536. int port=0;
  9537. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9538. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9539. //char comfirmstr[20];
  9540. int isSuccess = 0;
  9541. char ftpbuf[200];
  9542. char temp[100];
  9543. char * pch;
  9544. int retriesISNULL=FALSE;
  9545. int retryInterval=FALSE;
  9546. int c = 0;
  9547. //int i = 0;
  9548. char *loc;
  9549. char sstr[300]={ 0 };
  9550. char str[300]={ 0 };
  9551. //char *str = (char*) data; // ? ?輸入資 ?
  9552. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9553. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9554. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9555. //***************location **************/
  9556. loc = strstr(str, "location");
  9557. memset(sstr ,0, sizeof(sstr) );
  9558. c = 0;
  9559. while (loc[3+strlen("location")+c] != '\"')
  9560. {
  9561. sstr[c] = loc[3+strlen("location")+c];
  9562. c++;
  9563. }
  9564. sstr[c] = '\0';
  9565. strcpy(locationstr, sstr);
  9566. //***************retries**************/
  9567. c = 0;
  9568. loc = strstr(str, "retries");
  9569. if(loc == NULL)
  9570. {
  9571. retriesISNULL=TRUE;
  9572. }
  9573. else
  9574. {
  9575. memset(sstr ,0, sizeof(sstr) );
  9576. while (loc[strlen("retries")+2+c] != ',')
  9577. {
  9578. sstr[c] = loc[strlen("retries")+2+c];
  9579. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9580. c++;
  9581. }
  9582. sstr[c] = '\0';
  9583. }
  9584. if(retriesISNULL == FALSE)
  9585. {
  9586. retriesInt = atoi(sstr);
  9587. }
  9588. //***************retrieveDate **************/
  9589. loc = strstr(str, "retrieveDate");
  9590. memset(sstr ,0, sizeof(sstr) );
  9591. c = 0;
  9592. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9593. {
  9594. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9595. c++;
  9596. }
  9597. sstr[c] = '\0';
  9598. strcpy(retrieveDatestr, sstr);
  9599. //***************retryInterval **************/
  9600. c = 0;
  9601. loc = strstr(str, "retryInterval");
  9602. memset(sstr ,0, sizeof(sstr) );
  9603. if(loc == NULL)
  9604. {
  9605. retryInterval=TRUE;
  9606. }
  9607. else
  9608. {
  9609. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9610. {
  9611. sstr[c] = loc[strlen("retryInterval")+2+c];
  9612. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9613. c++;
  9614. }
  9615. sstr[c] = '\0';
  9616. }
  9617. if(retryInterval==FALSE)
  9618. {
  9619. retryIntervalInt = atoi(sstr);
  9620. }
  9621. memset(ftppath, 0, sizeof(ftppath));
  9622. memset(path, 0, sizeof(path));
  9623. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9624. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9625. if(strncmp(locationstr,"http", 4) == 0)
  9626. {
  9627. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9628. protocol, host, path);
  9629. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9630. // protocol, user, password, host, path);
  9631. sprintf(ftppath,"/%s", path);
  9632. //DEBUG_INFO("protocol =%s\n",protocol);
  9633. //DEBUG_INFO("host =%s\n",host);
  9634. //DEBUG_INFO("path =%s\n",path);
  9635. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9636. int ftppathlen=strlen(ftppath);
  9637. int i=1;
  9638. char filenametemp[50];
  9639. while(i < ftppathlen)
  9640. {
  9641. int len=ftppathlen-i;
  9642. if(ftppath[len]== 47) // '/' ascll code: 47
  9643. {
  9644. DEBUG_INFO("compare '/' all right\n");
  9645. break;
  9646. }
  9647. i=i+1;
  9648. }
  9649. memset(filenametemp, 0, sizeof(filenametemp));
  9650. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9651. filenametemp[i+1] = 0;
  9652. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9653. do{
  9654. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9655. sleep(retryIntervalInt);
  9656. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9657. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9658. if(!isSuccess)
  9659. {
  9660. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9661. }
  9662. else
  9663. {
  9664. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9665. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9666. //isUpdateRequest = TRUE;
  9667. }
  9668. }
  9669. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9670. {
  9671. memset(ftpbuf, 0, sizeof(ftpbuf));
  9672. memset(temp, 0, sizeof(temp));
  9673. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9674. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9675. int ftppathlen=strlen(ftpbuf);
  9676. int i=1;
  9677. char filenametemp[50];
  9678. while(i < ftppathlen)
  9679. {
  9680. int len=ftppathlen-i;
  9681. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9682. {
  9683. DEBUG_INFO(" compare '/' all right\n");
  9684. break;
  9685. }
  9686. i=i+1;
  9687. }
  9688. memset(filenametemp, 0, sizeof(filenametemp));
  9689. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9690. filenametemp[i+1] = 0;
  9691. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9692. pch=strchr(temp,'@');
  9693. if(pch==NULL)
  9694. {
  9695. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9696. protocol, host, &port, path);
  9697. strcpy(user,"anonymous");
  9698. strcpy(password,"");
  9699. }
  9700. else
  9701. {
  9702. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9703. protocol, user, password, host, &port, path);
  9704. }
  9705. sscanf(host,"%[^/]%s",host1, path1);
  9706. sprintf(ftppath,"%s", path1);
  9707. //DEBUG_INFO("protocol =%s\n",protocol);
  9708. //DEBUG_INFO("user =%s\n",user);
  9709. //DEBUG_INFO("password =%s\n",password);
  9710. //DEBUG_INFO("host1 =%s\n",host1);
  9711. //DEBUG_INFO("port =%d\n",port);
  9712. //DEBUG_INFO("path1 =%s\n",path1);
  9713. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9714. //ftpFile(host, user, password, port, ftppath, fname);
  9715. //download firmware pthred
  9716. if(port == 0)
  9717. {
  9718. port = 21;
  9719. }
  9720. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9721. do{
  9722. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9723. sleep(retryIntervalInt);
  9724. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9725. if(!isSuccess)
  9726. {
  9727. //BulldogUtil.sleepMs(interval*1000);
  9728. DEBUG_INFO("Update firmware request and download file fail.\n");
  9729. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9730. }
  9731. else
  9732. {
  9733. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9734. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9735. //isUpdateRequest = TRUE;
  9736. }
  9737. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9738. }
  9739. else
  9740. {
  9741. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9742. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9743. }
  9744. pthread_exit(NULL);
  9745. }
  9746. //==========================================
  9747. // Handle server response routine
  9748. //==========================================
  9749. void handleAuthorizeResponse(char *payload, int gun_index)
  9750. {
  9751. mtrace();
  9752. char expiryDatestr[30]={0};
  9753. char parentIdTagstr[20]={0};
  9754. char statusstr[20]={0};
  9755. char expiryDatestrtemp[30]={0};
  9756. char parentIdTagstrtemp[20]={0};
  9757. char IdTagstrtemp[20]={0};
  9758. char statusstrtemp[20]={0};
  9759. int expiryDateISNULL=FALSE;
  9760. int parentIdTagISNULL=FALSE;
  9761. char sstr[160]={0},sstrtemp[160]={0};
  9762. char* filename = AuthorizationCache_JSON;
  9763. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9764. int c = 0;
  9765. char *loc;
  9766. int resultRename=0;
  9767. int responseIdTagInfoAsZero= 0;
  9768. char rmFileCmd[50]={0};
  9769. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9770. strcpy(sstrtemp, stringtrimspace(payload));
  9771. //***********expiryDate*************/
  9772. loc = strstr(sstrtemp, "expiryDate");
  9773. memset(sstr ,0, sizeof(sstr) );
  9774. c = 0;
  9775. if(loc == NULL)
  9776. {
  9777. expiryDateISNULL = TRUE;
  9778. }
  9779. else
  9780. {
  9781. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9782. {
  9783. sstr[c] = loc[3+strlen("expiryDate")+c];
  9784. c++;
  9785. }
  9786. sstr[c] = '\0';
  9787. strcpy(expiryDatestr, sstr);
  9788. }
  9789. //***********parentIdTag*************/
  9790. loc = strstr(sstrtemp, "parentIdTag");
  9791. memset(sstr ,0, sizeof(sstr) );
  9792. c = 0;
  9793. if(loc == NULL)
  9794. {
  9795. parentIdTagISNULL = TRUE;
  9796. }
  9797. else
  9798. {
  9799. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9800. {
  9801. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9802. c++;
  9803. }
  9804. sstr[c] = '\0';
  9805. strcpy(parentIdTagstr, sstr);
  9806. }
  9807. //***********status*************/
  9808. loc = strstr(sstrtemp, "status");
  9809. memset(sstr ,0, sizeof(sstr) );
  9810. c = 0;
  9811. while (loc[3+strlen("status")+c] != '\"')
  9812. {
  9813. sstr[c] = loc[3+strlen("status")+c];
  9814. c++;
  9815. }
  9816. sstr[c] = '\0';
  9817. strcpy(statusstr, sstr);
  9818. if(expiryDateISNULL == FALSE)
  9819. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9820. if(parentIdTagISNULL == FALSE)
  9821. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9822. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9823. //Update idTag information to authorization cache if supproted
  9824. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9825. {
  9826. if((access(filename,F_OK))!=-1)
  9827. {
  9828. printf("AuthorizationCache exist.\n");
  9829. }
  9830. else
  9831. {
  9832. printf("AuthorizationCache not exist\n");
  9833. FILE *log = fopen(filename, "w+");
  9834. if(log == NULL)
  9835. {
  9836. printf("log is NULL\n");
  9837. goto out;
  9838. }
  9839. else
  9840. {
  9841. fclose(log);
  9842. }
  9843. }
  9844. FILE *infile;
  9845. FILE *outfile;
  9846. // open file for writing
  9847. infile = fopen (filename, "r");
  9848. outfile = fopen (tempfile, "w");
  9849. //*检测到文件结束标识返回1,否则返回0。*/
  9850. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9851. int c;
  9852. c = fgetc(infile);
  9853. //DEBUG_INFO("c:%d\n",c);
  9854. rewind(infile);
  9855. if(c == EOF)
  9856. {
  9857. DEBUG_INFO("Orignal File is NULL\n");
  9858. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9859. {
  9860. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9861. }
  9862. else
  9863. {
  9864. strcpy(expiryDatestrtemp, "");
  9865. }
  9866. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9867. {
  9868. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9869. }
  9870. else
  9871. {
  9872. //write Authorize IdTag
  9873. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9874. }
  9875. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9876. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9877. fclose(infile);
  9878. fclose(outfile);
  9879. sprintf(rmFileCmd,"rm -f %s",filename);
  9880. system(rmFileCmd);
  9881. resultRename = rename(tempfile, filename);
  9882. if(resultRename == 0)
  9883. {
  9884. printf("File renamed successfully");
  9885. }
  9886. else
  9887. {
  9888. printf("Error: unable to rename the file");
  9889. }
  9890. }
  9891. else
  9892. {
  9893. char buf[160]={0};
  9894. while (fgets(buf, sizeof(buf), infile) != NULL)
  9895. {
  9896. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9897. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9898. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9899. memset(statusstr, 0, sizeof(statusstrtemp));
  9900. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9901. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9902. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9903. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9904. //------------------IdTag-----------------------
  9905. loc = strstr(buf, "idTag");
  9906. memset(sstr ,0, sizeof(sstr) );
  9907. c = 0;
  9908. while (loc[3+strlen("idTag")+c] != '\"')
  9909. {
  9910. sstr[c] = loc[3+strlen("idTag")+c];
  9911. c++;
  9912. }
  9913. sstr[c] = '\0';
  9914. strcpy(IdTagstrtemp,sstr);
  9915. //*********************expiryDate***************/
  9916. loc = strstr(buf, "expiryDate");
  9917. memset(sstr ,0, sizeof(sstr) );
  9918. c = 0;
  9919. while (loc[3+strlen("expiryDate")+c] != '\"')
  9920. {
  9921. sstr[c] = loc[3+strlen("expiryDate")+c];
  9922. c++;
  9923. }
  9924. sstr[c] = '\0';
  9925. strcpy(expiryDatestr,sstr);
  9926. //*********************parentIdTag***************/
  9927. loc = strstr(buf, "parentIdTag");
  9928. memset(sstr ,0, sizeof(sstr) );
  9929. c = 0;
  9930. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9931. {
  9932. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9933. c++;
  9934. }
  9935. sstr[c] = '\0';
  9936. strcpy(parentIdTagstr,sstr);
  9937. //*********************status***************/
  9938. loc = strstr(buf, "status");
  9939. memset(sstr ,0, sizeof(sstr) );
  9940. c = 0;
  9941. while (loc[3+strlen("status")+c] != '\"')
  9942. {
  9943. sstr[c] = loc[3+strlen("status")+c];
  9944. c++;
  9945. }
  9946. sstr[c] = '\0';
  9947. strcpy(statusstr,sstr);
  9948. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9949. {
  9950. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9951. responseIdTagInfoAsZero = 1;
  9952. }
  9953. else
  9954. {
  9955. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9956. }
  9957. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9958. {
  9959. //modify item
  9960. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9961. {
  9962. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9963. }
  9964. else
  9965. {
  9966. strcpy(expiryDatestrtemp, "");
  9967. }
  9968. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9969. {
  9970. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9971. }
  9972. else
  9973. {
  9974. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9975. }
  9976. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9977. }
  9978. else
  9979. {
  9980. //wrie original item
  9981. strcpy(expiryDatestrtemp, expiryDatestr);
  9982. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9983. strcpy(statusstrtemp, statusstr);
  9984. }
  9985. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9986. }
  9987. fclose(infile);
  9988. fclose(outfile);
  9989. sprintf(rmFileCmd,"rm -f %s",filename);
  9990. system(rmFileCmd);
  9991. resultRename = rename(tempfile, filename);
  9992. if(resultRename == 0)
  9993. {
  9994. DEBUG_INFO("File renamed successfully");
  9995. }
  9996. else
  9997. {
  9998. DEBUG_INFO("Error: unable to rename the file");
  9999. }
  10000. }
  10001. }
  10002. out:
  10003. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10004. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10005. authorizeRetryTimes = 0;
  10006. }
  10007. char * strtrimc( char * s )
  10008. {
  10009. char * p1 = s;
  10010. char * p2 = s;
  10011. while(*p1 != '\0')
  10012. {
  10013. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  10014. {
  10015. if(*p1 != ',')
  10016. {
  10017. p1 ++;
  10018. }
  10019. else
  10020. {
  10021. break;
  10022. }
  10023. }
  10024. if(*p1 != ',')
  10025. {
  10026. * p2 ++ = *p1 ++;
  10027. //printf("p2=%s\n",p2);
  10028. }
  10029. else
  10030. {
  10031. break;
  10032. }
  10033. }
  10034. *p2 = '\0';
  10035. return (s);
  10036. }
  10037. void handleBootNotificationResponse(char *payload, int gun_index)
  10038. {
  10039. mtrace();
  10040. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10041. char statusStr[12]={0};
  10042. char currentTimeStr[30]={0};
  10043. char *loc;
  10044. int intervalInt = 0;
  10045. int c = 0;
  10046. //double diff_t;
  10047. struct tm tp;
  10048. char buf[28]={0};
  10049. char timebuf[50]={0};
  10050. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10051. //Filter string space
  10052. strcpy(sstrtemp, stringtrimspace(payload));
  10053. //*** interval ****/
  10054. c = 0;
  10055. loc = strstr(sstrtemp, "interval");
  10056. //printf("loc=%s\n",loc);
  10057. memset(sstr ,0, sizeof(sstr) );
  10058. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10059. {
  10060. sstr[c] = loc[strlen("interval")+2+c];
  10061. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10062. c++;
  10063. }
  10064. sstr[c] = '\0';
  10065. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10066. intervalInt = atoi(sstr);
  10067. //***status ****/
  10068. loc = strstr(sstrtemp, "status");
  10069. memset(sstr ,0, sizeof(sstr) );
  10070. c = 0;
  10071. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10072. {
  10073. sstr[c] = loc[3+strlen("status")+c];
  10074. c++;
  10075. }
  10076. sstr[c] = '\0';
  10077. strcpy(statusStr, sstr);
  10078. //***currentTime ****/
  10079. loc = strstr(sstrtemp, "currentTime");
  10080. //printf("loc=%s\n",loc);
  10081. memset(sstr ,0, sizeof(sstr) );
  10082. c = 0;
  10083. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10084. {
  10085. sstr[c] = loc[3+strlen("currentTime")+c];
  10086. c++;
  10087. }
  10088. sstr[c] = '\0';
  10089. strcpy(currentTimeStr, sstr);
  10090. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10091. //HeartBeatWaitTime = BootNotificationInterval;
  10092. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10093. BootNotificationInterval = intervalInt;
  10094. HeartBeatWaitTime = intervalInt;
  10095. clientTime.Heartbeat=time((time_t*)NULL);
  10096. //write back to ShmOCPP16Data->BootNotification
  10097. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10098. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10099. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10100. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10101. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10102. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10103. {
  10104. server_sign = TRUE;
  10105. server_pending =FALSE;
  10106. }
  10107. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10108. {
  10109. server_pending = TRUE;
  10110. }
  10111. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10112. tp.tm_isdst = -1;
  10113. //time_t utc = mktime(&tp);
  10114. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10115. memset(timebuf, 0, sizeof timebuf);
  10116. sprintf(timebuf,"date -s '%s'",buf);
  10117. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10118. system(timebuf);
  10119. //==============================================
  10120. // RTC sync
  10121. //==============================================
  10122. system("/sbin/hwclock -w --systohc");
  10123. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10124. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10125. }
  10126. void handleDataTransferResponse(char *payload, int gun_index)
  10127. {
  10128. char sstr[160]={0};//sstr[200]={ 0 };
  10129. int c = 0;
  10130. char *loc;
  10131. DEBUG_INFO("handleDataTransferResponse ...\n");
  10132. loc = strstr(payload, "status");
  10133. printf("loc=%s\n",loc);
  10134. c = 0;
  10135. while (loc[3+strlen("status")+c] != '\"')
  10136. {
  10137. sstr[c] = loc[3+strlen("status")+c];
  10138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10139. c++;
  10140. }
  10141. sstr[c] = '\0';
  10142. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10143. }
  10144. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10145. {
  10146. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10147. //struct json_object *obj;
  10148. // obj = json_tokener_parse(payload);
  10149. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10150. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10151. //No fields are defined.
  10152. }
  10153. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10154. {
  10155. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10156. //struct json_object *obj;
  10157. // obj = json_tokener_parse(payload);
  10158. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10159. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10160. //No fields are defined.
  10161. }
  10162. void handleHeartbeatResponse(char *payload, int gun_index)
  10163. {
  10164. mtrace();
  10165. //double diff_t;
  10166. struct tm tp;
  10167. char buf[28]={0};
  10168. char timebuf[50]={0},sstrtemp[100]={0};
  10169. char sstr[30]={ 0 };
  10170. int c = 0;
  10171. char *loc;
  10172. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10173. if(FirstHeartBeat == 0)
  10174. {
  10175. FirstHeartBeat = 1;
  10176. DEBUG_INFO("FirstHeartBeat \n");
  10177. }
  10178. HeartBeatWithNOResponse = 0;
  10179. strcpy(sstrtemp, stringtrimspace(payload));
  10180. c = 0;
  10181. loc = strstr(sstrtemp, "currentTime");
  10182. memset(sstr ,0, sizeof(sstr) );
  10183. while (loc[3+strlen("currentTime")+c] != '\"')
  10184. {
  10185. sstr[c] = loc[3+strlen("currentTime")+c];
  10186. c++;
  10187. }
  10188. sstr[c] = '\0';
  10189. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10190. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10191. tp.tm_isdst = -1;
  10192. //time_t utc = mktime(&tp);
  10193. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10194. memset(timebuf, 0, sizeof timebuf);
  10195. sprintf(timebuf,"date -s '%s'",buf);
  10196. system(timebuf);
  10197. //==============================================
  10198. // RTC sync
  10199. //==============================================
  10200. system("/sbin/hwclock -w --systohc");
  10201. //===============================================
  10202. //Print Out HeartBeat log
  10203. //===============================================
  10204. {
  10205. double diff_t;
  10206. struct tm tp,tp1;
  10207. // BootNotification Receive Time
  10208. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10209. tp.tm_isdst = -1;
  10210. time_t BootNotificationReceiveTime = mktime(&tp);
  10211. //HeartBeat Receive Time
  10212. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10213. tp1.tm_isdst = -1;
  10214. time_t HeartBeatReceiveTime = mktime(&tp1);
  10215. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10216. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10217. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10218. {
  10219. HeartBeatCountPerHour = (int)diff_t / 3600;
  10220. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10221. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10222. }
  10223. }
  10224. }
  10225. void handleMeterValuesResponse(char *payload, int gun_index)
  10226. {
  10227. mtrace();
  10228. //struct json_object *obj;
  10229. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10230. //No fields are defined.
  10231. }
  10232. void handleStartTransactionResponse(char *payload, int gun_index)
  10233. {
  10234. mtrace();
  10235. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10236. int c = 0;
  10237. int copyTo = 0;
  10238. char *loc;
  10239. //int transactionIdInt = 0;
  10240. FILE *outfile;
  10241. char data[100]={0};
  10242. //char *delim = ":";
  10243. //char requestKey[2][50]={0};
  10244. //char * pch;
  10245. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10246. DEBUG_INFO("handleStartTransactionResponse\n");
  10247. //****************expiryDate********************/
  10248. strcpy(sstrtemp, stringtrimspace(payload));
  10249. loc = strstr(sstrtemp, "expiryDate");
  10250. if(loc == NULL)
  10251. {
  10252. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10253. }
  10254. else
  10255. {
  10256. #if 0
  10257. c = 0;
  10258. memset(sstr ,0, sizeof(sstr) );
  10259. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10260. memset(requestKey ,0, sizeof(requestKey) );
  10261. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10262. //printf("sstrtemp=%s\n",sstrtemp);
  10263. //parsing strings to words
  10264. pch = strtok(sstrtemp,",");
  10265. while (pch != NULL)
  10266. {
  10267. strcpy(requestKey[c], pch);
  10268. pch = strtok (NULL, ",");
  10269. c = c + 1;
  10270. }
  10271. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10272. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10273. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10274. #endif
  10275. #if 1
  10276. c = 0;
  10277. memset(sstr ,0, sizeof(sstr) );
  10278. while (loc[3+strlen("expiryDate")+c] != '\"')
  10279. {
  10280. sstr[c] = loc[3+strlen("expiryDate")+c];
  10281. c++;
  10282. }
  10283. sstr[c] = '\0';
  10284. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10285. #endif
  10286. }
  10287. //****************parentIdTag********************/
  10288. loc = strstr(sstrtemp, "parentIdTag");
  10289. if(loc == NULL)
  10290. {
  10291. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10292. }
  10293. else
  10294. {
  10295. #if 0
  10296. c = 0;
  10297. memset(sstr ,0, sizeof(sstr) );
  10298. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10299. memset(requestKey ,0, sizeof(requestKey) );
  10300. strcpy(sstrtemp,loc);
  10301. //printf("sstrtemp=%s\n",sstrtemp);
  10302. //parsing strings to words
  10303. pch = strtok(sstrtemp,delim);
  10304. while (pch != NULL)
  10305. {
  10306. strcpy(requestKey[c], pch);
  10307. pch = strtok (NULL, delim);
  10308. c = c + 1;
  10309. }
  10310. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10311. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10312. #endif
  10313. #if 1
  10314. c = 0;
  10315. memset(sstr ,0, sizeof(sstr) );
  10316. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10317. {
  10318. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10319. c++;
  10320. }
  10321. sstr[c] = '\0';
  10322. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10323. #endif
  10324. }
  10325. //****************status********************/
  10326. loc = strstr(sstrtemp, "status");
  10327. if(loc == NULL)
  10328. {
  10329. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10330. }
  10331. else
  10332. {
  10333. #if 0
  10334. c = 0;
  10335. memset(sstr ,0, sizeof(sstr) );
  10336. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10337. memset(requestKey ,0, sizeof(requestKey) );
  10338. strcpy(sstrtemp,loc);
  10339. //printf("sstrtemp=%s\n",sstrtemp);
  10340. //parsing strings to words
  10341. pch = strtok(sstrtemp,delim);
  10342. while (pch != NULL)
  10343. {
  10344. strcpy(requestKey[c], pch);
  10345. pch = strtok (NULL, delim);
  10346. c = c + 1;
  10347. }
  10348. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10349. //strcpy(statusStr, strtrimc(requestKey[1]));
  10350. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10351. #endif
  10352. #if 1
  10353. c = 0;
  10354. memset(sstr ,0, sizeof(sstr) );
  10355. while (loc[3+strlen("status")+c] != '\"')
  10356. {
  10357. sstr[c] = loc[3+strlen("status")+c];
  10358. c++;
  10359. }
  10360. sstr[c] = '\0';
  10361. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10362. #endif
  10363. }
  10364. //****************transactionId********************/
  10365. c=0;
  10366. copyTo = 0;
  10367. loc = strstr(sstrtemp, "transactionId");
  10368. memset(sstr ,0, sizeof(sstr) );
  10369. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10370. {
  10371. if(loc[strlen("transactionId")+2+c] != ' ')
  10372. {
  10373. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10374. copyTo = copyTo + 1;
  10375. }
  10376. c++;
  10377. }
  10378. sstr[copyTo] = '\0';
  10379. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10380. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10381. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10382. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10383. //-----------Start : write to the Queue TransactionId file -----------------//
  10384. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10385. {
  10386. //DEBUG_INFO("QueueTransactionId exist.\n");
  10387. }
  10388. else
  10389. {
  10390. //DEBUG_INFO("QueueTransactionId not exist\n");
  10391. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10392. if(log == NULL)
  10393. {
  10394. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10395. return ;
  10396. }
  10397. else
  10398. {
  10399. fclose(log);
  10400. }
  10401. }
  10402. // open file for writing
  10403. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10404. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10405. {
  10406. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10407. //DEBUG_INFO("data=%s\n",data);
  10408. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10409. fputs(data, outfile);
  10410. //fputs("\n", outfile);
  10411. fclose (outfile);
  10412. }
  10413. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10414. //TransactionId[gun_index] = transactionIdInt;
  10415. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10416. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10417. #ifdef SystemLogMessage
  10418. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10419. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10420. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10421. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10422. #endif
  10423. }
  10424. void handleStatusNotificationResponse(char *payload, int gun_index)
  10425. {
  10426. mtrace();
  10427. printf("handleStatusNotificationResponse\n");
  10428. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10429. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10430. }
  10431. void handleStopTransactionnResponse(char *payload, int gun_index)
  10432. {
  10433. mtrace();
  10434. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10435. int c = 0;
  10436. char *loc;
  10437. //char *delim = ":";
  10438. //char requestKey[3][50]={0};
  10439. //char * pch;
  10440. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10441. strcpy(sstrtemp, stringtrimspace(payload));
  10442. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10443. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10444. loc = strstr(sstrtemp, "idTagInfo");
  10445. //***********************idTagInfo************************/
  10446. if(loc != NULL)
  10447. {
  10448. //***********************expiryDate************************/
  10449. loc = strstr(sstrtemp, "expiryDate");
  10450. if(loc != NULL)
  10451. {
  10452. memset(sstr ,0, sizeof(sstr) );
  10453. c = 0;
  10454. while (loc[3+strlen("expiryDate")+c] != '\"')
  10455. {
  10456. sstr[c] = loc[3+strlen("expiryDate")+c];
  10457. c++;
  10458. }
  10459. sstr[c] = '\0';
  10460. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10461. }
  10462. //***********************parentIdTag************************/
  10463. loc = strstr(sstrtemp, "parentIdTag");
  10464. if(loc != NULL)
  10465. {
  10466. memset(sstr ,0, sizeof(sstr) );
  10467. c = 0;
  10468. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10469. {
  10470. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10471. c++;
  10472. }
  10473. sstr[c] = '\0';
  10474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10475. }
  10476. //***********************status************************/
  10477. loc = strstr(sstrtemp, "status");
  10478. memset(sstr ,0, sizeof(sstr) );
  10479. c = 0;
  10480. while (loc[3+strlen("status")+c] != '\"')
  10481. {
  10482. sstr[c] = loc[3+strlen("status")+c];
  10483. c++;
  10484. }
  10485. sstr[c] = '\0';
  10486. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10487. }
  10488. #ifdef SystemLogMessage
  10489. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10490. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10491. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10492. #endif
  10493. }
  10494. //==========================================
  10495. // Handle Error routine
  10496. //==========================================
  10497. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10498. {
  10499. mtrace();
  10500. #ifdef SystemLogMessage
  10501. DEBUG_INFO("errorCode: %s\n", errorCode);
  10502. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10503. DEBUG_INFO("errorDetails: %s\n", payload);
  10504. #endif
  10505. }
  10506. //===============================================
  10507. // Common routine
  10508. //===============================================
  10509. int initialConfigurationTable(void)
  10510. {
  10511. //clock_t start_t, end_t, total_t;
  10512. FILE *fp;
  10513. FILE *outfile;
  10514. char str[200]={0};
  10515. char sstr[100]={0};
  10516. int c = 0;
  10517. char *loc;
  10518. printf("initialConfigurationTable \n");
  10519. //start_t = clock();
  10520. //printf("Starting of the program, start_t = %ld\n", start_t);
  10521. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10522. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10523. {
  10524. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10525. if(outfile == NULL) {
  10526. DEBUG_INFO("Error opening file");
  10527. return FALSE;
  10528. }
  10529. /*Core Profile*/
  10530. //AllowOfflineTxForUnknownId
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10532. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10536. //AuthorizationCacheEnabled
  10537. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10541. //AuthorizeRemoteTxRequests
  10542. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10546. //BlinkRepeat
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10550. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10551. //ClockAlignedDataInterval
  10552. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10554. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10555. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10556. //ConnectionTimeOut
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10560. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10561. //GetConfigurationMaxKeys
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10566. // HeartbeatInterval
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10571. // LightIntensity
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10576. // LocalAuthorizeOffline
  10577. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10581. // LocalPreAuthorize
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10585. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10586. // MaxEnergyOnInvalidId
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10590. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10592. // MeterValuesAlignedData
  10593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10596. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10597. // MeterValuesAlignedDataMaxLength
  10598. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10600. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10601. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10602. // MeterValuesSampledData
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10606. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10607. // MeterValuesSampledDataMaxLength
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10612. // MeterValueSampleInterval
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10617. // MinimumStatusDuration
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10621. server_cycle_Status = 120; //StatusNotification cycle
  10622. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10623. // NumberOfConnectors
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10626. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10627. {
  10628. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10629. }
  10630. else
  10631. {
  10632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10633. }
  10634. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10635. // ResetRetries
  10636. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10640. // ConnectorPhaseRotation
  10641. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10645. // ConnectorPhaseRotationMaxLength
  10646. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10650. // StopTransactionOnEVSideDisconnect
  10651. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10655. // StopTransactionOnInvalidId
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10659. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10660. // StopTxnAlignedData
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10665. // StopTxnAlignedDataMaxLength
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10670. // StopTxnSampledData
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10675. // StopTxnSampledDataMaxLength
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10679. {
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10681. }
  10682. else
  10683. {
  10684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10685. }
  10686. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10688. // SupportedFeatureProfiles
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10693. // SupportedFeatureProfilesMaxLength
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10698. // TransactionMessageAttempts
  10699. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10702. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10704. // TransactionMessageRetryInterval
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10708. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10710. // UnlockConnectorOnEVSideDisconnect
  10711. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10715. // WebSocketPingInterval
  10716. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10720. //* Local Auth List Management Profile*/
  10721. #if 0
  10722. //For OCTT Test Case
  10723. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10726. #endif
  10727. #if 1
  10728. //LocalAuthListEnabled
  10729. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10732. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10733. #endif
  10734. //LocalAuthListMaxLength
  10735. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10739. //SendLocalListMaxLength
  10740. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10744. //ReserveConnectorZeroSupported
  10745. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10749. //* Smart Charging Profile */
  10750. //ChargeProfileMaxStackLevel
  10751. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10755. // ChargingScheduleAllowedChargingRateUnit
  10756. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10760. // ChargingScheduleMaxPeriods
  10761. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10765. // ConnectorSwitch3to1PhaseSupported
  10766. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10770. // MaxChargingProfilesInstalled
  10771. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10775. fclose(outfile);
  10776. }
  10777. else
  10778. {
  10779. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10780. char keystr[60]={0};
  10781. char readonlystr[10]={0};
  10782. char valuestr[100]={0};
  10783. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10784. if(fp == NULL) {
  10785. DEBUG_INFO("Error opening file");
  10786. return FALSE;
  10787. }
  10788. while( fgets (str, sizeof(str), fp)!=NULL )
  10789. {
  10790. //DEBUG_INFO("Get Configuration \n");
  10791. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10792. //*************************key*********************************/
  10793. loc = strstr(str, "key");
  10794. c = 0;
  10795. memset(sstr ,0, sizeof(sstr) );
  10796. while (loc[strlen("key")+3+c] != '\"')
  10797. {
  10798. sstr[c] = loc[strlen("key")+3+c];
  10799. c++;
  10800. }
  10801. sstr[c] = '\0';
  10802. strcpy(keystr,sstr);
  10803. //*************************readonly*********************************/
  10804. loc = strstr(str, "readonly");
  10805. c = 0;
  10806. memset(sstr ,0, sizeof(sstr) );
  10807. while (loc[strlen("readonly")+2+c] != ',')
  10808. {
  10809. sstr[c] = loc[strlen("readonly")+2+c];
  10810. c++;
  10811. }
  10812. sstr[c] = '\0';
  10813. strcpy(readonlystr,sstr);
  10814. //*************************value*********************************/
  10815. loc = strstr(str, "value");
  10816. c = 0;
  10817. memset(sstr ,0, sizeof(sstr) );
  10818. while (loc[strlen("value")+3+c] != '\"')
  10819. {
  10820. sstr[c] = loc[strlen("value")+3+c];
  10821. c++;
  10822. }
  10823. sstr[c] = '\0';
  10824. strcpy(valuestr,sstr);
  10825. // DEBUG_INFO("keystr=%s\n",keystr);
  10826. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10827. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10828. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10829. {
  10830. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10831. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10832. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10833. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10834. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10835. }
  10836. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10837. {
  10838. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10839. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10840. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10841. }
  10842. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10843. {
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10846. }
  10847. if(strcmp(keystr, "BlinkRepeat") == 0)
  10848. {
  10849. //Charger.BlinkRepeat = Integer.parseInt(value);
  10850. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10852. }
  10853. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10854. {
  10855. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10857. }
  10858. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10859. {
  10860. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10861. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10862. }
  10863. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10864. {
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10867. }
  10868. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10869. {
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10872. HeartBeatWaitTime = atoi(valuestr);
  10873. }
  10874. if(strcmp(keystr, "LightIntensity") == 0)
  10875. {
  10876. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10878. }
  10879. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10880. {
  10881. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10882. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10883. }
  10884. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10885. {
  10886. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10888. }
  10889. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10890. {
  10891. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10892. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10893. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10894. }
  10895. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10896. {
  10897. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10899. }
  10900. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10901. {
  10902. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10904. }
  10905. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10906. {
  10907. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10909. }
  10910. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10911. {
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10914. }
  10915. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10916. {
  10917. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10919. }
  10920. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10921. {
  10922. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10924. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10925. }
  10926. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10927. {
  10928. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10930. }
  10931. if(strcmp(keystr, "ResetRetries") == 0)
  10932. {
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10935. }
  10936. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10937. {
  10938. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10940. }
  10941. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10942. {
  10943. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10944. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10945. }
  10946. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10947. {
  10948. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10950. }
  10951. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10952. {
  10953. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10954. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10955. }
  10956. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10957. {
  10958. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10960. }
  10961. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10962. {
  10963. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10964. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10965. }
  10966. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10967. {
  10968. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10969. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10970. }
  10971. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10972. {
  10973. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10974. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10975. }
  10976. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10977. {
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10980. }
  10981. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10982. {
  10983. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10985. }
  10986. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10987. {
  10988. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10990. TransactionMessageAttemptsValue = atoi(valuestr);
  10991. }
  10992. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10993. {
  10994. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10996. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10997. }
  10998. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10999. {
  11000. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11001. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11002. }
  11003. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11004. {
  11005. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11007. }
  11008. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11009. {
  11010. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11012. }
  11013. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11014. {
  11015. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11016. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11017. }
  11018. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11019. {
  11020. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11022. }
  11023. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11024. {
  11025. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11026. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11027. }
  11028. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11029. {
  11030. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11032. }
  11033. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11034. {
  11035. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11037. }
  11038. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11039. {
  11040. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11042. }
  11043. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11044. {
  11045. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11047. }
  11048. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11049. {
  11050. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11052. }
  11053. }
  11054. fclose(fp);
  11055. }
  11056. //end_t = clock();
  11057. //printf("End of the big loop, end_t = %ld\n", end_t);
  11058. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11059. //printf("Total time taken by CPU: %f\n", total_t );
  11060. return 0;
  11061. }
  11062. void StoreConfigurationTable(void)
  11063. {
  11064. FILE *outfile;
  11065. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11066. if(outfile == NULL)
  11067. {
  11068. DEBUG_INFO("Error opening file");
  11069. return ;
  11070. }
  11071. /*Core Profile*/
  11072. //AllowOfflineTxForUnknownId
  11073. /*
  11074. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11075. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11078. */
  11079. //DEBUG_INFO("data=%s\n",data);
  11080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11081. //AuthorizationCacheEnabled
  11082. /*
  11083. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11086. */
  11087. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11088. //AuthorizeRemoteTxRequests
  11089. /*
  11090. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11093. */
  11094. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11095. //BlinkRepeat
  11096. /*
  11097. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11098. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11100. */
  11101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11102. //ClockAlignedDataInterval
  11103. /*
  11104. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11107. */
  11108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11109. //ConnectionTimeOut
  11110. /*
  11111. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11113. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11114. */
  11115. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11116. //GetConfigurationMaxKeys
  11117. /*
  11118. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11121. */
  11122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11123. // HeartbeatInterval
  11124. /*
  11125. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11128. */
  11129. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11130. // LightIntensity
  11131. /*
  11132. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11133. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11135. */
  11136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11137. // LocalAuthorizeOffline
  11138. /*
  11139. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11142. */
  11143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11144. // LocalPreAuthorize
  11145. /*
  11146. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11149. */
  11150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11151. // MaxEnergyOnInvalidId
  11152. /*
  11153. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11156. */
  11157. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11158. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11159. // MeterValuesAlignedData
  11160. /*
  11161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11164. */
  11165. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11166. // MeterValuesAlignedDataMaxLength
  11167. /*
  11168. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11169. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11171. */
  11172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11173. // MeterValuesSampledData
  11174. /*
  11175. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11178. */
  11179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11180. // MeterValuesSampledDataMaxLength
  11181. /*
  11182. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11185. */
  11186. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11187. // MeterValueSampleInterval
  11188. /*
  11189. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11192. */
  11193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11194. // MinimumStatusDuration
  11195. /*
  11196. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11199. */
  11200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11201. // NumberOfConnectors
  11202. /*
  11203. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11205. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11206. {
  11207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11208. }
  11209. else
  11210. {
  11211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11212. }
  11213. */
  11214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11215. // ResetRetries
  11216. /*
  11217. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11220. */
  11221. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11222. // ConnectorPhaseRotation
  11223. /*
  11224. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11227. */
  11228. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11229. // ConnectorPhaseRotationMaxLength
  11230. /*
  11231. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11232. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11234. */
  11235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11236. // StopTransactionOnEVSideDisconnect
  11237. /*
  11238. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11241. */
  11242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11243. // StopTransactionOnInvalidId
  11244. /*
  11245. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11247. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11248. */
  11249. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11250. // StopTxnAlignedData
  11251. /*
  11252. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11255. */
  11256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11257. // StopTxnAlignedDataMaxLength
  11258. /*
  11259. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11260. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11262. */
  11263. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11264. // StopTxnSampledData
  11265. /*
  11266. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11269. */
  11270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11271. // StopTxnSampledDataMaxLength
  11272. /*
  11273. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11276. */
  11277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11278. // SupportedFeatureProfiles
  11279. /*
  11280. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11283. */
  11284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11285. // SupportedFeatureProfilesMaxLength
  11286. /*
  11287. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11289. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11290. */
  11291. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11292. // TransactionMessageAttempts
  11293. /*
  11294. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11295. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11297. */
  11298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11299. // TransactionMessageRetryInterval
  11300. /*
  11301. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11304. */
  11305. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11306. // UnlockConnectorOnEVSideDisconnect
  11307. /*
  11308. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11311. */
  11312. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11313. // WebSocketPingInterval
  11314. /*
  11315. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11317. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11318. */
  11319. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11320. //* Local Auth List Management Profile*/
  11321. //LocalAuthListEnabled
  11322. /*
  11323. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11326. */
  11327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11328. //LocalAuthListMaxLength
  11329. /*
  11330. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11333. */
  11334. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11335. //SendLocalListMaxLength
  11336. /*
  11337. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11339. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11340. */
  11341. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11342. //ReserveConnectorZeroSupported
  11343. /*
  11344. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11347. */
  11348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11349. //* Smart Charging Profile */
  11350. //ChargeProfileMaxStackLevel
  11351. /*
  11352. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11354. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11355. */
  11356. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11357. // ChargingScheduleAllowedChargingRateUnit
  11358. /*
  11359. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11360. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11361. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11362. */
  11363. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11364. // ChargingScheduleMaxPeriods
  11365. /*
  11366. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11367. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11368. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11369. */
  11370. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11371. // ConnectorSwitch3to1PhaseSupported
  11372. /*
  11373. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11374. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11376. */
  11377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11378. // MaxChargingProfilesInstalled
  11379. /*
  11380. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11382. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11383. */
  11384. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11385. fclose(outfile);
  11386. }
  11387. void getKeyValue(char *keyReq)
  11388. {
  11389. int isEmpty = FALSE;
  11390. int isKnowKey = FALSE;
  11391. //int unKnowIndex = 0;
  11392. DEBUG_INFO("getKeyValue \n");
  11393. DEBUG_INFO("keyReq=%s \n",keyReq);
  11394. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11395. isEmpty = TRUE;
  11396. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11400. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11403. }
  11404. else
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11407. }
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11409. isKnowKey = TRUE;
  11410. }
  11411. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11418. }
  11419. else
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11422. }
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11424. isKnowKey = TRUE;
  11425. }
  11426. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11430. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11433. }
  11434. else
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11437. }
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11439. isKnowKey = TRUE;
  11440. }
  11441. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11445. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11448. }
  11449. else
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11452. }
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11454. isKnowKey = TRUE;
  11455. }
  11456. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11460. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11463. }
  11464. else
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11467. }
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11469. isKnowKey = TRUE;
  11470. }
  11471. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11475. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11478. }
  11479. else
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11482. }
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11484. isKnowKey = TRUE;
  11485. }
  11486. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11490. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11493. }
  11494. else
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11497. }
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11499. isKnowKey = TRUE;
  11500. }
  11501. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11505. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11508. }
  11509. else
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11512. }
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11514. isKnowKey = TRUE;
  11515. }
  11516. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11523. }
  11524. else
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11527. }
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11529. isKnowKey = TRUE;
  11530. }
  11531. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11536. {
  11537. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11538. }
  11539. else
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11542. }
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11544. isKnowKey = TRUE;
  11545. }
  11546. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11551. {
  11552. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11553. }
  11554. else
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11557. }
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11559. isKnowKey = TRUE;
  11560. }
  11561. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11562. {
  11563. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11566. {
  11567. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11568. }
  11569. else
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11572. }
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11574. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11575. isKnowKey = TRUE;
  11576. }
  11577. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11581. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11584. }
  11585. else
  11586. {
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11588. }
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11590. isKnowKey = TRUE;
  11591. }
  11592. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11596. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11599. }
  11600. else
  11601. {
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11603. }
  11604. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11605. isKnowKey = TRUE;
  11606. }
  11607. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11611. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11614. }
  11615. else
  11616. {
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11618. }
  11619. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11620. isKnowKey = TRUE;
  11621. }
  11622. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11626. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11629. }
  11630. else
  11631. {
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11633. }
  11634. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11635. isKnowKey = TRUE;
  11636. }
  11637. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11641. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11644. }
  11645. else
  11646. {
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11648. }
  11649. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11650. isKnowKey = TRUE;
  11651. }
  11652. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11655. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11659. }
  11660. else
  11661. {
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11663. }
  11664. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11665. isKnowKey = TRUE;
  11666. }
  11667. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11670. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11674. }
  11675. else
  11676. {
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11678. }
  11679. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11680. isKnowKey = TRUE;
  11681. }
  11682. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11687. {
  11688. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11689. }
  11690. else
  11691. {
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11693. }
  11694. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11695. isKnowKey = TRUE;
  11696. }
  11697. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11702. {
  11703. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11704. }
  11705. else
  11706. {
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11708. }
  11709. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11710. isKnowKey = TRUE;
  11711. }
  11712. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11716. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11717. {
  11718. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11719. }
  11720. else
  11721. {
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11723. }
  11724. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11725. isKnowKey = TRUE;
  11726. }
  11727. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11732. {
  11733. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11734. }
  11735. else
  11736. {
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11738. }
  11739. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11740. isKnowKey = TRUE;
  11741. }
  11742. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11747. {
  11748. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11749. }
  11750. else
  11751. {
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11753. }
  11754. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11755. isKnowKey = TRUE;
  11756. }
  11757. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11761. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11762. {
  11763. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11764. }
  11765. else
  11766. {
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11768. }
  11769. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11770. isKnowKey = TRUE;
  11771. }
  11772. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11776. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11777. {
  11778. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11779. }
  11780. else
  11781. {
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11783. }
  11784. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11785. isKnowKey = TRUE;
  11786. }
  11787. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11792. {
  11793. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11794. }
  11795. else
  11796. {
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11798. }
  11799. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11800. isKnowKey = TRUE;
  11801. }
  11802. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11807. {
  11808. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11809. }
  11810. else
  11811. {
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11813. }
  11814. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11815. isKnowKey = TRUE;
  11816. }
  11817. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11821. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11822. {
  11823. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11824. }
  11825. else
  11826. {
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11828. }
  11829. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11830. isKnowKey = TRUE;
  11831. }
  11832. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11833. {
  11834. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11836. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11837. {
  11838. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11839. }
  11840. else
  11841. {
  11842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11843. }
  11844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11845. isKnowKey = TRUE;
  11846. }
  11847. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11848. {
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11851. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11852. {
  11853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11854. }
  11855. else
  11856. {
  11857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11858. }
  11859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11860. isKnowKey = TRUE;
  11861. }
  11862. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11863. {
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11866. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11867. {
  11868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11869. }
  11870. else
  11871. {
  11872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11873. }
  11874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11875. isKnowKey = TRUE;
  11876. }
  11877. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11878. {
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11881. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11882. {
  11883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11884. }
  11885. else
  11886. {
  11887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11888. }
  11889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11890. isKnowKey = TRUE;
  11891. }
  11892. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11893. {
  11894. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11896. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11897. {
  11898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11899. }
  11900. else
  11901. {
  11902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11903. }
  11904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11905. isKnowKey = TRUE;
  11906. }
  11907. #if 0
  11908. //For OCTT Test Case
  11909. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11910. {
  11911. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11913. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11914. {
  11915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11916. }
  11917. else
  11918. {
  11919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11920. }
  11921. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11922. isKnowKey = TRUE;
  11923. }
  11924. #endif
  11925. #if 1
  11926. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11927. {
  11928. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11930. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11931. {
  11932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11933. }
  11934. else
  11935. {
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11937. }
  11938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11939. isKnowKey = TRUE;
  11940. }
  11941. #endif
  11942. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11943. {
  11944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11946. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11947. {
  11948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11949. }
  11950. else
  11951. {
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11953. }
  11954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11955. isKnowKey = TRUE;
  11956. }
  11957. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11958. {
  11959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11961. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11962. {
  11963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11964. }
  11965. else
  11966. {
  11967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11968. }
  11969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11970. isKnowKey = TRUE;
  11971. }
  11972. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11973. {
  11974. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11976. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11977. {
  11978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11979. }
  11980. else
  11981. {
  11982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11983. }
  11984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11985. isKnowKey = TRUE;
  11986. }
  11987. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11988. {
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11991. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11992. {
  11993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11994. }
  11995. else
  11996. {
  11997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11998. }
  11999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12000. isKnowKey = TRUE;
  12001. }
  12002. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12003. {
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12006. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12007. {
  12008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12009. }
  12010. else
  12011. {
  12012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12013. }
  12014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12015. isKnowKey = TRUE;
  12016. }
  12017. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12018. {
  12019. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12021. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12022. {
  12023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12024. }
  12025. else
  12026. {
  12027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12028. }
  12029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12030. isKnowKey = TRUE;
  12031. }
  12032. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12033. {
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12036. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12037. {
  12038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12039. }
  12040. else
  12041. {
  12042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12043. }
  12044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12045. isKnowKey = TRUE;
  12046. }
  12047. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12048. {
  12049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12051. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12052. {
  12053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12054. }
  12055. else
  12056. {
  12057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12058. }
  12059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12060. isKnowKey = TRUE;
  12061. }
  12062. //=========================================================
  12063. if(!isEmpty && !isKnowKey)
  12064. {
  12065. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12066. strcpy(unknownkey[UnknownKeynum], keyReq);
  12067. UnknownKeynum = UnknownKeynum + 1;
  12068. }
  12069. }
  12070. void processUnkownKey(void)
  12071. {
  12072. DEBUG_INFO("processUnkownKey\n");
  12073. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12074. for(int index=0; index < UnknownKeynum; index++)
  12075. {
  12076. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12077. {
  12078. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12079. }
  12080. }
  12081. }
  12082. int setKeyValue(char *key, char *value)
  12083. {
  12084. int isSuccess = NotSupported;
  12085. int check_ascii=0;
  12086. char str[10]={0};
  12087. #ifdef Debug
  12088. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12089. #endif
  12090. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12091. {
  12092. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12094. {
  12095. strcpy(str, (const char*)value);
  12096. for(int i = 0; str[i]; i++){
  12097. str[i] = tolower(str[i]);
  12098. }
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. else
  12103. {
  12104. isSuccess = ConfigurationStatus_Rejected;
  12105. }
  12106. }
  12107. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12108. {
  12109. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12111. {
  12112. strcpy(str, (const char*)value);
  12113. for(int i = 0; str[i]; i++){
  12114. str[i] = tolower(str[i]);
  12115. }
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12119. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12120. }
  12121. else
  12122. {
  12123. isSuccess = ConfigurationStatus_Rejected;
  12124. }
  12125. }
  12126. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12127. {
  12128. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12129. {
  12130. strcpy(str, (const char*)value);
  12131. for(int i = 0; str[i]; i++)
  12132. {
  12133. str[i] = tolower(str[i]);
  12134. }
  12135. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12136. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12137. isSuccess = ConfigurationStatus_Accepted;
  12138. }
  12139. else
  12140. {
  12141. isSuccess = ConfigurationStatus_Rejected;
  12142. }
  12143. }
  12144. if(strcmp(key, "BlinkRepeat") == 0)
  12145. {
  12146. //Charger.BlinkRepeat = Integer.parseInt(value);
  12147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12148. {
  12149. check_ascii = value[0];
  12150. if( (check_ascii < 48) || (check_ascii > 57) )
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. else
  12155. {
  12156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12157. isSuccess = ConfigurationStatus_Accepted;
  12158. }
  12159. }
  12160. else
  12161. {
  12162. isSuccess = ConfigurationStatus_Rejected;
  12163. }
  12164. }
  12165. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12166. {
  12167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12168. {
  12169. check_ascii = value[0];
  12170. if( (check_ascii < 48) || (check_ascii > 57) )
  12171. {
  12172. isSuccess = ConfigurationStatus_Rejected;
  12173. }
  12174. else
  12175. {
  12176. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12178. isSuccess = ConfigurationStatus_Accepted;
  12179. }
  12180. }
  12181. else
  12182. {
  12183. isSuccess = ConfigurationStatus_Rejected;
  12184. }
  12185. }
  12186. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12187. {
  12188. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12189. {
  12190. check_ascii = value[0];
  12191. if( (check_ascii < 48) || (check_ascii > 57) )
  12192. {
  12193. isSuccess = ConfigurationStatus_Rejected;
  12194. }
  12195. else
  12196. {
  12197. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12199. isSuccess = ConfigurationStatus_Accepted;
  12200. }
  12201. }
  12202. else
  12203. {
  12204. isSuccess = ConfigurationStatus_Rejected;
  12205. }
  12206. }
  12207. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12208. {
  12209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12210. {
  12211. check_ascii = value[0];
  12212. if( (check_ascii < 48) || (check_ascii > 57) )
  12213. {
  12214. isSuccess = ConfigurationStatus_Rejected;
  12215. }
  12216. else
  12217. {
  12218. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12220. isSuccess = ConfigurationStatus_Accepted;
  12221. }
  12222. }
  12223. else
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. }
  12228. if(strcmp(key, "HeartbeatInterval") == 0)
  12229. {
  12230. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12231. {
  12232. check_ascii = value[0];
  12233. if( (check_ascii < 48) || (check_ascii > 57) )
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. else
  12238. {
  12239. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12241. HeartBeatWaitTime = atoi(value);
  12242. isSuccess = ConfigurationStatus_Accepted;
  12243. }
  12244. }
  12245. else
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. }
  12250. if(strcmp(key, "LightIntensity") == 0)
  12251. {
  12252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12253. {
  12254. check_ascii = value[0];
  12255. if( (check_ascii < 48) || (check_ascii > 57) )
  12256. {
  12257. isSuccess = ConfigurationStatus_Rejected;
  12258. }
  12259. else
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12271. {
  12272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12273. {
  12274. strcpy(str, (const char*)value);
  12275. for(int i = 0; str[i]; i++)
  12276. {
  12277. str[i] = tolower(str[i]);
  12278. }
  12279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12280. isSuccess = ConfigurationStatus_Accepted;
  12281. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12282. }
  12283. else
  12284. {
  12285. isSuccess = ConfigurationStatus_Rejected;
  12286. }
  12287. }
  12288. if(strcmp(key, "LocalPreAuthorize") == 0)
  12289. {
  12290. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12291. {
  12292. strcpy(str, (const char*)value);
  12293. for(int i = 0; str[i]; i++)
  12294. {
  12295. str[i] = tolower(str[i]);
  12296. }
  12297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12298. isSuccess = ConfigurationStatus_Accepted;
  12299. }
  12300. else
  12301. {
  12302. isSuccess = ConfigurationStatus_Rejected;
  12303. }
  12304. }
  12305. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12306. {
  12307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12308. {
  12309. check_ascii = value[0];
  12310. if( (check_ascii < 48) || (check_ascii > 57) )
  12311. {
  12312. isSuccess = ConfigurationStatus_Rejected;
  12313. }
  12314. else
  12315. {
  12316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12317. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. }
  12320. }
  12321. else
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. }
  12326. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12327. {
  12328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12329. {
  12330. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12331. isSuccess = ConfigurationStatus_Accepted;
  12332. }
  12333. else
  12334. {
  12335. isSuccess = ConfigurationStatus_Rejected;
  12336. }
  12337. }
  12338. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12339. {
  12340. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12341. {
  12342. check_ascii = value[0];
  12343. if( (check_ascii < 48) || (check_ascii > 57) )
  12344. {
  12345. isSuccess = ConfigurationStatus_Rejected;
  12346. }
  12347. else
  12348. {
  12349. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12351. isSuccess = ConfigurationStatus_Accepted;
  12352. }
  12353. }
  12354. else
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. }
  12359. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12360. {
  12361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12362. {
  12363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12364. isSuccess = ConfigurationStatus_Accepted;
  12365. }
  12366. else
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. }
  12371. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12372. {
  12373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12374. {
  12375. check_ascii = value[0];
  12376. if( (check_ascii < 48) || (check_ascii > 57) )
  12377. {
  12378. isSuccess = ConfigurationStatus_Rejected;
  12379. }
  12380. else
  12381. {
  12382. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12384. isSuccess = ConfigurationStatus_Accepted;
  12385. }
  12386. }
  12387. else
  12388. {
  12389. isSuccess = ConfigurationStatus_Rejected;
  12390. }
  12391. }
  12392. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12393. {
  12394. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12395. {
  12396. check_ascii = value[0];
  12397. if( (check_ascii < 48) || (check_ascii > 57) )
  12398. {
  12399. isSuccess = ConfigurationStatus_Rejected;
  12400. }
  12401. else
  12402. {
  12403. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12405. isSuccess = ConfigurationStatus_Accepted;
  12406. }
  12407. }
  12408. else
  12409. {
  12410. isSuccess = ConfigurationStatus_Rejected;
  12411. }
  12412. }
  12413. if(strcmp(key, "MinimumStatusDuration") == 0)
  12414. {
  12415. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12416. {
  12417. check_ascii = value[0];
  12418. if( (check_ascii < 48) || (check_ascii > 57) )
  12419. {
  12420. isSuccess = ConfigurationStatus_Rejected;
  12421. }
  12422. else
  12423. {
  12424. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. else
  12429. {
  12430. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12432. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12433. isSuccess = ConfigurationStatus_Accepted;
  12434. }
  12435. }
  12436. }
  12437. else
  12438. {
  12439. isSuccess = ConfigurationStatus_Rejected;
  12440. }
  12441. }
  12442. if(strcmp(key, "NumberOfConnectors") == 0)
  12443. {
  12444. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12445. {
  12446. check_ascii = value[0];
  12447. if( (check_ascii < 48) || (check_ascii > 57) )
  12448. {
  12449. isSuccess = ConfigurationStatus_Rejected;
  12450. }
  12451. else
  12452. {
  12453. //Charger.ResetRetries = Integer.parseInt(value);
  12454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12455. isSuccess = ConfigurationStatus_Accepted;
  12456. }
  12457. }
  12458. else
  12459. {
  12460. isSuccess = ConfigurationStatus_Rejected;
  12461. }
  12462. }
  12463. if(strcmp(key, "ResetRetries") == 0)
  12464. {
  12465. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12466. {
  12467. check_ascii = value[0];
  12468. if( (check_ascii < 48) || (check_ascii > 57) )
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. else
  12473. {
  12474. //Charger.ResetRetries = Integer.parseInt(value);
  12475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12476. isSuccess = ConfigurationStatus_Accepted;
  12477. }
  12478. }
  12479. else
  12480. {
  12481. isSuccess = ConfigurationStatus_Rejected;
  12482. }
  12483. }
  12484. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12485. {
  12486. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12487. {
  12488. strcpy(str, (const char*)value);
  12489. for(int i = 0; str[i]; i++)
  12490. {
  12491. str[i] = tolower(str[i]);
  12492. }
  12493. if(strcmp(str, "notapplicable")== 0)
  12494. {
  12495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12496. isSuccess = ConfigurationStatus_Accepted;
  12497. }
  12498. else if(strcmp(str, "unknown")== 0)
  12499. {
  12500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12501. isSuccess = ConfigurationStatus_Accepted;
  12502. }
  12503. else if(strcmp(str, "rst")== 0)
  12504. {
  12505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12506. isSuccess = ConfigurationStatus_Accepted;
  12507. }
  12508. else if(strcmp(str, "rts")== 0)
  12509. {
  12510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12511. isSuccess = ConfigurationStatus_Accepted;
  12512. }
  12513. else if(strcmp(str, "srt")== 0)
  12514. {
  12515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12516. isSuccess = ConfigurationStatus_Accepted;
  12517. }
  12518. else if(strcmp(str, "str")== 0)
  12519. {
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12521. isSuccess = ConfigurationStatus_Accepted;
  12522. }
  12523. else if(strcmp(str, "trs")== 0)
  12524. {
  12525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12526. isSuccess = ConfigurationStatus_Accepted;
  12527. }
  12528. else if(strcmp(str, "tsr")== 0)
  12529. {
  12530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12531. isSuccess = ConfigurationStatus_Accepted;
  12532. }
  12533. else
  12534. {
  12535. isSuccess = ConfigurationStatus_Rejected;
  12536. }
  12537. }
  12538. else
  12539. {
  12540. isSuccess = ConfigurationStatus_Rejected;
  12541. }
  12542. }
  12543. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12544. {
  12545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12546. {
  12547. check_ascii = value[0];
  12548. if( (check_ascii < 48) || (check_ascii > 57) )
  12549. {
  12550. isSuccess = ConfigurationStatus_Rejected;
  12551. }
  12552. else
  12553. {
  12554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12555. isSuccess = ConfigurationStatus_Accepted;
  12556. }
  12557. }
  12558. else
  12559. {
  12560. isSuccess = ConfigurationStatus_Rejected;
  12561. }
  12562. }
  12563. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12564. {
  12565. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12566. {
  12567. strcpy(str, (const char*)value);
  12568. for(int i = 0; str[i]; i++)
  12569. {
  12570. str[i] = tolower(str[i]);
  12571. }
  12572. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12574. isSuccess = ConfigurationStatus_Accepted;
  12575. }
  12576. else
  12577. {
  12578. isSuccess = ConfigurationStatus_Rejected;
  12579. }
  12580. }
  12581. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12582. {
  12583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12584. {
  12585. strcpy(str, (const char*)value);
  12586. for(int i = 0; str[i]; i++)
  12587. {
  12588. str[i] = tolower(str[i]);
  12589. }
  12590. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12592. isSuccess = ConfigurationStatus_Accepted;
  12593. }
  12594. else
  12595. {
  12596. isSuccess = ConfigurationStatus_Rejected;
  12597. }
  12598. }
  12599. if(strcmp(key, "StopTxnAlignedData") == 0)
  12600. {
  12601. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12602. {
  12603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12604. isSuccess = ConfigurationStatus_Accepted;
  12605. }
  12606. else
  12607. {
  12608. isSuccess = ConfigurationStatus_Rejected;
  12609. }
  12610. }
  12611. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12612. {
  12613. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12614. {
  12615. check_ascii = value[0];
  12616. if( (check_ascii < 48) || (check_ascii > 57) )
  12617. {
  12618. isSuccess = ConfigurationStatus_Rejected;
  12619. }
  12620. else
  12621. {
  12622. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12623. isSuccess = ConfigurationStatus_Accepted;
  12624. }
  12625. }
  12626. else
  12627. {
  12628. isSuccess = ConfigurationStatus_Rejected;
  12629. }
  12630. }
  12631. if(strcmp(key, "StopTxnSampledData") == 0)
  12632. {
  12633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12634. {
  12635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12636. isSuccess = ConfigurationStatus_Accepted;
  12637. }
  12638. else
  12639. {
  12640. isSuccess = ConfigurationStatus_Rejected;
  12641. }
  12642. }
  12643. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12644. {
  12645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12646. {
  12647. check_ascii = value[0];
  12648. if( (check_ascii < 48) || (check_ascii > 57) )
  12649. {
  12650. isSuccess = ConfigurationStatus_Rejected;
  12651. }
  12652. else
  12653. {
  12654. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12655. isSuccess = ConfigurationStatus_Accepted;
  12656. }
  12657. }
  12658. else
  12659. {
  12660. isSuccess = ConfigurationStatus_Rejected;
  12661. }
  12662. }
  12663. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12664. {
  12665. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12666. {
  12667. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12668. isSuccess = ConfigurationStatus_Accepted;
  12669. }
  12670. else
  12671. {
  12672. isSuccess = ConfigurationStatus_Rejected;
  12673. }
  12674. }
  12675. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12676. {
  12677. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12678. {
  12679. check_ascii = value[0];
  12680. if( (check_ascii < 48) || (check_ascii > 57) )
  12681. {
  12682. isSuccess = ConfigurationStatus_Rejected;
  12683. }
  12684. else
  12685. {
  12686. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12687. isSuccess = ConfigurationStatus_Accepted;
  12688. }
  12689. }
  12690. else
  12691. {
  12692. isSuccess = ConfigurationStatus_Rejected;
  12693. }
  12694. }
  12695. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12696. {
  12697. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12698. {
  12699. check_ascii = value[0];
  12700. if( (check_ascii < 48) || (check_ascii > 57) )
  12701. {
  12702. isSuccess = ConfigurationStatus_Rejected;
  12703. }
  12704. else
  12705. {
  12706. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12708. TransactionMessageAttemptsValue = atoi(value);
  12709. isSuccess = ConfigurationStatus_Accepted;
  12710. }
  12711. }
  12712. else
  12713. {
  12714. isSuccess = ConfigurationStatus_Rejected;
  12715. }
  12716. }
  12717. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12718. {
  12719. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12720. {
  12721. check_ascii = value[0];
  12722. if( (check_ascii < 48) || (check_ascii > 57) )
  12723. {
  12724. isSuccess = ConfigurationStatus_Rejected;
  12725. }
  12726. else
  12727. {
  12728. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12729. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12730. TransactionMessageRetryIntervalValue = atoi(value);
  12731. isSuccess = ConfigurationStatus_Accepted;
  12732. }
  12733. }
  12734. else
  12735. {
  12736. isSuccess = ConfigurationStatus_Rejected;
  12737. }
  12738. }
  12739. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12742. {
  12743. strcpy(str, (const char*)value);
  12744. for(int i = 0; str[i]; i++)
  12745. {
  12746. str[i] = tolower(str[i]);
  12747. }
  12748. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12749. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12750. isSuccess = ConfigurationStatus_Accepted;
  12751. }
  12752. else
  12753. {
  12754. isSuccess = ConfigurationStatus_Rejected;
  12755. }
  12756. }
  12757. if(strcmp(key, "WebSocketPingInterval") == 0)
  12758. {
  12759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12760. {
  12761. check_ascii = value[0];
  12762. if( (check_ascii < 48) || (check_ascii > 57) )
  12763. {
  12764. isSuccess = ConfigurationStatus_Rejected;
  12765. }
  12766. else
  12767. {
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12769. isSuccess = ConfigurationStatus_Accepted;
  12770. }
  12771. }
  12772. else
  12773. {
  12774. isSuccess = ConfigurationStatus_Rejected;
  12775. }
  12776. }
  12777. #if 0
  12778. //For OCPP Test Case
  12779. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12780. {
  12781. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12782. {
  12783. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12784. isSuccess = ConfigurationStatus_Accepted;
  12785. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12786. }
  12787. else
  12788. {
  12789. isSuccess = ConfigurationStatus_Rejected;
  12790. }
  12791. }
  12792. #endif
  12793. #if 1
  12794. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12795. {
  12796. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12797. {
  12798. strcpy(str, (const char*)value);
  12799. for(int i = 0; str[i]; i++)
  12800. {
  12801. str[i] = tolower(str[i]);
  12802. }
  12803. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12804. isSuccess = ConfigurationStatus_Accepted;
  12805. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12806. }
  12807. else
  12808. {
  12809. isSuccess = ConfigurationStatus_Rejected;
  12810. }
  12811. }
  12812. #endif
  12813. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12814. {
  12815. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12816. {
  12817. check_ascii = value[0];
  12818. if( (check_ascii < 48) || (check_ascii > 57) )
  12819. {
  12820. isSuccess = ConfigurationStatus_Rejected;
  12821. }
  12822. else
  12823. {
  12824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12825. isSuccess = ConfigurationStatus_Accepted;
  12826. }
  12827. }
  12828. else
  12829. {
  12830. isSuccess = ConfigurationStatus_Rejected;
  12831. }
  12832. }
  12833. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12834. {
  12835. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12836. {
  12837. check_ascii = value[0];
  12838. if( (check_ascii < 48) || (check_ascii > 57) )
  12839. {
  12840. isSuccess = ConfigurationStatus_Rejected;
  12841. }
  12842. else
  12843. {
  12844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12845. isSuccess = ConfigurationStatus_Accepted;
  12846. }
  12847. }
  12848. else
  12849. {
  12850. isSuccess = ConfigurationStatus_Rejected;
  12851. }
  12852. }
  12853. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12854. {
  12855. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12856. {
  12857. strcpy(str, (const char*)value);
  12858. for(int i = 0; str[i]; i++)
  12859. {
  12860. str[i] = tolower(str[i]);
  12861. }
  12862. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12863. isSuccess = ConfigurationStatus_Accepted;
  12864. }
  12865. else
  12866. {
  12867. isSuccess = ConfigurationStatus_Rejected;
  12868. }
  12869. }
  12870. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12871. {
  12872. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12873. {
  12874. check_ascii = value[0];
  12875. if( (check_ascii < 48) || (check_ascii > 57) )
  12876. {
  12877. isSuccess = ConfigurationStatus_Rejected;
  12878. }
  12879. else
  12880. {
  12881. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12882. isSuccess = ConfigurationStatus_Accepted;
  12883. }
  12884. }
  12885. else
  12886. {
  12887. isSuccess = ConfigurationStatus_Rejected;
  12888. }
  12889. }
  12890. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12891. {
  12892. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12893. {
  12894. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12895. isSuccess = ConfigurationStatus_Accepted;
  12896. }
  12897. else
  12898. {
  12899. isSuccess = ConfigurationStatus_Rejected;
  12900. }
  12901. }
  12902. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12903. {
  12904. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12905. {
  12906. check_ascii = value[0];
  12907. if( (check_ascii < 48) || (check_ascii > 57) )
  12908. {
  12909. isSuccess = ConfigurationStatus_Rejected;
  12910. }
  12911. else
  12912. {
  12913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12914. isSuccess = ConfigurationStatus_Accepted;
  12915. }
  12916. }
  12917. else
  12918. {
  12919. isSuccess = ConfigurationStatus_Rejected;
  12920. }
  12921. }
  12922. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12923. {
  12924. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12925. {
  12926. strcpy(str, (const char*)value);
  12927. for(int i = 0; str[i]; i++)
  12928. {
  12929. str[i] = tolower(str[i]);
  12930. }
  12931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12932. isSuccess = ConfigurationStatus_Accepted;
  12933. }
  12934. else
  12935. {
  12936. isSuccess = ConfigurationStatus_Rejected;
  12937. }
  12938. }
  12939. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12940. {
  12941. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12942. {
  12943. check_ascii = value[0];
  12944. if( (check_ascii < 48) || (check_ascii > 57) )
  12945. {
  12946. isSuccess = ConfigurationStatus_Rejected;
  12947. }
  12948. else
  12949. {
  12950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12951. isSuccess = ConfigurationStatus_Accepted;
  12952. }
  12953. }
  12954. else
  12955. {
  12956. isSuccess = ConfigurationStatus_Rejected;
  12957. }
  12958. }
  12959. return isSuccess;
  12960. }
  12961. int updateSetting(char *key, char *value)
  12962. {
  12963. mtrace();
  12964. int isSuccess = FALSE;
  12965. char string[1000]={0}, buffer[1000]={0};
  12966. char strtemp[50]={0};
  12967. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12968. int pos, c = 0;
  12969. char *loc;
  12970. int pos1=0;
  12971. FILE *f = fopen("/var/www/settings1", "r");
  12972. if(f == NULL)
  12973. {
  12974. #ifdef Debug
  12975. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12976. #endif
  12977. return isSuccess;
  12978. }
  12979. fseek(f, 0, SEEK_END);
  12980. long fsize = ftell(f);
  12981. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12982. fread(string, 1, fsize, f);
  12983. fclose(f);
  12984. string[fsize] = 0;
  12985. loc = strstr(string, key);
  12986. if(loc != NULL)
  12987. {
  12988. DEBUG_INFO("key exist!\n");
  12989. pos = loc - string-1;
  12990. f = fopen("/var/www/settings1", "w");
  12991. strncpy(buffer, string, pos);
  12992. fprintf(f, "%s", buffer);
  12993. memset(sstr ,0, sizeof(sstr) );
  12994. c = 0;
  12995. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12996. {
  12997. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12998. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12999. c++;
  13000. }
  13001. sstr[c] = '\0';
  13002. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  13003. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  13004. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  13005. memset(buffer ,0, sizeof(buffer) );
  13006. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  13007. //printf("buffer=%s",buffer);
  13008. fprintf(f, "%s", buffer);
  13009. fclose(f);
  13010. }
  13011. else
  13012. {
  13013. printf("key not exist!\n");
  13014. f = fopen("/var/www/settings1", "w+");
  13015. fputs(string, f);
  13016. fseek(f, -1, SEEK_CUR);
  13017. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  13018. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  13019. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  13020. fclose(f);
  13021. }
  13022. isSuccess = TRUE;
  13023. return isSuccess;
  13024. }
  13025. int TransactionMessageAttemptsGet(void)
  13026. {
  13027. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13028. }
  13029. int FirstHeartBeatResponse(void)
  13030. {
  13031. return FirstHeartBeat;
  13032. }
  13033. int TransactionMessageRetryIntervalGet(void)
  13034. {
  13035. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13036. }
  13037. #define SA struct sockaddr
  13038. #define MAXBUF 1024
  13039. //static int m_socket_data;
  13040. //static int sockfd;
  13041. int ReadHttpStatus(int sock){
  13042. //char c;
  13043. char buff[1024]="",*ptr=buff+1;
  13044. int bytes_received, status;
  13045. DEBUG_INFO("Begin Response ..\n");
  13046. while((bytes_received = recv(sock, ptr, 1, 0))){
  13047. if(bytes_received==-1){
  13048. perror("ReadHttpStatus");
  13049. exit(1);
  13050. }
  13051. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13052. ptr++;
  13053. }
  13054. *ptr=0;
  13055. ptr=buff+1;
  13056. sscanf(ptr,"%*s %d ", &status);
  13057. DEBUG_INFO("%s\n",ptr);
  13058. DEBUG_INFO("status=%d\n",status);
  13059. DEBUG_INFO("End Response ..\n");
  13060. return (bytes_received>0)?status:0;
  13061. }
  13062. //the only filed that it parsed is 'Content-Length'
  13063. int ParseHeader(int sock){
  13064. //char c;
  13065. char buff[1024]="",*ptr=buff+4;
  13066. int bytes_received;
  13067. DEBUG_INFO("Begin HEADER ..\n");
  13068. while((bytes_received = recv(sock, ptr, 1, 0))){
  13069. if(bytes_received==-1){
  13070. perror("Parse Header");
  13071. exit(1);
  13072. }
  13073. if(
  13074. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13075. (ptr[-1]=='\r') && (*ptr=='\n' )
  13076. ) break;
  13077. ptr++;
  13078. }
  13079. *ptr=0;
  13080. ptr=buff+4;
  13081. //printf("%s",ptr);
  13082. if(bytes_received){
  13083. ptr=strstr(ptr,"Content-Length:");
  13084. if(ptr){
  13085. sscanf(ptr,"%*s %d",&bytes_received);
  13086. }else
  13087. bytes_received=-1; //unknown size
  13088. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13089. }
  13090. DEBUG_INFO("End HEADER ..\n");
  13091. return bytes_received ;
  13092. }
  13093. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13094. {
  13095. char rmFileCmd[100]={0};
  13096. char FilePath[100]={0};
  13097. char ftpbuf[200];
  13098. int systemresult;
  13099. //DEBUG_INFO("filename=%s\n",filename);
  13100. //DEBUG_INFO("url=%s\n",url);
  13101. sprintf(FilePath,"/mnt/%s",filename);
  13102. if((access(FilePath,F_OK))!=-1)
  13103. {
  13104. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13105. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13106. system(rmFileCmd);
  13107. }
  13108. memset(ftpbuf, 0, sizeof(ftpbuf));
  13109. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13110. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13111. systemresult = system(ftpbuf);
  13112. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13113. if(systemresult != 0)
  13114. {
  13115. DEBUG_INFO("http DownLoad error!\n");
  13116. return FALSE;
  13117. }
  13118. return TRUE;
  13119. }
  13120. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13121. {
  13122. char rmFileCmd[100]={0};
  13123. char FilePath[100]={0};
  13124. char ftpbuf[200];
  13125. int systemresult;
  13126. //char temp[100];
  13127. #if 0
  13128. struct hostent* server;
  13129. char *IPbuffer;
  13130. server = gethostbyname(location);
  13131. // To convert an Internet network
  13132. // address into ASCII string
  13133. IPbuffer = inet_ntoa(*((struct in_addr*)
  13134. server->h_addr_list[0]));
  13135. #endif
  13136. sprintf(FilePath,"/mnt/%s",filename);
  13137. if((access(FilePath,F_OK))!=-1)
  13138. {
  13139. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13140. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13141. system(rmFileCmd);
  13142. }
  13143. memset(ftpbuf, 0, sizeof(ftpbuf));
  13144. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13145. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13146. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13147. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13148. systemresult = system(ftpbuf);
  13149. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13150. if(systemresult != 0)
  13151. {
  13152. printf("wget error!\n");
  13153. return FALSE;
  13154. }
  13155. return TRUE;
  13156. }
  13157. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13158. {
  13159. char rmFileCmd[100]={0};
  13160. char FilePath[100]={0};
  13161. char ftpbuf[200];
  13162. char filenametemp[60]={0};
  13163. int systemresult;
  13164. //DEBUG_INFO("filename=%s\n",filename);
  13165. //DEBUG_INFO("url=%s\n",url);
  13166. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13167. if((access(FilePath,F_OK))!=-1)
  13168. {
  13169. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13170. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13171. system(rmFileCmd);
  13172. }
  13173. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13174. if(fp == NULL)
  13175. {
  13176. DEBUG_INFO("log is NULL\n");
  13177. return FALSE;
  13178. }
  13179. else
  13180. {
  13181. fprintf(fp, "%s\n", url);
  13182. sscanf(filename, "%*2[.]%s", filenametemp);
  13183. fprintf(fp, "%s\n", filenametemp);
  13184. fclose(fp);
  13185. }
  13186. memset(ftpbuf, 0, sizeof(ftpbuf));
  13187. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13188. systemresult = system(ftpbuf);
  13189. DEBUG_INFO("systemresult=%d\n",systemresult);
  13190. if(systemresult != 0)
  13191. {
  13192. DEBUG_INFO("http upload error!\n");
  13193. return FALSE;
  13194. }
  13195. return TRUE;
  13196. }
  13197. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13198. {
  13199. struct hostent* server;
  13200. char *IPbuffer;
  13201. char ftpbuf[200];
  13202. int systemresult;
  13203. // To retrieve host information
  13204. server = gethostbyname(location);
  13205. // To convert an Internet network
  13206. // address into ASCII string
  13207. IPbuffer = inet_ntoa(*((struct in_addr*)
  13208. server->h_addr_list[0]));
  13209. memset(ftpbuf, 0, sizeof(ftpbuf));
  13210. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13211. /* format : ftpput -u username -p passwd IP target source*/
  13212. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13213. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13214. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13215. systemresult = system(ftpbuf);
  13216. DEBUG_INFO("systemresult=%d\n",systemresult);
  13217. if(systemresult != 0)
  13218. {
  13219. DEBUG_INFO("ftpput error!\n");
  13220. return FALSE;
  13221. }
  13222. return TRUE;
  13223. }
  13224. int SettingChargingRecord(int target, int transactionId)
  13225. {
  13226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13227. {
  13228. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13229. {
  13230. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13231. {
  13232. addBuff(target, transactionId, 0);
  13233. return TRUE;
  13234. }
  13235. }
  13236. for (int index = 0; index < CCS_QUANTITY; index++)
  13237. {
  13238. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13239. {
  13240. addBuff(target, transactionId, 0);
  13241. return TRUE;
  13242. }
  13243. }
  13244. for (int index = 0; index < GB_QUANTITY; index++)
  13245. {
  13246. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13247. {
  13248. addBuff(target, transactionId, 0);
  13249. return TRUE;
  13250. }
  13251. }
  13252. }
  13253. else
  13254. {
  13255. for (int index = 0; index < AC_QUANTITY; index++)
  13256. {
  13257. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13258. {
  13259. addBuff(target, transactionId, 0);
  13260. return TRUE;
  13261. }
  13262. }
  13263. }
  13264. return FALSE;
  13265. }
  13266. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13267. {
  13268. int isSuccess = FALSE;
  13269. //char *query = NULL;
  13270. sqlite3_stmt *stmt;
  13271. int rc; // return code
  13272. char str[20];
  13273. sprintf(str,"%d",user_id);
  13274. 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 */
  13275. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13276. rc = sqlite3_step(stmt); /* 3 */
  13277. if (rc != SQLITE_DONE) {
  13278. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13279. goto out;
  13280. }
  13281. sqlite3_finalize(stmt);
  13282. // free(query);
  13283. out:
  13284. //----------------------
  13285. // close SQLite database
  13286. //----------------------
  13287. sqlite3_close(db);
  13288. printf("database closed.\n");
  13289. return isSuccess;
  13290. }
  13291. /**
  13292. * Place the contents of the specified file into a memory buffer
  13293. *
  13294. * @param[in] filename The path and name of the file to read
  13295. * @param[out] filebuffer A pointer to the contents in memory
  13296. * @return status 0 success, 1 on failure
  13297. */
  13298. int get_file_contents(const char* filename, char** outbuffer) {
  13299. FILE* file = NULL;
  13300. long filesize;
  13301. const int blocksize = 1;
  13302. size_t readsize;
  13303. char* filebuffer;
  13304. // Open the file
  13305. file = fopen(filename, "r");
  13306. if (NULL == file)
  13307. {
  13308. printf("'%s' not opened\n", filename);
  13309. exit(EXIT_FAILURE);
  13310. }
  13311. // Determine the file size
  13312. fseek(file, 0, SEEK_END);
  13313. filesize = ftell(file);
  13314. rewind (file);
  13315. // Allocate memory for the file contents
  13316. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13317. *outbuffer = filebuffer;
  13318. if (filebuffer == NULL)
  13319. {
  13320. fputs ("malloc out-of-memory", stderr);
  13321. exit(EXIT_FAILURE);
  13322. }
  13323. // Read in the file
  13324. readsize = fread(filebuffer, blocksize, filesize, file);
  13325. if (readsize != filesize)
  13326. {
  13327. fputs ("didn't read file completely",stderr);
  13328. exit(EXIT_FAILURE);
  13329. }
  13330. // Clean exit
  13331. fclose(file);
  13332. return EXIT_SUCCESS;
  13333. }
  13334. static int selectSqlCount = 0;
  13335. static int callback(void *data, int argc, char **argv, char **azColName){
  13336. int i;
  13337. //printf("%s: ", (const char*)data);
  13338. selectSqlCount = argc;
  13339. for(i = 0; i<argc; i++){
  13340. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13341. }
  13342. //printf("\n");
  13343. return 0;
  13344. }
  13345. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13346. //int i;
  13347. //printf("%s:\n", (const char*)data);
  13348. localversion = argv[5] ? atoi(argv[5]) : 0;
  13349. //printf("localversion=%d\n", localversion);
  13350. return 0;
  13351. }
  13352. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13353. //int i;
  13354. //printf("%s:\n", (const char*)data);
  13355. //idTag
  13356. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13357. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13358. //parentIdTag
  13359. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13360. //expir_date
  13361. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13362. //status
  13363. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13364. //version
  13365. idTagQuery.listVersionInt = atoi(argv[5]);
  13366. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13367. return 0;
  13368. }
  13369. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13370. #if 0
  13371. int i;
  13372. //printf("%s:\n", (const char*)data);
  13373. for(i=0; i<argc; i++){
  13374. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13375. }
  13376. //printf("");
  13377. #endif
  13378. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13379. // printf("localversion=%d\n", localversion);
  13380. return 0;
  13381. }
  13382. /** sqlite3_exec的回调。
  13383. *
  13384. * 向控制台打印查询的结果。
  13385. *
  13386. * @param in data 传递给回调函数的数据。
  13387. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13388. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13389. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13390. * @return 状态码。
  13391. */
  13392. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13393. {
  13394. for (int i = 0; i < n_columns; i++)
  13395. {
  13396. DEBUG_INFO("%s/t", col_values[i]);
  13397. }
  13398. DEBUG_INFO("/n");
  13399. return 0;
  13400. }
  13401. void OCPP_getListVerion()
  13402. {
  13403. int rc = 0;
  13404. // const char* data = "Callback function called";
  13405. char sql[100];
  13406. char zErrMsg[100];
  13407. memset(sql, 0, 100);
  13408. memset(zErrMsg, 0, 100);
  13409. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13410. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13411. /* Execute SQL statement */
  13412. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13413. DEBUG_INFO("rc=%d\n",rc);
  13414. if( rc != SQLITE_OK ){
  13415. DEBUG_INFO("SQL error: %s", zErrMsg);
  13416. //sqlite3_free(zErrMsg);
  13417. }
  13418. }
  13419. void OCPP_getIdTag(char idTag[])
  13420. {
  13421. int rc = 0;
  13422. // const char* data = "Callback function called";
  13423. char sql[100];
  13424. char zErrMsg[100];
  13425. memset(sql, 0, 100);
  13426. memset(zErrMsg, 0, 100);
  13427. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13428. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13429. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13430. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13431. /* Execute SQL statement */
  13432. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13433. if( rc != SQLITE_OK ){
  13434. DEBUG_INFO("SQL error: %s", zErrMsg);
  13435. //sqlite3_free(zErrMsg);
  13436. }
  13437. //return ver;
  13438. }
  13439. void OCPP_get_TableAuthlocalAllData(void)
  13440. {
  13441. int rc = 0;
  13442. // const char* data = "Callback function called";
  13443. char sql[100];
  13444. char zErrMsg[100];
  13445. memset(sql, 0, 100);
  13446. memset(zErrMsg, 0, 100);
  13447. sprintf(sql,"select * from ocpp_auth_local ");
  13448. /* Execute SQL statement */
  13449. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13450. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13451. if( rc != SQLITE_OK ){
  13452. DEBUG_INFO("SQL error: %s", zErrMsg);
  13453. //sqlite3_free(zErrMsg);
  13454. }
  13455. //return ver;
  13456. }
  13457. int OCPP_cleanLocalList()
  13458. {
  13459. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13460. char *errMsg = 0;
  13461. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13462. if (SQLITE_OK != rc)
  13463. {
  13464. DEBUG_INFO("%s\n",errMsg);
  13465. return FALSE;
  13466. }
  13467. else
  13468. {
  13469. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13470. }
  13471. return TRUE;
  13472. }
  13473. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13474. {
  13475. int isSuccess = FALSE;
  13476. int ret = 0;
  13477. //const char* data = "Callback function called";
  13478. char sql[300];
  13479. char zErrMsg[200];
  13480. memset(sql, 0, 300);
  13481. memset(zErrMsg, 0, 200);
  13482. 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);
  13483. //* Execute SQL statement */
  13484. //zErrMsg = 0;
  13485. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13486. if( ret != SQLITE_OK ){
  13487. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13488. // free(zErrMsg);
  13489. // free(sql);
  13490. return isSuccess;
  13491. }
  13492. memset(sql, 0, 300);
  13493. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13494. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13495. if( ret != SQLITE_OK ){
  13496. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13497. // free(zErrMsg);
  13498. // free(sql);
  13499. return isSuccess;
  13500. }
  13501. // DEBUG_INFO("successfully Insert records created\n");
  13502. isSuccess = TRUE;
  13503. return isSuccess;
  13504. }
  13505. void OCPP_deleteIdTag(char idTag[])
  13506. {
  13507. //int ver = 0;
  13508. //int isSuccess = FALSE;
  13509. int rc = 0;
  13510. char sql[100];
  13511. char zErrMsg[100];
  13512. memset(sql, 0, 100);
  13513. memset(zErrMsg, 0, 100);
  13514. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13515. //* Execute SQL statement */
  13516. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13517. if( rc != SQLITE_OK ){
  13518. DEBUG_INFO("SQL error: %s", zErrMsg);
  13519. //sqlite3_free(zErrMsg);
  13520. }
  13521. }
  13522. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13523. {
  13524. int isSuccess = FALSE;
  13525. int ret = 0;
  13526. const char* data = "Callback function called";
  13527. char sql[200];
  13528. char zErrMsg[100];
  13529. memset(sql, 0, 200);
  13530. memset(zErrMsg, 0, 100);
  13531. //* selectFromTable */
  13532. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13533. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13534. //* Execute SQL statement */
  13535. selectSqlCount = 0;
  13536. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13537. if( ret != SQLITE_OK ){
  13538. printf("Error SQL: %s\n", zErrMsg);
  13539. }
  13540. printf("successfully select operation done\n");
  13541. memset(sql, 0, 200);
  13542. memset(zErrMsg, 0, 100);
  13543. if(selectSqlCount == 0)
  13544. {
  13545. //Insert
  13546. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13547. 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);
  13548. DEBUG_INFO("sql:%s\n", sql);
  13549. //* Execute SQL statement */
  13550. //zErrMsg = 0;
  13551. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13552. if( ret != SQLITE_OK ){
  13553. printf("SQL error: %s\n", zErrMsg);
  13554. return isSuccess;
  13555. }
  13556. DEBUG_INFO("successfully Insert records created\n");
  13557. isSuccess = TRUE;
  13558. }
  13559. else
  13560. {
  13561. //Update
  13562. //* Create merged SQL statement */
  13563. 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);
  13564. /* Execute SQL statement */
  13565. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13566. if( ret != SQLITE_OK ){
  13567. printf("SQL error: %s\n", zErrMsg);
  13568. //sqlite3_free(zErrMsg);
  13569. //sqlite3_free(sql);
  13570. return isSuccess;
  13571. }
  13572. DEBUG_INFO("Successfully operation done \n");
  13573. isSuccess = TRUE;
  13574. }
  13575. return isSuccess;
  13576. }
  13577. int GetOcppServerURL()
  13578. {
  13579. int result = FALSE;
  13580. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13581. memset(OcppHost, 0, sizeof(OcppHost));
  13582. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13583. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13584. {
  13585. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13586. #if 1
  13587. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13588. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13589. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13590. #endif
  13591. #if 0
  13592. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13593. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13594. OcppProtocol, OcppHost, OcppTempPath);
  13595. OcppPort = 443;
  13596. #endif
  13597. result = TRUE;
  13598. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13599. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13600. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13601. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13602. goto End;
  13603. }
  13604. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13605. {
  13606. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13607. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13608. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13609. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13610. result = TRUE;
  13611. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13612. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13613. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13614. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13615. goto End;
  13616. }
  13617. else
  13618. {
  13619. strcpy(OcppHost,"");
  13620. }
  13621. End:
  13622. return result;
  13623. }
  13624. int GetOcppPath()
  13625. {
  13626. int result = FALSE;
  13627. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13628. {
  13629. if(OcppTempPath == NULL)
  13630. {
  13631. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13632. }
  13633. else
  13634. {
  13635. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13636. }
  13637. result = TRUE;
  13638. goto End;
  13639. }
  13640. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13641. {
  13642. if(OcppTempPath == NULL)
  13643. {
  13644. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13645. }
  13646. else
  13647. {
  13648. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13649. }
  13650. result = TRUE;
  13651. goto End;
  13652. }
  13653. else
  13654. {
  13655. strcpy(OcppPath,"");
  13656. }
  13657. End:
  13658. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13659. return result;
  13660. }
  13661. int GetOcppPort()
  13662. {
  13663. return OcppPort;
  13664. }
  13665. int GetOcppConnStatus(void)
  13666. {
  13667. return ShmOCPP16Data->OcppConnStatus;
  13668. }
  13669. void SetOcppConnStatus(uint8_t status)
  13670. {
  13671. ShmOCPP16Data->OcppConnStatus = status;
  13672. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13673. }
  13674. int GetHeartBeatWithNOResponse(void)
  13675. {
  13676. return HeartBeatWithNOResponse;
  13677. }
  13678. void SetHeartBeatWithNOResponse(void)
  13679. {
  13680. HeartBeatWithNOResponse = 0;
  13681. }
  13682. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13683. /*
  13684. src 源字串的首地址(buf的地址)
  13685. separator 指定的分割字元
  13686. dest 接收子字串的陣列
  13687. num 分割後子字串的個數
  13688. */
  13689. char *pNext;
  13690. int count = 0;
  13691. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13692. return;
  13693. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13694. return;
  13695. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13696. while(pNext != NULL) {
  13697. *dest++ = pNext;
  13698. ++count;
  13699. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13700. }
  13701. *num = count;
  13702. }
  13703. int GetTransactionId(int gunindex, unsigned char idTag[])
  13704. {
  13705. char ch;
  13706. FILE *fptr1;
  13707. int temptransactionId;
  13708. char str[100]={0};
  13709. temptransactionId = 0;
  13710. /*------ Read the file ----------------*/
  13711. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13712. if (!fptr1)
  13713. {
  13714. //printf(" File not found or unable to open the input file!!\n");
  13715. return temptransactionId;
  13716. }
  13717. ch=fgetc(fptr1);
  13718. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13719. rewind(fptr1);
  13720. if(ch!=EOF)
  13721. {
  13722. // printf("%c",ch);
  13723. while (fgets(str, 100, fptr1) != NULL)
  13724. {
  13725. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13726. if(str[0]=='\0')
  13727. {
  13728. break;
  13729. }
  13730. char *revbuf[8] = {0}; //存放分割後的子字串
  13731. int num = 0;//分割後子字串的個數
  13732. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13733. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13734. {
  13735. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13736. {
  13737. temptransactionId = atoi(revbuf[2]);
  13738. break;
  13739. }
  13740. }
  13741. }
  13742. }
  13743. fclose(fptr1);
  13744. /*------- End of reading ---------------*/
  13745. return temptransactionId;
  13746. }
  13747. void SetTransactionIdZero(int transactionId)
  13748. {
  13749. //TransactionId[gunindex] = 0;
  13750. char ch;
  13751. FILE *fptr1, *fptr2;
  13752. int temptransactionId = 0;
  13753. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13754. printf("\n Delete a specific line from a file :\n");
  13755. printf("-----------------------------------------\n");
  13756. //scanf("%s",fname);
  13757. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13758. if (!fptr1)
  13759. {
  13760. //printf(" File not found or unable to open the input file!!\n");
  13761. return ;
  13762. }
  13763. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13764. if (!fptr2)
  13765. {
  13766. printf("Unable to open a temporary file to write!!\n");
  13767. fclose(fptr1);
  13768. return ;
  13769. }
  13770. ch=fgetc(fptr1);
  13771. //printf(" Now the content of the file %s is : \n",fname);
  13772. rewind(fptr1);
  13773. if(ch!=EOF)
  13774. {
  13775. // copy all contents to the temporary file except the specific line
  13776. while (fgets(str, 100, fptr1) != NULL)
  13777. {
  13778. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13779. if(str[0]=='\0')
  13780. {
  13781. break;
  13782. }
  13783. char *revbuf[8] = {0}; //存放分割後的子字串
  13784. int num = 0;//分割後子字串的個數
  13785. strcpy(strtemp, str);
  13786. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13787. if(revbuf[2][0] != '\0')
  13788. {
  13789. temptransactionId = atoi(revbuf[2]);
  13790. if(transactionId != temptransactionId)
  13791. {
  13792. fprintf(fptr2, "%s\n", strtemp);
  13793. }
  13794. }
  13795. }
  13796. }
  13797. fclose(fptr1);
  13798. fclose(fptr2);
  13799. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13800. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13801. printf("\n Delete a specific line from a file End\n");
  13802. printf("-----------------------------------------\n");
  13803. /*------ Read the file ----------------*/
  13804. }
  13805. int InternetDisconnect(void)
  13806. {
  13807. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13808. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13809. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13810. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13811. }
  13812. void GetChargingProfileRequest(int gunindex)
  13813. {
  13814. mtrace();
  13815. //int connectorIdInt, durationInt;
  13816. //char chargingRateUnitStr[4]={0};
  13817. int tempdurationInt = 0;
  13818. int tempchargingProfileId = 0;
  13819. int tempstackLevel = 0;
  13820. int temptransactionId = 0;
  13821. float tempminChargingRateFloat = 0.0;
  13822. char tempchargingProfilePurposeStr[24]={0};
  13823. char tempchargingProfileKindStr[12]={0};
  13824. char temprecurrencyKindStr[8]={0};
  13825. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13826. char tempvalidToStr[28]={0};
  13827. int tempStartPeriodInt = 0;
  13828. float tempLimitInt = 0.0;//0.1;
  13829. int tempNumberPhasesInt=0;
  13830. char fname[200];
  13831. //char comfirmstr[20];
  13832. float MinChargingRate =0.0;
  13833. double diff_t;
  13834. struct tm tp;
  13835. FILE *fptr1;//, *fptr2;
  13836. int c = 0;
  13837. char * pch;
  13838. char *loc;
  13839. char sstr[200]={ 0 };
  13840. int n_chargingProfile = 0;
  13841. int n_SchedulePeriods = 0;
  13842. char SchedulePeriodList[10][200]={0};
  13843. char sLineWord[1600]={0};
  13844. char word[1000]={0};
  13845. int confirmPeriods = 0;
  13846. struct StructProfile ChargePointMaxProfile;
  13847. struct StructProfile TxDefaultProfile;
  13848. struct StructProfile TxProfile;
  13849. struct StructProfile TxDefaultProfiletemp[2]={0};
  13850. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13851. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13852. struct StructChargingProfile TxProfile_TEMP={0};
  13853. int TxDefaultProfileFileIsNull=FALSE;
  13854. int ChargePointMaxProfileIsNull=FALSE;
  13855. int TxProfileIsNull=FALSE;
  13856. // int CompositeSceduleIndex = 0;
  13857. char ChargePointMaxProfileScheduleStr[30]={0};
  13858. char TxDefaultProfileScheduleStr[30]={0};
  13859. char TxProfileScheduleStr[30]={0};
  13860. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13861. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13862. memset(&TxProfile,0,sizeof(struct StructProfile));
  13863. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13864. DEBUG_INFO("GetChargingProfileRequest\n");
  13865. //*****************************ChargePointMaxProfile******************************************/
  13866. strcpy(fname, ChargePointMaxProfile_JSON);
  13867. ChargePointMaxProfileIsNull=TRUE;
  13868. DEBUG_INFO("test 1\n");
  13869. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13870. {
  13871. fptr1 = fopen(fname, "r");
  13872. int c;
  13873. c = fgetc(fptr1);
  13874. //DEBUG_INFO("c:%d\n",c);
  13875. rewind(fptr1);
  13876. if(c == EOF)
  13877. {
  13878. DEBUG_INFO("\n End of file reached.");
  13879. ChargePointMaxProfileIsNull=TRUE;
  13880. fclose(fptr1);
  13881. }
  13882. else
  13883. {
  13884. DEBUG_INFO("test 2\n");
  13885. ChargePointMaxProfileIsNull=FALSE;
  13886. while(fscanf(fptr1, "%s", word) != EOF)
  13887. {
  13888. if(strcmp(word, "chargingProfileId") == 0)
  13889. {
  13890. n_chargingProfile = n_chargingProfile + 1;
  13891. }
  13892. }
  13893. rewind(fptr1);
  13894. //search Charging Profile Element
  13895. int i = 0;
  13896. int j = 0;
  13897. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13898. //***********chargingProfileId**************/
  13899. c = 0;
  13900. loc = strstr(sLineWord, "chargingProfileId");
  13901. //DEBUG_INFO("loc=%s\n",loc);
  13902. memset(sstr ,0, sizeof(sstr) );
  13903. if(loc != NULL)
  13904. {
  13905. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13906. {
  13907. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13908. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13909. c++;
  13910. }
  13911. sstr[c] = '\0';
  13912. tempchargingProfileId = atoi(sstr);
  13913. }
  13914. else
  13915. {
  13916. tempchargingProfileId = 0;
  13917. }
  13918. //***********stackLevel**************/
  13919. c = 0;
  13920. loc = strstr(sLineWord, "stackLevel");
  13921. //DEBUG_INFO("loc=%s\n",loc);
  13922. memset(sstr ,0, sizeof(sstr) );
  13923. if(loc != NULL)
  13924. {
  13925. while (loc[2+strlen("stackLevel")+c] != '\"')
  13926. {
  13927. sstr[c] = loc[2+strlen("stackLevel")+c];
  13928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13929. c++;
  13930. }
  13931. sstr[c] = '\0';
  13932. tempstackLevel = atoi(sstr);
  13933. }
  13934. else
  13935. {
  13936. tempstackLevel = 0;
  13937. }
  13938. //***********chargingProfilePurpose **************/
  13939. c = 0;
  13940. loc = strstr(sLineWord, "chargingProfilePurpose");
  13941. //DEBUG_INFO("loc=%s\n",loc);
  13942. memset(sstr ,0, sizeof(sstr) );
  13943. if(loc != NULL)
  13944. {
  13945. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13946. {
  13947. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13949. c++;
  13950. }
  13951. sstr[c] = '\0';
  13952. strcpy(tempchargingProfilePurposeStr,sstr);
  13953. }
  13954. else
  13955. {
  13956. strcpy(tempchargingProfilePurposeStr,"");
  13957. }
  13958. //***********chargingProfileKind **************/
  13959. c = 0;
  13960. loc = strstr(sLineWord, "chargingProfileKind");
  13961. //DEBUG_INFO("loc=%s\n",loc);
  13962. memset(sstr ,0, sizeof(sstr) );
  13963. if(loc != NULL)
  13964. {
  13965. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13966. {
  13967. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13969. c++;
  13970. }
  13971. sstr[c] = '\0';
  13972. strcpy(tempchargingProfileKindStr,sstr);
  13973. }
  13974. else
  13975. {
  13976. strcpy(tempchargingProfileKindStr,"");
  13977. }
  13978. //***********recurrencyKind **************/
  13979. c = 0;
  13980. loc = strstr(sLineWord, "recurrencyKind");
  13981. //DEBUG_INFO("loc=%s\n",loc);
  13982. memset(sstr ,0, sizeof(sstr) );
  13983. if(loc != NULL)
  13984. {
  13985. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13986. {
  13987. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13988. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13989. c++;
  13990. }
  13991. sstr[c] = '\0';
  13992. strcpy(temprecurrencyKindStr,sstr);
  13993. }
  13994. else
  13995. {
  13996. strcpy(temprecurrencyKindStr,"");
  13997. }
  13998. //***********validFrom**************/
  13999. c = 0;
  14000. loc = strstr(sLineWord, "validFrom");
  14001. //DEBUG_INFO("loc=%s\n",loc);
  14002. memset(sstr ,0, sizeof(sstr) );
  14003. if(loc != NULL)
  14004. {
  14005. while (loc[3+strlen("validFrom")+c] != '\"')
  14006. {
  14007. sstr[c] = loc[3+strlen("validFrom")+c];
  14008. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14009. c++;
  14010. }
  14011. sstr[c] = '\0';
  14012. strcpy(tempvalidFromStr,sstr);
  14013. }
  14014. else
  14015. {
  14016. strcpy(tempvalidFromStr,"");
  14017. }
  14018. //***********validTo **************/
  14019. c = 0;
  14020. loc = strstr(sLineWord, "validTo");
  14021. //DEBUG_INFO("loc=%s\n",loc);
  14022. memset(sstr ,0, sizeof(sstr) );
  14023. if(loc != NULL)
  14024. {
  14025. while (loc[3+strlen("validTo")+c] != '\"')
  14026. {
  14027. sstr[c] = loc[3+strlen("validTo")+c];
  14028. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14029. c++;
  14030. }
  14031. sstr[c] = '\0';
  14032. strcpy(tempvalidToStr,sstr);
  14033. }
  14034. else
  14035. {
  14036. strcpy(tempvalidToStr,"");
  14037. }
  14038. //***********validFrom**************/
  14039. c = 0;
  14040. loc = strstr(sLineWord, "validFrom");
  14041. if(loc != NULL)
  14042. {
  14043. memset(sstr ,0, sizeof(sstr) );
  14044. while (loc[3+strlen("validFrom")+c] != '\"')
  14045. {
  14046. sstr[c] = loc[3+strlen("validFrom")+c];
  14047. c++;
  14048. }
  14049. sstr[c] = '\0';
  14050. strcpy(tempvalidFromStr,sstr);
  14051. }
  14052. else
  14053. {
  14054. strcpy(tempvalidFromStr,"");
  14055. }
  14056. //***********validTo **************/
  14057. c = 0;
  14058. loc = strstr(sLineWord, "validTo");
  14059. if(loc != NULL)
  14060. {
  14061. memset(sstr ,0, sizeof(sstr) );
  14062. while (loc[3+strlen("validTo")+c] != '\"')
  14063. {
  14064. sstr[c] = loc[3+strlen("validTo")+c];
  14065. c++;
  14066. }
  14067. sstr[c] = '\0';
  14068. strcpy(tempvalidToStr,sstr);
  14069. }
  14070. else
  14071. {
  14072. strcpy(tempvalidToStr,"");
  14073. }
  14074. //***********duration**************/
  14075. c = 0;
  14076. loc = strstr(sLineWord, "duration");
  14077. if(loc != NULL)
  14078. {
  14079. memset(sstr ,0, sizeof(sstr) );
  14080. while (loc[2+strlen("duration")+c] != ',')
  14081. {
  14082. sstr[c] = loc[2+strlen("duration")+c];
  14083. c++;
  14084. }
  14085. sstr[c] = '\0';
  14086. tempdurationInt = atoi(sstr);
  14087. }
  14088. else
  14089. {
  14090. tempdurationInt = 0;
  14091. }
  14092. //**********startSchedule**********/
  14093. c = 0;
  14094. loc = strstr(sLineWord, "startSchedule");
  14095. if(loc != NULL)
  14096. {
  14097. memset(sstr ,0, sizeof(sstr) );
  14098. while (loc[3+strlen("startSchedule")+c] != '\"')
  14099. {
  14100. sstr[c] = loc[3+strlen("startSchedule")+c];
  14101. c++;
  14102. }
  14103. sstr[c] = '\0';
  14104. strcpy(tempstartScheduleStr, sstr);
  14105. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14106. }
  14107. else
  14108. {
  14109. strcpy(tempstartScheduleStr, "");
  14110. strcpy(ChargePointMaxProfileScheduleStr, "");
  14111. }
  14112. //**********chargingRateUnit**********/
  14113. c = 0;
  14114. loc = strstr(sLineWord, "chargingRateUnit");
  14115. memset(sstr ,0, sizeof(sstr) );
  14116. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14117. {
  14118. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14119. c++;
  14120. }
  14121. sstr[c] = '\0';
  14122. strcpy(tempchargingRateUnitStr, sstr);
  14123. //**********minChargingRate*******/
  14124. c = 0;
  14125. loc = strstr(sLineWord, "minChargingRate");
  14126. if(loc != NULL)
  14127. {
  14128. memset(sstr ,0, sizeof(sstr) );
  14129. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14130. {
  14131. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14132. c++;
  14133. }
  14134. sstr[c] = '\0';
  14135. tempminChargingRateFloat = atof(sstr);
  14136. }
  14137. else
  14138. {
  14139. tempminChargingRateFloat = 0.0;
  14140. }
  14141. //
  14142. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14143. tp.tm_isdst = -1;
  14144. time_t utc = mktime(&tp);
  14145. time_t t = time(NULL);
  14146. diff_t = difftime(t, utc);
  14147. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14148. //parsing strings to words
  14149. i = 0;
  14150. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14151. loc = loc+3+strlen("chargingSchedulePeriod");
  14152. pch = strtok(loc ,"{");
  14153. while (pch != NULL)
  14154. {
  14155. strcpy(SchedulePeriodList[i], pch);
  14156. pch = strtok (NULL, "{");
  14157. i = i + 1;
  14158. }
  14159. n_SchedulePeriods = i;
  14160. for(int i=0;i<n_SchedulePeriods;i++)
  14161. {
  14162. //*************startPeriod****************/
  14163. c = 0;
  14164. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14165. memset(sstr ,0, sizeof(sstr) );
  14166. while (loc[strlen("startPeriod")+2+c] != ',')
  14167. {
  14168. sstr[c] = loc[strlen("startPeriod")+2+c];
  14169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14170. c++;
  14171. }
  14172. sstr[c] = '\0';
  14173. tempStartPeriodInt = atoi(sstr);
  14174. //*************limit****************/
  14175. c = 0;
  14176. loc = strstr(SchedulePeriodList[i], "limit");
  14177. memset(sstr ,0, sizeof(sstr) );
  14178. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14179. {
  14180. sstr[c] = loc[strlen("limit")+2+c];
  14181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14182. c++;
  14183. }
  14184. sstr[c] = '\0';
  14185. tempLimitInt = atof(sstr);
  14186. //*************numberPhases****************/
  14187. c = 0;
  14188. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14189. memset(sstr ,0, sizeof(sstr) );
  14190. if(loc != NULL)
  14191. {
  14192. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14193. {
  14194. sstr[c] = loc[strlen("numberPhases")+2+c];
  14195. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14196. c++;
  14197. }
  14198. sstr[c] = '\0';
  14199. tempNumberPhasesInt = atoi(sstr);
  14200. }
  14201. else
  14202. {
  14203. tempNumberPhasesInt = 0;
  14204. }
  14205. if(j == 0)
  14206. {
  14207. ChargePointMaxProfile.Duration = tempdurationInt;
  14208. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14209. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14210. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14211. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14212. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14213. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14214. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14215. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14216. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14217. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14218. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14219. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14220. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14221. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14222. }
  14223. }
  14224. if(MinChargingRate < tempminChargingRateFloat)
  14225. {
  14226. MinChargingRate = tempminChargingRateFloat;
  14227. }
  14228. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14229. if(confirmPeriods < n_SchedulePeriods)
  14230. {
  14231. confirmPeriods = n_SchedulePeriods;
  14232. }
  14233. j = j + 1;
  14234. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14235. fclose(fptr1);
  14236. }// end else
  14237. }// the end of access file ChargePointMaxProfile
  14238. DEBUG_INFO("test 3\n");
  14239. //****************************TxDefaultProfile************************************************/
  14240. memset(fname, 0, sizeof fname);
  14241. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14242. TxDefaultProfileFileIsNull=TRUE;
  14243. if((access(fname,F_OK))!=-1)
  14244. {
  14245. fptr1 = fopen(fname, "r");
  14246. c = 0;
  14247. c = fgetc(fptr1);
  14248. //DEBUG_INFO("c:%d\n",c);
  14249. rewind(fptr1);
  14250. if(c == EOF)
  14251. {
  14252. DEBUG_INFO("\n End of file reached.");
  14253. TxDefaultProfileFileIsNull=TRUE;
  14254. fclose(fptr1);
  14255. }
  14256. else
  14257. {
  14258. TxDefaultProfileFileIsNull=FALSE;
  14259. while(fscanf(fptr1, "%s", word) != EOF)
  14260. {
  14261. if(strcmp(word, "chargingProfileId") == 0)
  14262. {
  14263. n_chargingProfile = n_chargingProfile + 1;
  14264. }
  14265. }
  14266. rewind(fptr1);
  14267. //search Charging Profile Element
  14268. int i = 0;
  14269. int j = 0;
  14270. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14271. {
  14272. #if 0
  14273. //***********connectorId****************/
  14274. c = 0;
  14275. loc = strstr(sLineWord, "connectorId");
  14276. memset(sstr ,0, sizeof(sstr) );
  14277. while (loc[strlen("connectorId")+2+c] != ',')
  14278. {
  14279. sstr[c] = loc[strlen("connectorId")+2+c];
  14280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14281. c++;
  14282. }
  14283. sstr[c] = '\0';
  14284. tempconnectorIdInt = atoi(sstr);
  14285. #endif
  14286. //***********chargingProfileId**************/
  14287. c = 0;
  14288. loc = strstr(sLineWord, "chargingProfileId");
  14289. //DEBUG_INFO("loc=%s\n",loc);
  14290. memset(sstr ,0, sizeof(sstr) );
  14291. if(loc != NULL)
  14292. {
  14293. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14294. {
  14295. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14296. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14297. c++;
  14298. }
  14299. sstr[c] = '\0';
  14300. tempchargingProfileId = atoi(sstr);
  14301. }
  14302. else
  14303. {
  14304. tempchargingProfileId = 0;
  14305. }
  14306. //***********stackLevel**************/
  14307. c = 0;
  14308. loc = strstr(sLineWord, "stackLevel");
  14309. //DEBUG_INFO("loc=%s\n",loc);
  14310. memset(sstr ,0, sizeof(sstr) );
  14311. if(loc != NULL)
  14312. {
  14313. while (loc[2+strlen("stackLevel")+c] != '\"')
  14314. {
  14315. sstr[c] = loc[2+strlen("stackLevel")+c];
  14316. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14317. c++;
  14318. }
  14319. sstr[c] = '\0';
  14320. tempstackLevel = atoi(sstr);
  14321. }
  14322. else
  14323. {
  14324. tempstackLevel = 0;
  14325. }
  14326. //***********chargingProfilePurpose **************/
  14327. c = 0;
  14328. loc = strstr(sLineWord, "chargingProfilePurpose");
  14329. //DEBUG_INFO("loc=%s\n",loc);
  14330. memset(sstr ,0, sizeof(sstr) );
  14331. if(loc != NULL)
  14332. {
  14333. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14334. {
  14335. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14336. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14337. c++;
  14338. }
  14339. sstr[c] = '\0';
  14340. strcpy(tempchargingProfilePurposeStr,sstr);
  14341. }
  14342. else
  14343. {
  14344. strcpy(tempchargingProfilePurposeStr,"");
  14345. }
  14346. //***********chargingProfileKind **************/
  14347. c = 0;
  14348. loc = strstr(sLineWord, "chargingProfileKind");
  14349. //DEBUG_INFO("loc=%s\n",loc);
  14350. memset(sstr ,0, sizeof(sstr) );
  14351. if(loc != NULL)
  14352. {
  14353. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14354. {
  14355. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14356. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14357. c++;
  14358. }
  14359. sstr[c] = '\0';
  14360. strcpy(tempchargingProfileKindStr,sstr);
  14361. }
  14362. else
  14363. {
  14364. strcpy(tempchargingProfileKindStr,"");
  14365. }
  14366. //***********recurrencyKind **************/
  14367. c = 0;
  14368. loc = strstr(sLineWord, "recurrencyKind");
  14369. //DEBUG_INFO("loc=%s\n",loc);
  14370. memset(sstr ,0, sizeof(sstr) );
  14371. if(loc != NULL)
  14372. {
  14373. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14374. {
  14375. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14376. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14377. c++;
  14378. }
  14379. sstr[c] = '\0';
  14380. strcpy(temprecurrencyKindStr,sstr);
  14381. }
  14382. else
  14383. {
  14384. strcpy(temprecurrencyKindStr,"");
  14385. }
  14386. //***********validFrom**************/
  14387. c = 0;
  14388. loc = strstr(sLineWord, "validFrom");
  14389. if(loc != NULL)
  14390. {
  14391. memset(sstr ,0, sizeof(sstr) );
  14392. while (loc[3+strlen("validFrom")+c] != '\"')
  14393. {
  14394. sstr[c] = loc[3+strlen("validFrom")+c];
  14395. c++;
  14396. }
  14397. sstr[c] = '\0';
  14398. strcpy(tempvalidFromStr,sstr);
  14399. }
  14400. else
  14401. {
  14402. strcpy(tempvalidFromStr,"");
  14403. }
  14404. //***********validTo **************/
  14405. c = 0;
  14406. loc = strstr(sLineWord, "validTo");
  14407. if(loc != NULL)
  14408. {
  14409. memset(sstr ,0, sizeof(sstr) );
  14410. while (loc[3+strlen("validTo")+c] != '\"')
  14411. {
  14412. sstr[c] = loc[3+strlen("validTo")+c];
  14413. c++;
  14414. }
  14415. sstr[c] = '\0';
  14416. strcpy(tempvalidToStr,sstr);
  14417. }
  14418. else
  14419. {
  14420. strcpy(tempvalidToStr,"");
  14421. }
  14422. //***********duration**************/
  14423. c = 0;
  14424. loc = strstr(sLineWord, "duration");
  14425. if(loc != NULL)
  14426. {
  14427. memset(sstr ,0, sizeof(sstr) );
  14428. while (loc[2+strlen("duration")+c] != ',')
  14429. {
  14430. sstr[c] = loc[2+strlen("duration")+c];
  14431. c++;
  14432. }
  14433. sstr[c] = '\0';
  14434. tempdurationInt = atoi(sstr);
  14435. }
  14436. else
  14437. {
  14438. tempdurationInt = 0;
  14439. }
  14440. //**********startSchedule**********/
  14441. c = 0;
  14442. loc = strstr(sLineWord, "startSchedule");
  14443. if(loc != NULL)
  14444. {
  14445. memset(sstr ,0, sizeof(sstr) );
  14446. while (loc[3+strlen("startSchedule")+c] != '\"')
  14447. {
  14448. sstr[c] = loc[3+strlen("startSchedule")+c];
  14449. c++;
  14450. }
  14451. sstr[c] = '\0';
  14452. strcpy(tempstartScheduleStr, sstr);
  14453. strcpy(TxDefaultProfileScheduleStr, sstr);
  14454. }
  14455. else
  14456. {
  14457. strcpy(tempstartScheduleStr, "");
  14458. strcpy(TxDefaultProfileScheduleStr, "");
  14459. }
  14460. //**********chargingRateUnit**********/
  14461. c = 0;
  14462. loc = strstr(sLineWord, "chargingRateUnit");
  14463. memset(sstr ,0, sizeof(sstr) );
  14464. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14465. {
  14466. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14467. c++;
  14468. }
  14469. sstr[c] = '\0';
  14470. strcpy(tempchargingRateUnitStr, sstr);
  14471. //**********minChargingRate*******/
  14472. c = 0;
  14473. loc = strstr(sLineWord, "minChargingRate");
  14474. if(loc != NULL)
  14475. {
  14476. memset(sstr ,0, sizeof(sstr) );
  14477. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14478. {
  14479. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14480. c++;
  14481. }
  14482. sstr[c] = '\0';
  14483. tempminChargingRateFloat = atof(sstr);
  14484. }
  14485. else
  14486. {
  14487. tempminChargingRateFloat = 0.0;
  14488. }
  14489. //
  14490. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14491. tp.tm_isdst = -1;
  14492. time_t utc = mktime(&tp);
  14493. time_t t = time(NULL);
  14494. diff_t = difftime(t, utc);
  14495. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14496. //parsing strings to words
  14497. i = 0;
  14498. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14499. loc = loc+3+strlen("chargingSchedulePeriod");
  14500. pch = strtok(loc ,"{");
  14501. while (pch != NULL)
  14502. {
  14503. strcpy(SchedulePeriodList[i], pch);
  14504. pch = strtok (NULL, "{");
  14505. i = i + 1;
  14506. }
  14507. n_SchedulePeriods = i;
  14508. for(int i=0;i<n_SchedulePeriods;i++)
  14509. {
  14510. //*************startPeriod****************/
  14511. c = 0;
  14512. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14513. memset(sstr ,0, sizeof(sstr) );
  14514. while (loc[strlen("startPeriod")+2+c] != ',')
  14515. {
  14516. sstr[c] = loc[strlen("startPeriod")+2+c];
  14517. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14518. c++;
  14519. }
  14520. sstr[c] = '\0';
  14521. tempStartPeriodInt = atoi(sstr);
  14522. //*************limit****************/
  14523. c = 0;
  14524. loc = strstr(SchedulePeriodList[i], "limit");
  14525. memset(sstr ,0, sizeof(sstr) );
  14526. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14527. {
  14528. sstr[c] = loc[strlen("limit")+2+c];
  14529. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14530. c++;
  14531. }
  14532. sstr[c] = '\0';
  14533. tempLimitInt = atof(sstr);
  14534. //*************numberPhases****************/
  14535. c = 0;
  14536. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14537. memset(sstr ,0, sizeof(sstr) );
  14538. if(loc != NULL)
  14539. {
  14540. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14541. {
  14542. sstr[c] = loc[strlen("numberPhases")+2+c];
  14543. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14544. c++;
  14545. }
  14546. sstr[c] = '\0';
  14547. tempNumberPhasesInt = atoi(sstr);
  14548. }
  14549. else
  14550. {
  14551. tempNumberPhasesInt = 0;
  14552. }
  14553. if(j == 0)
  14554. {
  14555. TxDefaultProfile.Duration = tempdurationInt;
  14556. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14557. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14558. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14559. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14560. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14561. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14562. TxDefaultProfile_TEMP.TransactionId = 0;
  14563. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14564. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14565. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14566. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14567. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14568. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14569. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14570. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14571. }
  14572. else
  14573. {
  14574. //other stack level charging Profile
  14575. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14576. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14577. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14578. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14579. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14580. }
  14581. }
  14582. if(MinChargingRate < tempminChargingRateFloat)
  14583. {
  14584. MinChargingRate = tempminChargingRateFloat;
  14585. }
  14586. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14587. if(confirmPeriods < n_SchedulePeriods)
  14588. confirmPeriods = n_SchedulePeriods;
  14589. j = j + 1;
  14590. }
  14591. fclose(fptr1);
  14592. //Stacking Charging Profiles
  14593. for(int l=0; l <(j-1) ;l++)
  14594. {
  14595. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14596. {
  14597. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14598. {
  14599. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14600. {
  14601. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14602. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14603. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14604. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14605. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14606. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14607. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14608. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14609. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14610. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14611. }
  14612. else
  14613. {
  14614. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14615. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14616. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14617. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14618. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14619. }
  14620. }
  14621. }
  14622. }//end of Stacking Charging Profiles
  14623. }// end else
  14624. }// the end of ACCESS TxDefaultProfile
  14625. //****************************TxProfile************************************************/
  14626. memset(fname, 0, sizeof fname);
  14627. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14628. TxProfileIsNull=TRUE;
  14629. if((access(fname,F_OK))!=-1)
  14630. {
  14631. fptr1 = fopen(fname, "r");
  14632. c = 0;
  14633. c = fgetc(fptr1);
  14634. //DEBUG_INFO("c:%d\n",c);
  14635. rewind(fptr1);
  14636. if(c == EOF)
  14637. {
  14638. DEBUG_INFO("\n End of file reached.");
  14639. TxProfileIsNull=TRUE;
  14640. fclose(fptr1);
  14641. }
  14642. else
  14643. {
  14644. TxProfileIsNull=FALSE;
  14645. while(fscanf(fptr1, "%s", word) != EOF)
  14646. {
  14647. if(strcmp(word, "chargingProfileId") == 0)
  14648. {
  14649. n_chargingProfile = n_chargingProfile + 1;
  14650. }
  14651. }
  14652. rewind(fptr1);
  14653. //search Charging Profile Element
  14654. int i= 0;
  14655. int j= 0;
  14656. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14657. #if 0
  14658. /***********connectorId****************/
  14659. c = 0;
  14660. loc = strstr(sLineWord, "connectorId");
  14661. memset(sstr ,0, sizeof(sstr) );
  14662. while (loc[strlen("connectorId")+2+c] != ',')
  14663. {
  14664. sstr[c] = loc[strlen("connectorId")+2+c];
  14665. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14666. c++;
  14667. }
  14668. sstr[c] = '\0';
  14669. tempconnectorIdInt = atoi(sstr);
  14670. #endif
  14671. //***********chargingProfileId**************/
  14672. c = 0;
  14673. loc = strstr(sLineWord, "chargingProfileId");
  14674. memset(sstr ,0, sizeof(sstr) );
  14675. if(loc != NULL)
  14676. {
  14677. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14678. {
  14679. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14680. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14681. c++;
  14682. }
  14683. sstr[c] = '\0';
  14684. tempchargingProfileId = atoi(sstr);
  14685. }
  14686. else
  14687. {
  14688. tempchargingProfileId = 0;
  14689. }
  14690. //***********transactionId **************/
  14691. c = 0;
  14692. loc = strstr(sLineWord, "transactionId");
  14693. //DEBUG_INFO("loc=%s\n",loc);
  14694. memset(sstr ,0, sizeof(sstr) );
  14695. if(loc != NULL)
  14696. {
  14697. while (loc[2+strlen("transactionId")+c] != '\"')
  14698. {
  14699. sstr[c] = loc[2+strlen("transactionId")+c];
  14700. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14701. c++;
  14702. }
  14703. sstr[c] = '\0';
  14704. temptransactionId = atoi(sstr);
  14705. }
  14706. else
  14707. {
  14708. temptransactionId = 0;
  14709. }
  14710. //***********stackLevel**************/
  14711. c = 0;
  14712. loc = strstr(sLineWord, "stackLevel");
  14713. //DEBUG_INFO("loc=%s\n",loc);
  14714. memset(sstr ,0, sizeof(sstr) );
  14715. if(loc != NULL)
  14716. {
  14717. while (loc[2+strlen("stackLevel")+c] != '\"')
  14718. {
  14719. sstr[c] = loc[2+strlen("stackLevel")+c];
  14720. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14721. c++;
  14722. }
  14723. sstr[c] = '\0';
  14724. tempstackLevel = atoi(sstr);
  14725. }
  14726. else
  14727. {
  14728. tempstackLevel = 0;
  14729. }
  14730. //***********chargingProfilePurpose **************/
  14731. c = 0;
  14732. loc = strstr(sLineWord, "chargingProfilePurpose");
  14733. //DEBUG_INFO("loc=%s\n",loc);
  14734. memset(sstr ,0, sizeof(sstr) );
  14735. if(loc != NULL)
  14736. {
  14737. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14738. {
  14739. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14740. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14741. c++;
  14742. }
  14743. sstr[c] = '\0';
  14744. strcpy(tempchargingProfilePurposeStr,sstr);
  14745. }
  14746. else
  14747. {
  14748. strcpy(tempchargingProfilePurposeStr,"");
  14749. }
  14750. //***********chargingProfileKind **************/
  14751. c = 0;
  14752. loc = strstr(sLineWord, "chargingProfileKind");
  14753. //DEBUG_INFO("loc=%s\n",loc);
  14754. memset(sstr ,0, sizeof(sstr) );
  14755. if(loc != NULL)
  14756. {
  14757. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14758. {
  14759. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14760. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14761. c++;
  14762. }
  14763. sstr[c] = '\0';
  14764. strcpy(tempchargingProfileKindStr,sstr);
  14765. }
  14766. else
  14767. {
  14768. strcpy(tempchargingProfileKindStr,"");
  14769. }
  14770. //***********recurrencyKind **************/
  14771. c = 0;
  14772. loc = strstr(sLineWord, "recurrencyKind");
  14773. //DEBUG_INFO("loc=%s\n",loc);
  14774. memset(sstr ,0, sizeof(sstr) );
  14775. if(loc != NULL)
  14776. {
  14777. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14778. {
  14779. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14780. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14781. c++;
  14782. }
  14783. sstr[c] = '\0';
  14784. strcpy(temprecurrencyKindStr,sstr);
  14785. }
  14786. else
  14787. {
  14788. strcpy(temprecurrencyKindStr,"");
  14789. }
  14790. //***********validFrom**************/
  14791. c = 0;
  14792. loc = strstr(sLineWord, "validFrom");
  14793. if(loc != NULL)
  14794. {
  14795. memset(sstr ,0, sizeof(sstr) );
  14796. while (loc[3+strlen("validFrom")+c] != '\"')
  14797. {
  14798. sstr[c] = loc[3+strlen("validFrom")+c];
  14799. c++;
  14800. }
  14801. sstr[c] = '\0';
  14802. strcpy(tempvalidFromStr,sstr);
  14803. }
  14804. else
  14805. {
  14806. strcpy(tempvalidFromStr,"");
  14807. }
  14808. //***********validTo**************/
  14809. c = 0;
  14810. loc = strstr(sLineWord, "validTo");
  14811. if(loc != NULL)
  14812. {
  14813. memset(sstr ,0, sizeof(sstr) );
  14814. while (loc[3+strlen("validTo")+c] != '\"')
  14815. {
  14816. sstr[c] = loc[3+strlen("validTo")+c];
  14817. c++;
  14818. }
  14819. sstr[c] = '\0';
  14820. strcpy(tempvalidToStr,sstr);
  14821. }
  14822. else
  14823. {
  14824. strcpy(tempvalidToStr,"");
  14825. }
  14826. //***********duration**************/
  14827. c = 0;
  14828. loc = strstr(sLineWord, "duration");
  14829. //DEBUG_INFO("loc=%s\n",loc);
  14830. memset(sstr ,0, sizeof(sstr) );
  14831. if(loc != NULL)
  14832. {
  14833. while (loc[2+strlen("duration")+c] != '\"')
  14834. {
  14835. sstr[c] = loc[2+strlen("duration")+c];
  14836. c++;
  14837. }
  14838. sstr[c] = '\0';
  14839. tempdurationInt = atoi(sstr);
  14840. }
  14841. else
  14842. {
  14843. tempdurationInt = 0;
  14844. }
  14845. //**********startSchedule**********/
  14846. c = 0;
  14847. loc = strstr(sLineWord, "startSchedule");
  14848. if(loc != NULL)
  14849. {
  14850. memset(sstr ,0, sizeof(sstr) );
  14851. while (loc[3+strlen("startSchedule")+c] != '\"')
  14852. {
  14853. sstr[c] = loc[3+strlen("startSchedule")+c];
  14854. c++;
  14855. }
  14856. sstr[c] = '\0';
  14857. strcpy(tempstartScheduleStr, sstr);
  14858. strcpy(TxProfileScheduleStr, sstr);
  14859. }
  14860. else
  14861. {
  14862. strcpy(tempstartScheduleStr, "");
  14863. strcpy(TxProfileScheduleStr, "");
  14864. }
  14865. //**********chargingRateUnit**********/
  14866. c = 0;
  14867. loc = strstr(sLineWord, "chargingRateUnit");
  14868. memset(sstr ,0, sizeof(sstr) );
  14869. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14870. {
  14871. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14872. c++;
  14873. }
  14874. sstr[c] = '\0';
  14875. strcpy(tempchargingRateUnitStr, sstr);
  14876. //**********minChargingRate*******/
  14877. c = 0;
  14878. loc = strstr(sLineWord, "minChargingRate");
  14879. if(loc != NULL)
  14880. {
  14881. memset(sstr ,0, sizeof(sstr) );
  14882. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14883. {
  14884. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14885. c++;
  14886. }
  14887. sstr[c] = '\0';
  14888. tempminChargingRateFloat = atof(sstr);
  14889. }
  14890. else
  14891. {
  14892. tempminChargingRateFloat = 0.0;
  14893. }
  14894. //
  14895. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14896. tp.tm_isdst = -1;
  14897. time_t utc = mktime(&tp);
  14898. time_t t = time(NULL);
  14899. diff_t = difftime(t, utc);
  14900. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14901. //parsing strings to words
  14902. i = 0;
  14903. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14904. loc = loc+3+strlen("chargingSchedulePeriod");
  14905. pch = strtok(loc ,"{");
  14906. while (pch != NULL)
  14907. {
  14908. strcpy(SchedulePeriodList[i], pch);
  14909. pch = strtok (NULL, "{");
  14910. i = i + 1;
  14911. }
  14912. n_SchedulePeriods = i;
  14913. for(int i=0;i<n_SchedulePeriods;i++)
  14914. {
  14915. //*************startPeriod****************/
  14916. c = 0;
  14917. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14918. memset(sstr ,0, sizeof(sstr) );
  14919. while (loc[strlen("startPeriod")+2+c] != ',')
  14920. {
  14921. sstr[c] = loc[strlen("startPeriod")+2+c];
  14922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14923. c++;
  14924. }
  14925. sstr[c] = '\0';
  14926. tempStartPeriodInt = atoi(sstr);
  14927. //*************limit****************/
  14928. c = 0;
  14929. loc = strstr(SchedulePeriodList[i], "limit");
  14930. memset(sstr ,0, sizeof(sstr) );
  14931. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14932. {
  14933. sstr[c] = loc[strlen("limit")+2+c];
  14934. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14935. c++;
  14936. }
  14937. sstr[c] = '\0';
  14938. tempLimitInt = atof(sstr);
  14939. //*************numberPhases****************/
  14940. c = 0;
  14941. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14942. memset(sstr ,0, sizeof(sstr) );
  14943. if(loc != NULL)
  14944. {
  14945. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14946. {
  14947. sstr[c] = loc[strlen("numberPhases")+2+c];
  14948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14949. c++;
  14950. }
  14951. sstr[c] = '\0';
  14952. tempNumberPhasesInt = atoi(sstr);
  14953. }
  14954. else
  14955. {
  14956. tempNumberPhasesInt = 0;
  14957. }
  14958. //TxProfile.Duration = durationInt;
  14959. TxProfile.TotalPeriod = n_SchedulePeriods;
  14960. TxProfile.Period[i].Limit = tempLimitInt;
  14961. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14962. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14963. }
  14964. if(MinChargingRate < tempminChargingRateFloat)
  14965. {
  14966. MinChargingRate = tempminChargingRateFloat;
  14967. }
  14968. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14969. if(confirmPeriods < n_SchedulePeriods)
  14970. confirmPeriods = n_SchedulePeriods;
  14971. if(j == 0)
  14972. {
  14973. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14974. TxProfile_TEMP.StackLevel = tempstackLevel;
  14975. TxProfile_TEMP.TransactionId = 0;
  14976. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14977. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14978. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14979. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14980. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14981. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14982. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14983. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14984. }
  14985. }
  14986. fclose(fptr1);
  14987. }
  14988. }// the end of ACCESS TxProfile
  14989. //-----------------------------------------------CompositeSchedule--------------------------//
  14990. int period=0;
  14991. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14992. {
  14993. //TxProfile
  14994. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14995. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14996. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14997. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14998. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14999. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15000. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15001. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15002. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15003. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15004. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15005. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15006. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15007. for(int k=0; k < TxProfile.TotalPeriod;k++)
  15008. {
  15009. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  15010. {
  15011. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15012. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15013. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15014. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15015. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15016. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15017. period = period + 1;
  15018. }
  15019. else
  15020. {
  15021. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  15022. {
  15023. }
  15024. else
  15025. {
  15026. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15027. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15028. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15029. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15030. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15031. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15032. period = period + 1;
  15033. }
  15034. }
  15035. }
  15036. struct tm tp;
  15037. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15038. tp.tm_isdst = -1;
  15039. time_t utc = mktime(&tp);
  15040. time_t t = time(NULL);
  15041. double diff_f = difftime(t, utc);
  15042. int diff_i;// = (int)diff_f;
  15043. int quotient; // = diff_i / 86400;//86400 seconds/day
  15044. if(diff_f >= 0)
  15045. {
  15046. diff_i = (int)diff_f;
  15047. quotient = diff_i / 86400;//86400 seconds/day
  15048. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15049. {
  15050. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15051. {
  15052. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15053. {
  15054. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15055. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15056. }
  15057. else
  15058. {
  15059. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15060. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15061. }
  15062. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15063. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15064. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15065. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15066. period = period + 1;
  15067. }
  15068. }
  15069. }// end of if(diff_f >= 0)
  15070. }
  15071. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15072. {
  15073. //TxDefaultProfile
  15074. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15075. struct tm tp;
  15076. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15077. tp.tm_isdst = -1;
  15078. time_t utc = mktime(&tp);
  15079. time_t t = time(NULL);
  15080. double diff_f = difftime(t, utc);
  15081. int diff_i;// = (int)diff_f;
  15082. int quotient; // = diff_i / 86400;//86400 seconds/day
  15083. int remainder;
  15084. //---- Define StartSchedule----/
  15085. struct tm *gtime;
  15086. time_t now;
  15087. char buf[28];
  15088. //---Read the current system time---/
  15089. time(&now);
  15090. //---Convert the system time to GMT (now UTC)---/
  15091. gtime = gmtime(&now);
  15092. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15093. if(diff_f >= 0)
  15094. {
  15095. diff_i = (int)diff_f;
  15096. quotient = diff_i / 86400;//86400 seconds/day
  15097. remainder = diff_i % 86400;
  15098. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15099. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15100. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15101. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15102. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15103. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15104. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15105. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15106. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15107. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15108. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15109. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15110. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15111. {
  15112. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15113. {
  15114. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15115. {
  15116. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15117. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15118. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15119. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15120. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15121. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15122. period = period + 1;
  15123. }
  15124. else
  15125. {
  15126. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15127. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15128. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15129. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15130. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15131. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15132. period = period + 1;
  15133. }
  15134. }
  15135. }
  15136. } // end of diff_f >= 0
  15137. }
  15138. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15139. {
  15140. //TxDefaultProfile
  15141. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15142. struct tm tp;
  15143. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15144. tp.tm_isdst = -1;
  15145. time_t utc = mktime(&tp);
  15146. time_t t = time(NULL);
  15147. double diff_f = difftime(t, utc);
  15148. int diff_i;// = (int)diff_f;
  15149. int quotient; // = diff_i / 86400;//86400 seconds/day
  15150. int remainder;
  15151. //---- Define StartSchedule----/
  15152. struct tm *gtime;
  15153. time_t now;
  15154. char buf[28];
  15155. //---Read the current system time---/
  15156. time(&now);
  15157. //---Convert the system time to GMT (now UTC)---/
  15158. gtime = gmtime(&now);
  15159. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15160. if(diff_f >= 0)
  15161. {
  15162. diff_i = (int)diff_f;
  15163. quotient = diff_i / 86400;//86400 seconds/day
  15164. remainder = diff_i % 86400;
  15165. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15166. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15167. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15168. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15170. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15173. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15174. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15175. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15176. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15177. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15178. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15179. {
  15180. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15181. {
  15182. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15185. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15186. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15187. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15188. period = period + 1;
  15189. }
  15190. }
  15191. } //end of diff_f >= 0
  15192. }
  15193. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15194. {
  15195. //ChargePointMaxProfile
  15196. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15197. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15198. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15199. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15200. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15202. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15209. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15210. {
  15211. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15214. period = period + 1;
  15215. }
  15216. }
  15217. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15218. {
  15219. //TxProfile Daily
  15220. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15221. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15222. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15223. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15224. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15225. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15226. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15227. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15228. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15229. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15230. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15231. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15232. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15233. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15234. {
  15235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15238. }
  15239. }
  15240. confirmPeriods = period;
  15241. if(confirmPeriods != 0)
  15242. {
  15243. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15244. 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,"
  15245. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15246. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15247. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15248. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15249. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15250. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15251. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15252. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15253. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15254. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15256. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15257. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15260. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15261. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15262. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15274. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15281. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15282. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15283. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15284. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15285. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15289. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15290. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15291. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15297. }
  15298. }
  15299. void storeTempStopTransaction(int gun_index)
  15300. {
  15301. //int result = FAIL;
  15302. //char message[1500]={0};
  15303. char guid[37]={0};
  15304. int tempIndex = 0;
  15305. //char tempdata[65]={0};
  15306. //int idx_sample=0;
  15307. DEBUG_ERROR("sendStopTransactionRequest \n");
  15308. memset(queuedata, 0, sizeof(queuedata));
  15309. //ENERGY_ACTIVE_IMPORT_REGISTER
  15310. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15311. if(gunType[gun_index] == 'J')
  15312. {
  15313. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15314. {
  15315. tempIndex = ((gun_index==2) ? 1: 0);
  15316. }
  15317. else
  15318. {
  15319. tempIndex = gun_index;
  15320. }
  15321. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15322. {
  15323. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15324. {
  15325. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  15326. }
  15327. }// END OF CHAdeMO_QUANTITY
  15328. }
  15329. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15330. {
  15331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15332. {
  15333. tempIndex = ((gun_index==2) ? 1: 0);
  15334. }
  15335. else
  15336. {
  15337. tempIndex = gun_index;
  15338. }
  15339. for (int index = 0; index < CCS_QUANTITY; index++)
  15340. {
  15341. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15342. {
  15343. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  15344. }
  15345. }// END OF CCS_QUANTITY
  15346. }
  15347. else if(gunType[gun_index] == 'G')
  15348. {
  15349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15350. {
  15351. tempIndex = ((gun_index==2) ? 1: 0);
  15352. }
  15353. else
  15354. {
  15355. tempIndex = gun_index;
  15356. }
  15357. for (int index = 0; index < GB_QUANTITY; index++)
  15358. {
  15359. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15360. {
  15361. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  15362. }
  15363. }// END OF GB_QUANTITY
  15364. }
  15365. else
  15366. {
  15367. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15368. {
  15369. tempIndex = 2;
  15370. }
  15371. else
  15372. {
  15373. tempIndex = gun_index;
  15374. }
  15375. for (int index = 0; index < AC_QUANTITY; index++)
  15376. {
  15377. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15378. {
  15379. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15380. }
  15381. }// END OF AC_QUANTITY
  15382. }
  15383. //Stop Transaction Time
  15384. struct timeval tmnow;
  15385. struct tm *tm;
  15386. char buf[28];//, usec_buf[6];
  15387. gettimeofday(&tmnow, NULL);
  15388. time_t t;
  15389. t = time(NULL);
  15390. /*UTC time and date*/
  15391. tm = gmtime(&t);
  15392. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15393. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15394. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15395. random_uuid(guid);
  15396. /***********************************transactionData******************************************************/
  15397. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15399. //=================================
  15400. // Transaction_Begin
  15401. //=================================
  15402. // Energy.Active.Export.Interval
  15403. //idx_sample=0;
  15404. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15405. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15407. 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*/]);
  15408. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15409. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15410. {
  15411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15412. }
  15413. else
  15414. {
  15415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15416. }
  15417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15418. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15419. //=================================
  15420. // Transaction_End
  15421. //=================================
  15422. //Current.Export
  15423. //idx_sample=1;
  15424. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15425. if(gunType[gun_index] == 'J')
  15426. {
  15427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15428. {
  15429. tempIndex = ((gun_index==2) ? 1: 0);
  15430. }
  15431. else
  15432. {
  15433. tempIndex = gun_index;
  15434. }
  15435. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15436. {
  15437. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15438. {
  15439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15440. }
  15441. }// End of for CHAdeMO_QUANTITY
  15442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15443. }
  15444. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15445. {
  15446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15447. {
  15448. tempIndex = ((gun_index==2) ? 1: 0);
  15449. }
  15450. else
  15451. {
  15452. tempIndex = gun_index;
  15453. }
  15454. for (int index = 0; index < CCS_QUANTITY; index++)
  15455. {
  15456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15457. {
  15458. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15459. }
  15460. }// End of for CCS_QUANTITY
  15461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15462. }
  15463. else if(gunType[gun_index] == 'G')
  15464. {
  15465. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15466. {
  15467. tempIndex = ((gun_index==2) ? 1: 0);
  15468. }
  15469. else
  15470. {
  15471. tempIndex = gun_index;
  15472. }
  15473. for (int index = 0; index < GB_QUANTITY; index++)
  15474. {
  15475. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15476. {
  15477. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15478. }
  15479. }// End of for GB_QUANTITY
  15480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15481. }
  15482. else
  15483. {
  15484. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15485. {
  15486. tempIndex = 2;
  15487. }
  15488. else
  15489. {
  15490. tempIndex = gun_index;
  15491. }
  15492. for (int index = 0; index < AC_QUANTITY; index++)
  15493. {
  15494. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15495. {
  15496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15497. }
  15498. }// End of for AC_QUANTITY
  15499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15500. }
  15501. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15504. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15507. //Energy.Active.Export.Interval
  15508. //idx_sample=2;
  15509. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15510. if(gunType[gun_index] == 'J')
  15511. {
  15512. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15513. {
  15514. tempIndex = ((gun_index==2) ? 1: 0);
  15515. }
  15516. else
  15517. {
  15518. tempIndex = gun_index;
  15519. }
  15520. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15521. {
  15522. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15523. {
  15524. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15525. }
  15526. }// END OF CHAdeMO_QUANTITY
  15527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15528. }
  15529. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15530. {
  15531. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15532. {
  15533. tempIndex = ((gun_index==2) ? 1: 0);
  15534. }
  15535. else
  15536. {
  15537. tempIndex = gun_index;
  15538. }
  15539. for (int index = 0; index < CCS_QUANTITY; index++)
  15540. {
  15541. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15542. {
  15543. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15544. }
  15545. }// END OF CCS_QUANTITY
  15546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15547. }
  15548. else if(gunType[gun_index] == 'G')
  15549. {
  15550. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15551. {
  15552. tempIndex = ((gun_index==2) ? 1: 0);
  15553. }
  15554. else
  15555. {
  15556. tempIndex = gun_index;
  15557. }
  15558. for (int index = 0; index < GB_QUANTITY; index++)
  15559. {
  15560. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15561. {
  15562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15563. }
  15564. }// END OF GB_QUANTITY
  15565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15566. }
  15567. else
  15568. {
  15569. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15570. {
  15571. tempIndex = 2;
  15572. }
  15573. else
  15574. {
  15575. tempIndex = gun_index;
  15576. }
  15577. for (int index = 0; index < AC_QUANTITY; index++)
  15578. {
  15579. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15580. {
  15581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15582. }
  15583. }// END OF AC_QUANTITY
  15584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15585. }
  15586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15589. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15592. //Power.Active.Export
  15593. //idx_sample=3;
  15594. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15595. if(gunType[gun_index] == 'J')
  15596. {
  15597. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15598. {
  15599. tempIndex = ((gun_index==2) ? 1: 0);
  15600. }
  15601. else
  15602. {
  15603. tempIndex = gun_index;
  15604. }
  15605. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15606. {
  15607. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15608. {
  15609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15610. }
  15611. } // End for CHAdeMO_QUANTITY
  15612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15613. }
  15614. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15615. {
  15616. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15617. {
  15618. tempIndex = ((gun_index==2) ? 1: 0);
  15619. }
  15620. else
  15621. {
  15622. tempIndex = gun_index;
  15623. }
  15624. for (int index = 0; index < CCS_QUANTITY; index++)
  15625. {
  15626. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15627. {
  15628. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15629. }
  15630. } // END for CCS_QUANTITY
  15631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15632. }
  15633. else if(gunType[gun_index] == 'G')
  15634. {
  15635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15636. {
  15637. tempIndex = ((gun_index==2) ? 1: 0);
  15638. }
  15639. else
  15640. {
  15641. tempIndex = gun_index;
  15642. }
  15643. for (int index = 0; index < GB_QUANTITY; index++)
  15644. {
  15645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15646. {
  15647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15648. }
  15649. }// END for GB_QUANTITY
  15650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15651. }
  15652. else
  15653. {
  15654. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15655. {
  15656. tempIndex = 2;
  15657. }
  15658. else
  15659. {
  15660. tempIndex = gun_index;
  15661. }
  15662. for (int index = 0; index < AC_QUANTITY; index++)
  15663. {
  15664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15665. {
  15666. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15667. }
  15668. } // END for AC_QUANTITY
  15669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15670. }
  15671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15673. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15674. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15677. //Voltage
  15678. //idx_sample=4;
  15679. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15680. if(gunType[gun_index] == 'J')
  15681. {
  15682. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15683. {
  15684. tempIndex = ((gun_index==2) ? 1: 0);
  15685. }
  15686. else
  15687. {
  15688. tempIndex = gun_index;
  15689. }
  15690. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15691. {
  15692. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15693. {
  15694. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15695. }
  15696. } // END OF FOR CHAdeMO_QUANTITY
  15697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15698. }
  15699. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15700. {
  15701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15702. {
  15703. tempIndex = ((gun_index==2) ? 1: 0);
  15704. }
  15705. else
  15706. {
  15707. tempIndex = gun_index;
  15708. }
  15709. for (int index = 0; index < CCS_QUANTITY; index++)
  15710. {
  15711. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15712. {
  15713. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15714. }
  15715. } // END OF FOR CCS_QUANTITY
  15716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15717. }
  15718. else if(gunType[gun_index] == 'G')
  15719. {
  15720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15721. {
  15722. tempIndex = ((gun_index==2) ? 1: 0);
  15723. }
  15724. else
  15725. {
  15726. tempIndex = gun_index;
  15727. }
  15728. for (int index = 0; index < GB_QUANTITY; index++)
  15729. {
  15730. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15731. {
  15732. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15733. }
  15734. } // END OF FOR GB_QUANTITY
  15735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15736. }
  15737. else
  15738. {
  15739. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15740. {
  15741. tempIndex = 2;
  15742. }
  15743. else
  15744. {
  15745. tempIndex = gun_index;
  15746. }
  15747. for (int index = 0; index < AC_QUANTITY; index++)
  15748. {
  15749. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15750. {
  15751. 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
  15752. }
  15753. } // END OF FOR AC_QUANTITY
  15754. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15755. }
  15756. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15757. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15758. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15759. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15762. //SoC
  15763. //idx_sample=5;
  15764. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15765. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15766. {
  15767. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15768. {
  15769. tempIndex = ((gun_index==2) ? 1: 0);
  15770. }
  15771. else
  15772. {
  15773. tempIndex = gun_index;
  15774. }
  15775. if(gunType[gun_index] == 'J')
  15776. {
  15777. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15778. {
  15779. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15780. {
  15781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15782. }
  15783. }
  15784. }
  15785. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15786. {
  15787. for (int index = 0; index < CCS_QUANTITY; index++)
  15788. {
  15789. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15790. {
  15791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15792. }
  15793. }
  15794. }
  15795. else if(gunType[gun_index] == 'G')
  15796. {
  15797. for (int index = 0; index < GB_QUANTITY; index++)
  15798. {
  15799. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15800. {
  15801. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15802. }
  15803. }
  15804. }
  15805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15806. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15807. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15811. } // END FOR DC CASE
  15812. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15813. {
  15814. 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\"}]}]}]"
  15815. ,MESSAGE_TYPE_CALL
  15816. ,guid
  15817. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15818. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15819. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15821. ,"PowerLoss"
  15822. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15865. );
  15866. }
  15867. else
  15868. {
  15869. 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\"}]}]}]"
  15870. ,MESSAGE_TYPE_CALL
  15871. ,guid
  15872. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15873. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15874. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15876. ,"PowerLoss"
  15877. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15913. );
  15914. }
  15915. // Check File "TempStopTransaction" Exist
  15916. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15917. {
  15918. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15919. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15920. }
  15921. else
  15922. {
  15923. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15924. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15925. if(log == NULL)
  15926. {
  15927. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15928. return ;
  15929. }
  15930. else
  15931. {
  15932. fclose(log);
  15933. }
  15934. }
  15935. //Add TempStopTransaction | Update TempStopTransaction
  15936. // open file for writing
  15937. FILE *outfile;
  15938. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15939. DEBUG_INFO("data=%s\n",queuedata);
  15940. fputs(queuedata, outfile);
  15941. fputs("\n", outfile);
  15942. fclose (outfile);
  15943. }
  15944. void checkTempStopTransaction(int gun_index)
  15945. {
  15946. FILE *fptr1;
  15947. char ch;
  15948. char str[1200]={0};
  15949. char guid[37]={0};
  15950. char tempdata[65]={0};
  15951. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  15952. if (!fptr1)
  15953. {
  15954. //printf(" File not found or unable to open the input file!!\n");
  15955. return ;
  15956. }
  15957. ch=fgetc(fptr1);
  15958. //printf(" Now the content of the file %s is : \n",fname);
  15959. rewind(fptr1);
  15960. if(ch!=EOF)
  15961. {
  15962. // copy all contents to the temporary file except the specific line
  15963. while (fgets(str, 1200, fptr1) != NULL)
  15964. {
  15965. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15966. if(str[0]=='\0')
  15967. {
  15968. break;
  15969. }
  15970. random_uuid(guid);
  15971. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15972. if(hashmap_operation(0, guid, tempdata) == 1)
  15973. {
  15974. DEBUG_INFO("StopTransaction mapitem pass\n");
  15975. }
  15976. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15977. memset(str,0,sizeof str);
  15978. }
  15979. }
  15980. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15981. fclose(fptr1);
  15982. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15983. }
  15984. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15985. {
  15986. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15987. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15988. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15989. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15990. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15991. }
  15992. int GetWebSocketPingInterval(void)
  15993. {
  15994. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15995. }
  15996. int GetServerSign(void)
  15997. {
  15998. return server_sign;
  15999. }
  16000. void SetServerSign(int value)
  16001. {
  16002. server_sign = value;
  16003. }
  16004. int GetBootNotificationInterval(void)
  16005. {
  16006. return BootNotificationInterval;
  16007. }
  16008. int GetInternetConn(void)
  16009. {
  16010. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16011. }
  16012. void InitialSystemValue(void)
  16013. {
  16014. int connectorIndex = 0;
  16015. //int valueASCII = 0;
  16016. server_cycle_Status = 120;
  16017. gunTotalNumber=0;
  16018. SystemInitial = 0;
  16019. localversion=0;
  16020. BootNotificationInterval = 0;
  16021. authorizeRetryTimes = 0;
  16022. GunStatusInterval = 10;
  16023. TransactionMessageAttemptsValue = 0;
  16024. TransactionMessageRetryIntervalValue = 0;
  16025. //Hear Beat
  16026. HeartBeatWithNOResponse = 0;
  16027. HeartBeatCountPerHour = 0;
  16028. HeartBeatWaitTime = 10;
  16029. FirstHeartBeat = 0;
  16030. FirmwareStatusNotificationStatus = 3; // Idle
  16031. DiagnosticsStatusNotificationStatus = 0; // Idle
  16032. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16033. memset(statusModeChage, 0, sizeof(statusModeChage));
  16034. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16035. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16036. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16037. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16038. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16039. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16040. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16041. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16042. memset(gunType, 0, sizeof(gunType));
  16043. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16044. {
  16045. //check connector / socket type (index: 8, 9, 10)
  16046. for(int index=7; index <10 ; index++)
  16047. {
  16048. if(index != 8)
  16049. {
  16050. // DC Connector
  16051. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16052. {
  16053. SystemInitial = SystemInitial + 1;
  16054. gunTotalNumber = gunTotalNumber + 1;
  16055. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16056. connectorIndex = connectorIndex + 1;
  16057. }
  16058. }
  16059. else
  16060. {
  16061. // AC Connector
  16062. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16063. {
  16064. SystemInitial = SystemInitial + 1;
  16065. gunTotalNumber = gunTotalNumber + 1;
  16066. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16067. connectorIndex = connectorIndex + 1;
  16068. }
  16069. }
  16070. }
  16071. //DEBUG_INFO("DC ...\n");
  16072. }
  16073. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16074. {
  16075. //check connector / socket type (index: 8, 9, 10)
  16076. for(int index=7; index <10 ; index++)
  16077. {
  16078. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16079. {
  16080. SystemInitial = SystemInitial + 1;
  16081. gunTotalNumber = gunTotalNumber + 1;
  16082. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16083. connectorIndex = connectorIndex + 1;
  16084. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16085. }
  16086. }
  16087. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16088. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16089. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16090. //DEBUG_INFO("AC ...\n");
  16091. }
  16092. //Status && ConnectorPlugIn Setting
  16093. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16094. {
  16095. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16096. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16097. }
  16098. for (int index = 0; index < CCS_QUANTITY; index++)
  16099. {
  16100. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16101. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16102. }
  16103. for (int index = 0; index < GB_QUANTITY; index++)
  16104. {
  16105. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16106. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16107. }
  16108. for (int index = 0; index < AC_QUANTITY; index++)
  16109. {
  16110. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16111. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16112. }
  16113. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16114. {
  16115. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16116. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16117. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16118. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16119. }
  16120. // Charger PRE_SYS_MODE
  16121. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16122. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16123. clientTime.Heartbeat=time((time_t*)NULL);
  16124. sleep(1);
  16125. }
  16126. void LWS_Send(char * str)
  16127. {
  16128. //=====================================================
  16129. // Check InternetConn 0: disconnected, 1: connected
  16130. //====================================================
  16131. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16132. {
  16133. DEBUG_INFO("\n offline now !!!\n");
  16134. return;
  16135. }
  16136. pthread_mutex_lock(&lock);
  16137. memset(SendBuffer,0,SendBufLen);
  16138. sprintf((char *)SendBuffer, "%s", str);
  16139. pthread_mutex_unlock(&lock);
  16140. lws_callback_on_writable(wsi_client);
  16141. lws_service(context, 10000);//timeout_ms
  16142. }