MessageHandler.c 576 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817
  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 "hashmap.h"
  21. #include "ShareMemory.h"
  22. #include "TransactionQueue.h"
  23. #include "SystemLogMessage.h"
  24. #include "define.h"
  25. #include "ShareMemory.h"
  26. #include "SystemLogMessage.h"
  27. //#include "config.h"
  28. #include <sys/socket.h>
  29. #include <netinet/in.h>
  30. #include <stdlib.h>
  31. /*for sendfile()*/
  32. #include <sys/sendfile.h>
  33. /*for O_RDONLY*/
  34. #include <fcntl.h>
  35. #include "sqlite3.h"
  36. #include <arpa/inet.h>
  37. //#define _GNU_SOURCE
  38. #include <time.h>
  39. #include "MessageHandler.h"
  40. #include <assert.h>
  41. #include <pthread.h>
  42. #include <mcheck.h>
  43. #define PASS 1
  44. #define FAIL -1
  45. #define FALSE 0
  46. #define TRUE 1 // Option 1
  47. //ChargePointMaxProfile
  48. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  49. //TxDefaultProfile
  50. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  51. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  52. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  53. //TxProfile
  54. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  55. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  56. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  57. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  58. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  59. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  60. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  61. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  62. struct StatusCodeData *ShmStatusCodeData;
  63. struct PsuData *ShmPsuData ;
  64. struct OCPP16Data *ShmOCPP16Data;
  65. // define Macro
  66. #define SystemLogMessage
  67. // OCPP Message Type
  68. #define MESSAGE_TYPE_CALL 2
  69. #define MESSAGE_TYPE_CALLRESULT 3
  70. #define MESSAGE_TYPE_CALLERROR 4
  71. //
  72. #define server_cycle_Status 120
  73. #define MACROSTR(k) #k
  74. //ConfigurationMaxKeys
  75. #define GetConfigurationMaxKeysNUM 43
  76. //char guid[37];
  77. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  78. char queuedata[2600]={0};
  79. //===============================
  80. // Configuration: unknownkey
  81. //===============================
  82. static char unknownkey[10][20]={0};
  83. static int UnknownKeynum = 0;
  84. //===============================
  85. // Gun Total Numbers
  86. //===============================
  87. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  88. static int gunTotalNumber=0;
  89. //===============================
  90. // Local List Version
  91. //===============================
  92. static int localversion=0;
  93. static char idTagAuthorization[32]={0};
  94. //===============================
  95. // OCPP Path
  96. //===============================
  97. extern char OcppPath[160];
  98. extern char OcppProtocol[10];
  99. extern char OcppHost[50];
  100. extern char OcppTempPath[50];
  101. int OcppPort=0;
  102. //===============================
  103. // OCPP sign variable
  104. //===============================
  105. int server_sign = FALSE;
  106. int server_pending = FALSE;
  107. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  108. int BootNotificationInterval = 0;
  109. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  110. //===============================
  111. // OCPP auth variable
  112. //===============================
  113. int authenrequest = FALSE;
  114. int authorizeRetryTimes = 0; //number of Retry times
  115. //===============================
  116. // OCPP StartTransaction transactionId variables
  117. //===============================
  118. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  119. //===============================
  120. // OCPP other variables
  121. //===============================
  122. int isUpdateRequest = FALSE;
  123. static int HeartBeatWaitTime = 10;
  124. static int FirstHeartBeat = 0;
  125. static int FirmwareStatusNotificationStatus = 3; // Idle
  126. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  127. static char CurrentChargingProfileScheduleStr[30]={0};
  128. //========================================
  129. // OCPP status/previous related variables
  130. //========================================
  131. static int GunStatusInterval = 10;
  132. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  133. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  134. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  135. static int GbPreviousSystemStatus[GB_QUANTITY];
  136. static int AcPreviousSystemStatus[AC_QUANTITY];
  137. int TransactionMessageAttemptsValue = 0;
  138. int TransactionMessageRetryIntervalValue = 0;
  139. static struct OCPPAuthLocalElemet
  140. {
  141. int listVersionInt;
  142. char idTagstr[20];
  143. char parentIdTag[20];
  144. char expiryDate[30];
  145. char idTagstatus[16];
  146. }idTagQuery;
  147. //=============================================
  148. // OCPP HeartBeat Response Not Receive Counts
  149. //============================================
  150. static int HeartBeatWithNOResponse = 0;
  151. static int HeartBeatCount = 0;
  152. extern struct lws *wsi_client;
  153. extern struct lws_context *context;
  154. #if 0
  155. extern unsigned char *SendBuffer;
  156. #endif
  157. extern unsigned char SendBuffer[4096];
  158. extern int SendBufLen;
  159. //extern map_t hashMap;
  160. //extern data_struct_t* mapItem; --- remove for temporally
  161. //extern data_struct_t mapItem[0];
  162. extern char *random_uuid( char buf[37] );
  163. extern void split(char **arr, char *str, const char *del);
  164. extern pthread_mutex_t mutex1;
  165. extern struct Charger_Info Charger;
  166. extern sqlite3 *db;
  167. int TransactionMessageAttemptsGet(void);
  168. int TransactionMessageRetryIntervalGet(void);
  169. int GetOcppConnStatus(void);
  170. void SetOcppConnStatus(uint8_t status);
  171. int updateSetting(char *key, char *value);
  172. int setKeyValue(char *key, char *value);
  173. void OCPP_get_TableAuthlocalAllData(void);
  174. void processUnkownKey(void);
  175. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  176. struct StructOCPPMeterValue
  177. {
  178. unsigned char TimeStamp[28];
  179. struct StructSampledValue SampledValue[10];
  180. };
  181. struct ClientTime
  182. {
  183. unsigned int Heartbeat;
  184. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  185. unsigned int StartTransaction;
  186. unsigned int StopTransaction;
  187. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  188. }clientTime;
  189. typedef union
  190. {
  191. //Operations Initiated by Central System
  192. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  193. struct
  194. {
  195. //CsMsgValue[0]
  196. unsigned char StatusNotificationReq :1; //bit 0,
  197. unsigned char StatusNotificationConf :1; //bit 0,
  198. unsigned char :6; //bit 2~7
  199. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  200. }CpinitiateMsg;
  201. CpinitiateMsg cpinitateMsg;
  202. //==========================================
  203. // Init all Enumeration & Mapping String
  204. //==========================================
  205. /*ChargePointErrorCode*/
  206. typedef enum {
  207. ConnectorLockFailure,
  208. EVCommunicationError,
  209. GroundFailure,
  210. HighTemperature,
  211. InternalError,
  212. LocalListConflict,
  213. NoError,
  214. OtherError,
  215. OverCurrentFailure,
  216. OverVoltage,
  217. PowerMeterFailure,
  218. PowerSwitchFailure,
  219. ReaderFailure,
  220. ResetFailure,
  221. UnderVoltage,
  222. WeakSignal
  223. } ChargePointErrorCode;
  224. #if 0
  225. static char *ChargePointErrorCodeStr[] = {
  226. MACROSTR(ConnectorLockFailure),
  227. MACROSTR(EVCommunicationError),
  228. MACROSTR(GroundFailure),
  229. MACROSTR(HighTemperature),
  230. MACROSTR(InternalError),
  231. MACROSTR(LocalListConflict),
  232. MACROSTR(NoError),
  233. MACROSTR(OtherError),
  234. MACROSTR(OverCurrentFailure),
  235. MACROSTR(OverVoltage),
  236. MACROSTR(PowerMeterFailure),
  237. MACROSTR(PowerSwitchFailure),
  238. MACROSTR(ReaderFailure),
  239. MACROSTR(ResetFailure),
  240. MACROSTR(UnderVoltage),
  241. MACROSTR(WeakSignal)
  242. };
  243. #endif
  244. /*ChargePointStatus*/
  245. typedef enum {
  246. Available =0,
  247. Preparing,
  248. Charging,
  249. SuspendedEVSE,
  250. SuspendedEV,
  251. Finishing,
  252. Reserved,
  253. Unavailable,
  254. Faulted
  255. } ChargePointStatus;
  256. static char * ChargePointStatusStr[] = {
  257. MACROSTR(Available),
  258. MACROSTR(Preparing),
  259. MACROSTR(Charging),
  260. MACROSTR(SuspendedEVSE),
  261. MACROSTR(SuspendedEV),
  262. MACROSTR(Finishing),
  263. MACROSTR(Reserved),
  264. MACROSTR(Unavailable),
  265. MACROSTR(Faulted)
  266. };
  267. /*AvailabilityType*/
  268. typedef enum {
  269. RegistrationStatus_Accepted,
  270. RegistrationStatus_Pending,
  271. RegistrationStatus_Rejected
  272. } RegistrationStatus;
  273. static char *RegistrationStatusStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Pending),
  276. MACROSTR(Rejected)
  277. };
  278. /*AvailabilityType*/
  279. typedef enum {
  280. Inoperative,
  281. Operative
  282. } AvailabilityType;
  283. static char *AvailabilityTypeStr[] = {
  284. MACROSTR(Inoperative),
  285. MACROSTR(Operative)
  286. };
  287. /*AvailabilityStatus*/
  288. typedef enum {
  289. Accepted,
  290. Rejected,
  291. Scheduled
  292. } AvailabilityStatus;
  293. static char *AvailabilityStatusStr[] = {
  294. MACROSTR(Accepted),
  295. MACROSTR(Rejected),
  296. MACROSTR(Scheduled)
  297. };
  298. /*ConfigurationStatus*/
  299. typedef enum {
  300. ConfigurationStatus_Accepted,
  301. ConfigurationStatus_Rejected,
  302. RebootRequired,
  303. NotSupported
  304. } ConfigurationStatus;
  305. static char *ConfigurationStatusStr[] = {
  306. MACROSTR(Accepted),
  307. MACROSTR(Rejected),
  308. MACROSTR(RebootRequired),
  309. MACROSTR(NotSupported)
  310. };
  311. /*ClearCacheStatus*/
  312. typedef enum {
  313. ClearCacheStatus_Accepted,
  314. ClearCacheStatus_Rejected
  315. } ClearCacheStatus;
  316. static char *ClearCacheStatusStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected)
  319. };
  320. /*ChargingProfilePurposeType*/
  321. typedef enum {
  322. ChargePointMaxProfile,
  323. TxDefaultProfile,
  324. TxProfile
  325. } ChargingProfilePurposeType;
  326. static char *ChargingProfilePurposeTypeStr[] = {
  327. MACROSTR(ChargePointMaxProfile),
  328. MACROSTR(TxDefaultProfile),
  329. MACROSTR(TxProfile)
  330. };
  331. /*ChargingProfileStatus*/
  332. typedef enum {
  333. ChargingProfileStatus_Accepted,
  334. ChargingProfileStatus_Rejected,
  335. ChargingProfileStatus_NotSupported
  336. } ChargingProfileStatus;
  337. static char *ChargingProfileStatusStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(NotSupported)
  341. };
  342. /*ClearChargingProfileStatus*/
  343. typedef enum {
  344. ClearChargingProfileStatus_Accepted,
  345. ClearChargingProfileStatus_Unknown
  346. } ClearChargingProfileStatus;
  347. static char *ClearChargingProfileStatusStr[] = {
  348. MACROSTR(Accepted),
  349. MACROSTR(Unknown)
  350. };
  351. /*GetCompositeScheduleStatus*/
  352. typedef enum {
  353. GetCompositeScheduleStatus_Accepted,
  354. GetCompositeScheduleStatus_Rejected
  355. } GetCompositeScheduleStatus;
  356. static char *GetCompositeScheduleStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Rejected)
  359. };
  360. /*ChargingRateUnitType*/
  361. typedef enum {
  362. ChargingRateUnitType_W,
  363. ChargingRateUnitType_A
  364. } ChargingRateUnitType;
  365. /*AuthorizationStatus*/
  366. typedef enum {
  367. AuthorizationStatus_Accepted ,
  368. AuthorizationStatus_Blocked ,
  369. AuthorizationStatus_Expired ,
  370. AuthorizationStatus_Invalid ,
  371. AuthorizationStatus_ConcurrentTx
  372. } AuthorizationStatus;
  373. /*UpdateType*/
  374. typedef enum {
  375. Differential ,
  376. Full
  377. } UpdateType;
  378. static char *UpdateTypeStr[] = {
  379. MACROSTR(Differential),
  380. MACROSTR(Full)
  381. };
  382. /*UpdateStatus*/
  383. typedef enum {
  384. UpdateStatus_Accepted ,
  385. UpdateStatus_Failed ,
  386. UpdateStatus_NotSupported ,
  387. UpdateStatus_VersionMismatch
  388. } UpdateStatus;
  389. static char *UpdateStatusStr[] = {
  390. MACROSTR(Accepted),
  391. MACROSTR(Failed),
  392. MACROSTR(NotSupported),
  393. MACROSTR(VersionMismatch)
  394. };
  395. /*RemoteStartStopStatus*/
  396. typedef enum {
  397. RemoteStartStopStatus_Accepted,
  398. RemoteStartStopStatus_Rejected
  399. } RemoteStartStopStatus;
  400. static char *RemoteStartStopStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected)
  403. };
  404. /*ReservationStatus*/
  405. typedef enum {
  406. ReservationStatus_Accepted,
  407. ReservationStatus_Faulted,
  408. ReservationStatus_Occupied,
  409. ReservationStatus_Rejected,
  410. ReservationStatus_Unavailable
  411. } ReservationStatus;
  412. static char *ReservationStatusStr[] = {
  413. MACROSTR(Accepted),
  414. MACROSTR(Faulted),
  415. MACROSTR(Occupied),
  416. MACROSTR(Rejected),
  417. MACROSTR(Unavailable)
  418. };
  419. /*ResetType*/
  420. typedef enum {
  421. Hard,
  422. Soft
  423. } ResetType;
  424. static char *ResetTypeStr[] = {
  425. MACROSTR(Hard),
  426. MACROSTR(Soft)
  427. };
  428. /*ResetStatus*/
  429. typedef enum {
  430. ResetStatus_Accepted,
  431. ResetStatus_Rejected
  432. } ResetStatus;
  433. static char *ResetStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected)
  436. };
  437. /*DiagnosticsStatus*/
  438. typedef enum {
  439. DiagnosticsStatus_Idle,
  440. DiagnosticsStatus_Uploaded,
  441. DiagnosticsStatus_UploadFailed,
  442. DiagnosticsStatus_Uploading
  443. } DiagnosticsStatus;
  444. static char * DiagnosticsStatusStr[] = {
  445. MACROSTR(Idle),
  446. MACROSTR(Uploaded),
  447. MACROSTR(UploadFailed),
  448. MACROSTR(Uploading)
  449. };
  450. /*FirmwareStatus*/
  451. typedef enum {
  452. FirmwareStatus_Downloaded,
  453. FirmwareStatus_DownloadFailed,
  454. FirmwareStatus_Downloading,
  455. FirmwareStatus_Idle,
  456. FirmwareStatus_InstallationFailed,
  457. FirmwareStatus_Installing,
  458. FirmwareStatus_Installed
  459. } FirmwareStatus;
  460. static char * FirmwareStatusStr[] = {
  461. MACROSTR(Downloaded),
  462. MACROSTR(DownloadFailed),
  463. MACROSTR(Downloading),
  464. MACROSTR(Idle),
  465. MACROSTR(InstallationFailed),
  466. MACROSTR(Installing),
  467. MACROSTR(Installed)
  468. };
  469. /*MessageTrigger*/
  470. typedef enum {
  471. BootNotification,
  472. DiagnosticsStatusNotification,
  473. FirmwareStatusNotification,
  474. Heartbeat,
  475. MeterValues,
  476. StatusNotification
  477. } MessageTrigger;
  478. static char * MessageTriggerStr[] = {
  479. MACROSTR(BootNotification),
  480. MACROSTR(DiagnosticsStatusNotification),
  481. MACROSTR(FirmwareStatusNotification),
  482. MACROSTR(Heartbeat),
  483. MACROSTR(MeterValues),
  484. MACROSTR(StatusNotification)
  485. };
  486. /*TriggerMessageStatus*/
  487. typedef enum {
  488. TriggerMessageStatus_Accepted ,
  489. TriggerMessageStatus_Rejected ,
  490. TriggerMessageStatus_NotImplemented
  491. } TriggerMessageStatus;
  492. static char * TriggerMessageStatusStr[] = {
  493. MACROSTR(Accepted),
  494. MACROSTR(Rejected),
  495. MACROSTR(NotImplemented)
  496. };
  497. /*UnlockStatus*/
  498. typedef enum {
  499. Unlocked,
  500. UnlockFailed,
  501. UnlockStatus_NotSupported
  502. } UnlockStatus;
  503. static char * UnlockStatusStr[] = {
  504. MACROSTR(Unlocked),
  505. MACROSTR(UnlockFailed),
  506. MACROSTR(NotSupported)
  507. };
  508. /*StopTransactionReason*/
  509. typedef enum {
  510. EmergencyStop,
  511. EVDisconnected,
  512. HardReset,
  513. Local,
  514. Other,
  515. PowerLoss,
  516. Reboot,
  517. Remote,
  518. SoftReset,
  519. UnlockCommand,
  520. DeAuthorized
  521. } StopTransactionReason;
  522. static char * StopTransactionReasonStr[] = {
  523. MACROSTR(EmergencyStop),
  524. MACROSTR(EVDisconnected),
  525. MACROSTR(HardReset),
  526. MACROSTR(Local),
  527. MACROSTR(Other),
  528. MACROSTR(PowerLoss),
  529. MACROSTR(Reboot),
  530. MACROSTR(Remote),
  531. MACROSTR(SoftReset),
  532. MACROSTR(UnlockCommand),
  533. MACROSTR(DeAuthorized)
  534. };
  535. /*CancelReservationStatus*/
  536. typedef enum {
  537. CancelReservationStatus_Accepted,
  538. CancelReservationStatus_Rejected
  539. } CancelReservationStatus;
  540. static char * CancelReservationStatusStr[] = {
  541. MACROSTR(Accepted),
  542. MACROSTR(Rejected)
  543. };
  544. /*ReadingContext*/
  545. typedef enum {
  546. ReadingContext_Interruption_Begin,
  547. ReadingContext_Interruption_End,
  548. ReadingContext_Other,
  549. ReadingContext_Sample_Clock,
  550. ReadingContext_Sample_Periodic ,
  551. ReadingContext_Transaction_Begin ,
  552. ReadingContext_Transaction_End,
  553. ReadingContext_Trigger
  554. } ReadingContext;
  555. static char * ReadingContextStr[] = {
  556. MACROSTR(Interruption.Begin),
  557. MACROSTR(Interruption.End),
  558. MACROSTR(Other),
  559. MACROSTR(Sample.Clock),
  560. MACROSTR(Sample.Periodic),
  561. MACROSTR(Transaction.Begin),
  562. MACROSTR(Transaction.End),
  563. MACROSTR(Trigger)
  564. };
  565. /*ValueFormat*/
  566. typedef enum {
  567. Raw,
  568. SignedData
  569. } ValueFormat;
  570. static char * ValueFormatStr[] = {
  571. MACROSTR(Raw),
  572. MACROSTR(SignedData)
  573. };
  574. /*Measurand*/
  575. typedef enum {
  576. Current_Export ,
  577. Current_Import,
  578. Current_Offered,
  579. Energy_Active_Export_Register,
  580. Energy_Active_Import_Register,
  581. Energy_Reactive_Export_Register,
  582. Energy_Reactive_Import_Register,
  583. Energy_Active_Export_Interval,
  584. Energy_Active_Import_Interval,
  585. Energy_Reactive_Export_Interval,
  586. Energy_Reactive_Import_Interval,
  587. Frequency,
  588. Power_Active_Export ,
  589. Power_Active_Import,
  590. Power_Factor,
  591. Power_Offered,
  592. Power_Reactive_Export,
  593. Power_Reactive_Import,
  594. RPM,
  595. SoC,
  596. Temperature ,
  597. Voltage
  598. } Measurand;
  599. static char * MeasurandStr[] = {
  600. MACROSTR(Current.Export),
  601. MACROSTR(Current.Import),
  602. MACROSTR(Current.Offered),
  603. MACROSTR(Energy.Active.Export.Register),
  604. MACROSTR(Energy.Active.Import.Register),
  605. MACROSTR(Energy.Reactive.Export.Register),
  606. MACROSTR(Energy.Reactive.Import.Register),
  607. MACROSTR(Energy.Active.Export.Interval),
  608. MACROSTR(Energy.Active.Import.Interval),
  609. MACROSTR(Energy.Reactive.Export.Interval),
  610. MACROSTR(Energy.Reactive.Import.Interval),
  611. MACROSTR(Frequency),
  612. MACROSTR(Power.Active.Export),
  613. MACROSTR(Power.Active.Import),
  614. MACROSTR(Power.Factor),
  615. MACROSTR(Power.Offered),
  616. MACROSTR(Power.Reactive.ExportMACROSTR),
  617. MACROSTR(Power.Reactive.Import),
  618. MACROSTR(RPM),
  619. MACROSTR(SoC),
  620. MACROSTR(Temperature),
  621. MACROSTR(Voltage)
  622. };
  623. /*Location*/
  624. typedef enum {
  625. Location_Body,
  626. Location_Cable,
  627. Location_EV,
  628. Location_Inlet ,
  629. Location_Outlet
  630. } Location;
  631. static char * LocationStr[] = {
  632. MACROSTR(Body),
  633. MACROSTR(Cable),
  634. MACROSTR(EV),
  635. MACROSTR(Inlet),
  636. MACROSTR(Outlet)
  637. };
  638. /*Phase*/
  639. typedef enum {
  640. L1,
  641. L2,
  642. L3,
  643. N,
  644. L1_N,
  645. L2_N,
  646. L3_N,
  647. L1_L2,
  648. L2_L3,
  649. L3_L1
  650. } Phase;
  651. static char * PhaseStr[] = {
  652. MACROSTR(L1),
  653. MACROSTR(L2),
  654. MACROSTR(L3),
  655. MACROSTR(N),
  656. MACROSTR(L1-N),
  657. MACROSTR(L2-N),
  658. MACROSTR(L3-N),
  659. MACROSTR(L1-L2),
  660. MACROSTR(L2-L3),
  661. MACROSTR(L3-L1)
  662. };
  663. /*UnitOfMeasure*/
  664. typedef enum {
  665. UnitOfMeasure_Wh,
  666. UnitOfMeasure_kWh ,
  667. UnitOfMeasure_varh ,
  668. UnitOfMeasure_kvarh ,
  669. UnitOfMeasure_W ,
  670. UnitOfMeasure_kW ,
  671. UnitOfMeasure_VA ,
  672. UnitOfMeasure_kVA ,
  673. UnitOfMeasure_var ,
  674. UnitOfMeasure_kvar ,
  675. UnitOfMeasure_A ,
  676. UnitOfMeasure_V ,
  677. UnitOfMeasure_Celsius ,
  678. UnitOfMeasure_Fahrenheit ,
  679. UnitOfMeasure_K ,
  680. UnitOfMeasure_Percent
  681. } UnitOfMeasure;
  682. static char * UnitOfMeasureStr[] = {
  683. MACROSTR(Wh),
  684. MACROSTR(kWh),
  685. MACROSTR(varh),
  686. MACROSTR(kvarh),
  687. MACROSTR(W),
  688. MACROSTR(kW),
  689. MACROSTR(VA),
  690. MACROSTR(kVA),
  691. MACROSTR(var),
  692. MACROSTR(kvar),
  693. MACROSTR(A),
  694. MACROSTR(V),
  695. MACROSTR(Celsius),
  696. MACROSTR(Fahrenheit),
  697. MACROSTR(K),
  698. MACROSTR(Percent)
  699. };
  700. #if 0
  701. /*Configuration enum*/
  702. enum CoreProfile {
  703. AllowOfflineTxForUnknownId=0,
  704. AuthorizationCacheEnabled,
  705. AuthorizeRemoteTxRequests,
  706. BlinkRepeat,
  707. ClockAlignedDataInterval,
  708. ConnectionTimeOut,
  709. GetConfigurationMaxKeys,
  710. HeartbeatInterval,
  711. LightIntensity,
  712. LocalAuthorizeOffline,
  713. LocalPreAuthorize,
  714. MaxEnergyOnInvalidId,
  715. MeterValuesAlignedData,
  716. MeterValuesAlignedDataMaxLength,
  717. MeterValuesSampledData,
  718. MeterValuesSampledDataMaxLength,
  719. MeterValueSampleInterval,
  720. MinimumStatusDuration,
  721. NumberOfConnectors,
  722. ResetRetries,
  723. ConnectorPhaseRotation,
  724. ConnectorPhaseRotationMaxLength,
  725. StopTransactionOnEVSideDisconnect,
  726. StopTransactionOnInvalidId,
  727. StopTxnAlignedData,
  728. StopTxnAlignedDataMaxLength,
  729. StopTxnSampledData,
  730. StopTxnSampledDataMaxLength,
  731. SupportedFeatureProfiles,
  732. SupportedFeatureProfilesMaxLength,
  733. TransactionMessageAttempts,
  734. TransactionMessageRetryInterval,
  735. UnlockConnectorOnEVSideDisconnect,
  736. WebSocketPingInterval,
  737. _CoreProfile_CNT
  738. };
  739. #endif
  740. enum LocalAuthListManagementProfile{
  741. LocalAuthListEnabled=0,
  742. LocalAuthListMaxLength,
  743. SendLocalListMaxLength,
  744. _LocalAuthListManagementProfile_CNT
  745. };
  746. enum ReservationProfile{
  747. ReserveConnectorZeroSupported
  748. };
  749. enum SmartChargingProfile{
  750. ChargeProfileMaxStackLevel,
  751. ChargingScheduleAllowedChargingRateUnit,
  752. ChargingScheduleMaxPeriods,
  753. ConnectorSwitch3to1PhaseSupported,
  754. MaxChargingProfilesInstalled
  755. };
  756. enum ChargerSystemStatus{
  757. ChargerSystemStatus_Booting,
  758. ChargerSystemStatus_Idle,
  759. ChargerSystemStatus_Authorizing,
  760. ChargerSystemStatus_Preparing,
  761. ChargerSystemStatus_Charging,
  762. ChargerSystemStatus_Terminating,
  763. ChargerSystemStatus_Alarm,
  764. ChargerSystemStatus_Fault
  765. };
  766. enum GetConfigurationKey {
  767. GetConfiguration_AllowOfflineTxForUnknownId=0,
  768. GetConfiguration_AuthorizationCacheEnabled,
  769. GetConfiguration_AuthorizeRemoteTxRequests,
  770. GetConfiguration_BlinkRepeat,
  771. GetConfiguration_ClockAlignedDataInterval,
  772. GetConfiguration_ConnectionTimeOut,
  773. GetConfiguration_GetConfigurationMaxKeys,
  774. GetConfiguration_HeartbeatInterval,
  775. GetConfiguration_LightIntensity,
  776. GetConfiguration_LocalAuthorizeOffline,
  777. GetConfiguration_LocalPreAuthorize,
  778. GetConfiguration_MaxEnergyOnInvalidId,
  779. GetConfiguration_MeterValuesAlignedData,
  780. GetConfiguration_MeterValuesAlignedDataMaxLength,
  781. GetConfiguration_MeterValuesSampledData,
  782. GetConfiguration_MeterValuesSampledDataMaxLength,
  783. GetConfiguration_MeterValueSampleInterval,
  784. GetConfiguration_MinimumStatusDuration,
  785. GetConfiguration_NumberOfConnectors,
  786. GetConfiguration_ResetRetries,
  787. GetConfiguration_ConnectorPhaseRotation,
  788. GetConfiguration_ConnectorPhaseRotationMaxLength,
  789. GetConfiguration_StopTransactionOnEVSideDisconnect,
  790. GetConfiguration_StopTransactionOnInvalidId,
  791. GetConfiguration_StopTxnAlignedData,
  792. GetConfiguration_StopTxnAlignedDataMaxLength,
  793. GetConfiguration_StopTxnSampledData,
  794. GetConfiguration_StopTxnSampledDataMaxLength,
  795. GetConfiguration_SupportedFeatureProfiles,
  796. GetConfiguration_SupportedFeatureProfilesMaxLength,
  797. GetConfiguration_TransactionMessageAttempts,
  798. GetConfiguration_TransactionMessageRetryInterval,
  799. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  800. GetConfiguration_WebSocketPingInterval,
  801. GetConfiguration_LocalAuthListEnabled,
  802. GetConfiguration_LocalAuthListMaxLength,
  803. GetConfiguration_SendLocalListMaxLength,
  804. GetConfiguration_ReserveConnectorZeroSupported,
  805. GetConfiguration_ChargeProfileMaxStackLevel,
  806. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  807. GetConfiguration_ChargingScheduleMaxPeriods,
  808. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  809. GetConfiguration_MaxChargingProfilesInstalled,
  810. };
  811. //GetConfiguration Array
  812. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  813. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  814. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  815. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  816. //==========================================
  817. // Init all share memory
  818. //==========================================
  819. int InitShareMemory()
  820. {
  821. int result = PASS;
  822. int MeterSMId;
  823. //printf("1\n");
  824. //creat ShmSysConfigAndInfo
  825. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  826. {
  827. #ifdef SystemLogMessage
  828. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  829. #endif
  830. result = FAIL;
  831. }
  832. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  833. {
  834. #ifdef SystemLogMessage
  835. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  836. #endif
  837. result = FAIL;
  838. }
  839. else
  840. {}
  841. //printf("2\n");
  842. //creat ShmStatusCodeData
  843. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  844. {
  845. #ifdef SystemLogMessage
  846. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  847. #endif
  848. result = FAIL;
  849. }
  850. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  851. {
  852. #ifdef SystemLogMessage
  853. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  854. #endif
  855. result = FAIL;
  856. }
  857. else
  858. {}
  859. //printf("3\n");
  860. //creat ShmPsuData
  861. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  862. {
  863. #ifdef SystemLogMessage
  864. DEBUG_ERROR("shmget ShmPsuData NG\n");
  865. #endif
  866. result = FAIL;
  867. }
  868. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmat ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else
  876. {}
  877. //creat ShmOCPP16Data
  878. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  879. {
  880. #ifdef SystemLogMessage
  881. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  882. #endif
  883. result = FAIL;
  884. }
  885. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else
  893. {}
  894. /****************************** For Initial Settings************************************************/
  895. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  896. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  897. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  898. {
  899. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  900. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  901. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  902. }
  903. // Charger PRE_SYS_MODE
  904. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  905. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  906. clientTime.Heartbeat=time((time_t*)NULL);
  907. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  908. {
  909. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  910. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  911. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  912. }
  913. //HeartBeatWaitTime = 10;
  914. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  915. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  916. // allocate Configuration memory address
  917. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  918. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  919. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  920. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  921. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  922. {
  923. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  924. DEBUG_INFO("DC ...\n");
  925. }
  926. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  927. {
  928. SystemInitial = AC_QUANTITY;
  929. DEBUG_INFO("AC ...\n");
  930. }
  931. //Status Setting
  932. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  933. {
  934. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  935. }
  936. for (int index = 0; index < CCS_QUANTITY; index++)
  937. {
  938. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  939. }
  940. for (int index = 0; index < GB_QUANTITY; index++)
  941. {
  942. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  943. }
  944. for (int index = 0; index < AC_QUANTITY; index++)
  945. {
  946. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  947. }
  948. //memset(unknownkey, 0, 10);
  949. return result;
  950. }
  951. int ProcessShareMemory()
  952. {
  953. if(InitShareMemory() == FAIL)
  954. {
  955. #ifdef SystemLogMessage
  956. DEBUG_ERROR("InitShareMemory NG\n");
  957. #endif
  958. if(ShmStatusCodeData!=NULL)
  959. {
  960. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  961. }
  962. sleep(5);
  963. return FAIL;
  964. }
  965. return PASS;
  966. }
  967. //---------------------------------------------
  968. // new:
  969. // enum SYSTEM_STATUS
  970. // {
  971. // SYS_MODE_BOOTING = 0,
  972. // SYS_MODE_IDLE = 1,
  973. // SYS_MODE_AUTHORIZING = 2,
  974. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  975. // SYS_MODE_REASSIGN = 4,
  976. // SYS_MODE_PREPARING = 5,
  977. // SYS_MODE_PREPARE_FOR_EV = 6,
  978. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  979. // SYS_MODE_CHARGING = 8,
  980. // SYS_MODE_TERMINATING = 9,
  981. // SYS_MODE_COMPLETE = 10,
  982. // SYS_MODE_ALARM = 11,
  983. // SYS_MODE_FAULT = 12,
  984. // SYS_MODE_RESERVATION = 13,
  985. // SYS_MODE_BOOKING = 14,
  986. // SYS_MODE_MAINTAIN = 15,
  987. // SYS_MODE_DEBUG = 16,
  988. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  989. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  990. // SYS_MODE_UPDATE = 19
  991. // };
  992. //
  993. //
  994. //-----------------------------------------
  995. void CheckSystemValue(void)
  996. {
  997. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  998. int IdleModeCnt = 0;
  999. char filenmae[100]={0};
  1000. char str[100]={0};
  1001. //===============================
  1002. // send Heartbeat
  1003. //===============================
  1004. //printf("server_sign=%d\n",server_sign);
  1005. //printf("HeartBeatWaitTime=%d\n",HeartBeatWaitTime);
  1006. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1007. {
  1008. printf("Heartbeat !!!\n");
  1009. //parameter for test
  1010. sendHeartbeatRequest(0);
  1011. //==============================================
  1012. // Reset Waiting Time
  1013. //==============================================
  1014. clientTime.Heartbeat=time((time_t*)NULL);
  1015. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1016. }
  1017. //==============================================
  1018. // Update firmware request
  1019. //==============================================
  1020. if(isUpdateRequest == TRUE )
  1021. {
  1022. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1023. {
  1024. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1025. {
  1026. //check SystemStatus
  1027. /*************************DC*******************************/
  1028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1029. {
  1030. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1031. {
  1032. IdleModeCnt = IdleModeCnt + 1;
  1033. }
  1034. }
  1035. for (int index = 0; index < CCS_QUANTITY; index++)
  1036. {
  1037. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1038. {
  1039. IdleModeCnt = IdleModeCnt + 1;
  1040. }
  1041. }
  1042. for (int index = 0; index < GB_QUANTITY; index++)
  1043. {
  1044. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1045. {
  1046. IdleModeCnt = IdleModeCnt + 1;
  1047. }
  1048. }
  1049. }
  1050. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1051. {
  1052. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1053. isUpdateRequest = FALSE;
  1054. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1055. }
  1056. }
  1057. else
  1058. {
  1059. /*************************AC*******************************/
  1060. for (int index = 0; index < AC_QUANTITY; index++)
  1061. {
  1062. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1063. {
  1064. IdleModeCnt = IdleModeCnt + 1;
  1065. }
  1066. }
  1067. if(IdleModeCnt == AC_QUANTITY)
  1068. {
  1069. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1070. isUpdateRequest = FALSE;
  1071. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1072. }
  1073. }
  1074. }
  1075. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1076. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1077. {
  1078. //===============================
  1079. // CSU Trigger Reset Conf
  1080. //===============================
  1081. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1082. {
  1083. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1084. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1085. {
  1086. server_sign = FALSE;
  1087. }
  1088. }
  1089. //===============================
  1090. // CSU Trigger Authorize Request
  1091. //===============================
  1092. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1093. {
  1094. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1095. {
  1096. sendAuthorizeRequest(0);
  1097. authorizeRetryTimes = authorizeRetryTimes + 1;
  1098. // authenrequest = TRUE
  1099. if(authorizeRetryTimes < 3)
  1100. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1101. }
  1102. }
  1103. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1104. {
  1105. authorizeRetryTimes = 0;
  1106. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1107. server_sign = FALSE;
  1108. }
  1109. //===============================
  1110. // CSU Trigger Smart Charging Profilw
  1111. //===============================
  1112. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1113. {
  1114. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1115. GetChargingProfileRequest(gun_index);
  1116. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1117. }
  1118. //==============================================
  1119. // Charger start transaction
  1120. //==============================================
  1121. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1122. {
  1123. sendStartTransactionRequest(gun_index);
  1124. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1125. clientTime.StartTransaction = time((time_t*)NULL);
  1126. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1127. }
  1128. //==============================================
  1129. // Charger stop transaction
  1130. //==============================================
  1131. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1132. {
  1133. sendStopTransactionRequest(gun_index);
  1134. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1135. clientTime.StopTransaction = time((time_t*)NULL);
  1136. }
  1137. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1138. //==============================================
  1139. // Charger status report
  1140. //==============================================
  1141. /* Check Mode Change */
  1142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1143. {
  1144. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1145. {
  1146. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1147. {
  1148. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1149. {
  1150. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1151. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1152. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1153. statusModeChage[gun_index] = TRUE;
  1154. }
  1155. }
  1156. }
  1157. for (int index = 0; index < CCS_QUANTITY; index++)
  1158. {
  1159. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1160. {
  1161. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1162. {
  1163. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1164. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1165. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1166. statusModeChage[gun_index] = TRUE;
  1167. }
  1168. }
  1169. }
  1170. for (int index = 0; index < GB_QUANTITY; index++)
  1171. {
  1172. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1173. {
  1174. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1175. {
  1176. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1177. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1178. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1179. statusModeChage[gun_index] = TRUE;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. else //AC
  1185. {
  1186. for (int index = 0; index < AC_QUANTITY; index++)
  1187. {
  1188. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1189. {
  1190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1191. {
  1192. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1193. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1194. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1195. statusModeChage[gun_index] = TRUE;
  1196. }
  1197. }
  1198. }// END OF FOR
  1199. }// END OF ELSE
  1200. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1201. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1202. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1203. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1204. {
  1205. if(SystemInitial != 0)
  1206. SystemInitial = SystemInitial -1;
  1207. //GunStatusInterval= GunStatusInterval* gun_index;
  1208. sendStatusNotificationRequest(gun_index);
  1209. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1210. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1211. statusModeChage[gun_index] = FALSE;
  1212. //sleep(30); // sleep for 30 seconds
  1213. }
  1214. //==============================================
  1215. // Meter report
  1216. //==============================================
  1217. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1218. {
  1219. //check Transaction active
  1220. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1221. {
  1222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1223. {
  1224. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1225. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1226. {
  1227. meterValueSend[gun_index] =1;
  1228. }
  1229. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1230. {
  1231. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1232. if((access(filenmae,F_OK))!=-1)
  1233. {
  1234. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1235. sprintf(str,"rm -f %s",filenmae);
  1236. system(str);
  1237. }
  1238. }
  1239. }// End for CHAdeMO
  1240. for (int index = 0; index < CCS_QUANTITY; index++)
  1241. {
  1242. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1243. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1244. {
  1245. meterValueSend[gun_index] =1;
  1246. }
  1247. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1248. {
  1249. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1250. if((access(filenmae,F_OK))!=-1)
  1251. {
  1252. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1253. sprintf(str,"rm -f %s",filenmae);
  1254. system(str);
  1255. }
  1256. }
  1257. } // End for CCS
  1258. for (int index = 0; index < GB_QUANTITY; index++)
  1259. {
  1260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1262. {
  1263. meterValueSend[gun_index] =1;
  1264. }
  1265. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1266. {
  1267. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1268. if((access(filenmae,F_OK))!=-1)
  1269. {
  1270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1271. sprintf(str,"rm -f %s",filenmae);
  1272. system(str);
  1273. }
  1274. }
  1275. }// End for GB
  1276. }
  1277. else
  1278. {
  1279. for (int index = 0; index < AC_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }//End for AC
  1297. }//END OF ELSE
  1298. // sleep(1);
  1299. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1300. if(meterValueSend[gun_index] == 1)
  1301. sendMeterValuesRequest(gun_index);
  1302. }
  1303. //==============================================
  1304. // Check Connector reserved
  1305. //==============================================
  1306. //===============================
  1307. // Check if Reserve is expired
  1308. //===============================
  1309. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1310. {
  1311. double diff_t;
  1312. struct tm tp;
  1313. // current time
  1314. time_t t = time(NULL);
  1315. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1316. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1317. tp.tm_isdst = -1;
  1318. time_t utc = mktime(&tp);
  1319. diff_t = difftime(utc, t);
  1320. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1321. if(diff_t <= 0)
  1322. {
  1323. DEBUG_INFO("reserve expired !!! \n");
  1324. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1325. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1326. }
  1327. }//END OF Check if Reserve is expired
  1328. //==========================================
  1329. // csu trigger FirmwareStatusNotificationReq
  1330. //==========================================
  1331. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1332. {
  1333. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1334. }
  1335. //==========================================
  1336. // csu trigger CancelReservationConf
  1337. //==========================================
  1338. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1339. {
  1340. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1341. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1342. }
  1343. //==========================================
  1344. // csu trigger ChangeAvailabilityConf
  1345. //==========================================
  1346. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1347. {
  1348. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1349. }
  1350. //==========================================
  1351. // csu trigger UnlockConnectorConf
  1352. //==========================================
  1353. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1354. {
  1355. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger ReserveNowConf
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1362. {
  1363. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1365. }
  1366. //==========================================
  1367. // csu trigger DataTransferReq
  1368. //==========================================
  1369. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1370. {
  1371. sendDataTransferRequest(gun_index);
  1372. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1373. }
  1374. }
  1375. }
  1376. //==========================================
  1377. // send request routine
  1378. //==========================================
  1379. int sendAuthorizeRequest(int gun_index)
  1380. {
  1381. mtrace();
  1382. int result = FAIL;
  1383. char message[100]={0};
  1384. char guid[37];
  1385. char tempdata[65]={0};
  1386. DEBUG_INFO("sendAuthorizeRequest \n");
  1387. //Local Authorize
  1388. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1389. {
  1390. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1391. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1392. {
  1393. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1395. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1396. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1397. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1398. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1399. authorizeRetryTimes = 0;
  1400. return result;
  1401. }
  1402. else
  1403. {
  1404. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1405. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1406. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1407. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1408. result = PASS;
  1409. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1410. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1411. authorizeRetryTimes = 0;
  1412. return result;
  1413. }
  1414. }
  1415. //initailize struct Authorize
  1416. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1417. //get data from shared memory
  1418. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1419. random_uuid(guid);
  1420. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1421. LWS_Send(message);
  1422. sprintf(tempdata, "Authorize,%d", gun_index);
  1423. if(hashmap_operation(0, guid, tempdata) == 1)
  1424. {
  1425. result = PASS;
  1426. DEBUG_ERROR("Authorize mapItem pass\n");
  1427. }
  1428. //#ifdef SystemLogMessage
  1429. //DEBUG_INFO(">>>>>Authorize request\n");
  1430. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1431. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1432. //#endif
  1433. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1434. return result;
  1435. }
  1436. int sendBootNotificationRequest(void)
  1437. {
  1438. mtrace();
  1439. int result = FAIL;
  1440. char message[500]={0}, payload[700]={0};
  1441. char guid[37]={0};
  1442. char tempdata[65]={0};
  1443. int IsGunCharging = FALSE;
  1444. //check Transaction active
  1445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1446. {
  1447. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1448. {
  1449. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1450. {
  1451. IsGunCharging = TRUE;
  1452. }
  1453. }
  1454. for (int index = 0; index < CCS_QUANTITY; index++)
  1455. {
  1456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1457. {
  1458. IsGunCharging = TRUE;
  1459. }
  1460. }
  1461. for (int index = 0; index < GB_QUANTITY; index++)
  1462. {
  1463. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1464. {
  1465. IsGunCharging = TRUE;
  1466. }
  1467. }
  1468. }
  1469. else
  1470. {
  1471. for (int index = 0; index < AC_QUANTITY; index++)
  1472. {
  1473. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1474. {
  1475. IsGunCharging = TRUE;
  1476. }
  1477. }
  1478. }
  1479. if(IsGunCharging == TRUE)
  1480. {
  1481. server_sign = TRUE;
  1482. return result;
  1483. }
  1484. // Fill BootNotification fields
  1485. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1486. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1487. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1488. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1489. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1490. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1491. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1492. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1493. ShmOCPP16Data->ChargeBoxId
  1494. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1495. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1496. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1497. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1498. ,ShmOCPP16Data->BootNotification.CpIccid
  1499. ,ShmOCPP16Data->BootNotification.CpImsi
  1500. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1501. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1502. random_uuid(guid);
  1503. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1504. LWS_Send(message);
  1505. sprintf(tempdata, "BootNotification,0");
  1506. 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*/)
  1507. {
  1508. result = PASS;
  1509. }
  1510. memset(queuedata, 0, sizeof(queuedata));
  1511. strcpy(queuedata,message);
  1512. HeartBeatCount = 0;
  1513. //#ifdef SystemLogMessage
  1514. //DEBUG_INFO(">>>>>BootNotification request\n");
  1515. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1516. //#endif
  1517. return result;
  1518. }
  1519. int sendDataTransferRequest(int gun_index)
  1520. {
  1521. mtrace();
  1522. char message[1000]={0};
  1523. char guid[37]={0};
  1524. char tempdata[65]={0};
  1525. int result = FAIL;
  1526. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1527. random_uuid(guid);
  1528. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1529. MESSAGE_TYPE_CALL,
  1530. guid,
  1531. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1532. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1533. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1534. LWS_Send(message);
  1535. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1536. 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*/)
  1537. {
  1538. result = PASS;
  1539. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1540. }
  1541. //#ifdef SystemLogMessage
  1542. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1543. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1544. //#endif
  1545. return result;
  1546. }
  1547. int sendDiagnosticsStatusNotificationRequest(char *status)
  1548. {
  1549. mtrace();
  1550. int result = FAIL;
  1551. char message[110]={0};
  1552. char guid[37]={0};
  1553. char tempdata[65]={0};
  1554. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1555. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1556. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1557. random_uuid(guid);
  1558. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1559. LWS_Send(message);
  1560. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1561. if(hashmap_operation(0, guid, tempdata) == 1)
  1562. {
  1563. result = PASS;
  1564. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1565. }
  1566. //#ifdef SystemLogMessage
  1567. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1568. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1569. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1570. //#endif
  1571. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1572. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1573. //record status
  1574. if(strcmp(status,"Idle")==0)
  1575. {
  1576. DiagnosticsStatusNotificationStatus = 0;
  1577. }
  1578. else if(strcmp(status,"Uploaded")==0)
  1579. {
  1580. DiagnosticsStatusNotificationStatus = 1;
  1581. }
  1582. else if(strcmp(status,"UploadFailed")==0)
  1583. {
  1584. DiagnosticsStatusNotificationStatus = 2;
  1585. }
  1586. else if(strcmp(status,"Uploading")==0)
  1587. {
  1588. DiagnosticsStatusNotificationStatus = 3;
  1589. }
  1590. return result;
  1591. }
  1592. int sendFirmwareStatusNotificationRequest(char *status)
  1593. {
  1594. mtrace();
  1595. int result = FAIL;
  1596. char message[110]={0};
  1597. char guid[37]={0};
  1598. char tempdata[65]={0};
  1599. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1600. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1601. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1602. random_uuid(guid);
  1603. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1604. LWS_Send(message);
  1605. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1606. 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*/)
  1607. {
  1608. result = PASS;
  1609. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1610. }
  1611. //#ifdef SystemLogMessage
  1612. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1613. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1614. //#endif
  1615. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1616. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1617. //record status
  1618. if(strcmp(status,"Downloaded")==0)
  1619. {
  1620. FirmwareStatusNotificationStatus = 0;
  1621. }
  1622. else if(strcmp(status,"DownloadFailed")==0)
  1623. {
  1624. FirmwareStatusNotificationStatus = 1;
  1625. }
  1626. else if(strcmp(status,"Downloading")==0)
  1627. {
  1628. FirmwareStatusNotificationStatus = 2;
  1629. }
  1630. else if(strcmp(status,"Idle")==0)
  1631. {
  1632. FirmwareStatusNotificationStatus = 3;
  1633. }
  1634. else if(strcmp(status,"InstallationFailed")==0)
  1635. {
  1636. FirmwareStatusNotificationStatus = 4;
  1637. }
  1638. else if(strcmp(status,"Installing")==0)
  1639. {
  1640. FirmwareStatusNotificationStatus = 5;
  1641. }
  1642. else if(strcmp(status,"Installed")==0)
  1643. {
  1644. FirmwareStatusNotificationStatus = 6;
  1645. }
  1646. return result;
  1647. }
  1648. int sendHeartbeatRequest(int gun_index)
  1649. {
  1650. mtrace();
  1651. int result = FAIL;
  1652. char message[80]={0};
  1653. char guid[37]={0};
  1654. char tempdata[65]={0};
  1655. random_uuid(guid);
  1656. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1657. , MESSAGE_TYPE_CALL
  1658. , guid );
  1659. LWS_Send(message);
  1660. sprintf(tempdata, "Heartbeat,%d", 0);
  1661. 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*/)
  1662. {
  1663. result = PASS;
  1664. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1665. }
  1666. return result;
  1667. }
  1668. int sendStartTransactionRequest(int gun_index)
  1669. {
  1670. mtrace();
  1671. int result = FAIL;
  1672. char message[250]={0};
  1673. char guid[37]={0};
  1674. struct timeval tmnow;
  1675. struct tm *tm;
  1676. char buf[28];//, usec_buf[6];
  1677. char tempdata[65]={0};
  1678. DEBUG_INFO("sendStartTransactionRequest...");
  1679. gettimeofday(&tmnow, NULL);
  1680. time_t t;
  1681. t = time(NULL);
  1682. /*UTC time and date*/
  1683. tm = gmtime(&t);
  1684. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1685. #if 0 // remove temporally
  1686. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1687. strcat(buf,".");
  1688. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1689. strcat(buf,usec_buf);
  1690. #endif
  1691. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1692. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1693. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1694. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1695. {
  1696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1697. {
  1698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1699. {
  1700. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1701. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1702. }
  1703. }
  1704. for (int index = 0; index < CCS_QUANTITY; index++)
  1705. {
  1706. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1707. {
  1708. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1709. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1710. }
  1711. }
  1712. for (int index = 0; index < GB_QUANTITY; index++)
  1713. {
  1714. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1715. {
  1716. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1717. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1718. }
  1719. }
  1720. }
  1721. else
  1722. {
  1723. for (int index = 0; index < AC_QUANTITY; index++)
  1724. {
  1725. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1726. {
  1727. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1728. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1729. }
  1730. }
  1731. }//END OF ELSE
  1732. random_uuid(guid);
  1733. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1734. , MESSAGE_TYPE_CALL
  1735. , guid
  1736. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1737. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1738. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1739. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1740. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1741. LWS_Send(message);
  1742. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1743. 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*/)
  1744. {
  1745. result = PASS;
  1746. }
  1747. strcpy(queuedata, message);
  1748. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1749. //#ifdef SystemLogMessage
  1750. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1751. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1752. //#endif
  1753. return result;
  1754. }
  1755. int sendStatusNotificationRequest(int gun_index)
  1756. {
  1757. mtrace();
  1758. int result = FAIL;
  1759. char message[600]={0};
  1760. char guid[37];
  1761. int currentStatus = 0;
  1762. struct timeval tmnow;
  1763. struct tm *tm;
  1764. char buf[28];//, usec_buf[6];
  1765. char tempdata[65]={0};
  1766. gettimeofday(&tmnow, NULL);
  1767. time_t t;
  1768. t = time(NULL);
  1769. /*UTC time and date*/
  1770. tm = gmtime(&t);
  1771. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1772. #if 0 // remove temporally
  1773. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1774. strcat(buf,".");
  1775. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1776. strcat(buf,usec_buf);
  1777. #endif
  1778. printf("%s",buf);
  1779. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1780. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1781. // it's option
  1782. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1783. /*
  1784. enum _SYSTEM_STATUS
  1785. {
  1786. S_BOOTING = 0,
  1787. S_IDLE, = 1
  1788. S_AUTHORIZING, =2
  1789. S_REASSIGN_CHECK, =3
  1790. S_REASSIGN, =4
  1791. S_PRECHARGE, =5
  1792. S_PREPARING_FOR_EV, =6
  1793. S_PREPARING_FOR_EVSE, =7
  1794. S_CHARGING, =8
  1795. S_TERMINATING, =9
  1796. S_COMPLETE, =10
  1797. S_ALARM, =11
  1798. S_FAULT =12
  1799. }
  1800. */
  1801. //check Transaction active
  1802. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1803. {
  1804. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1805. {
  1806. //printf("gun_index=%d\n",gun_index);
  1807. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1808. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1809. {
  1810. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1811. currentStatus = 0; //OCPP Status
  1812. }
  1813. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1814. {
  1815. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1816. currentStatus = 1; //OCPP Status
  1817. }
  1818. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1819. {
  1820. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1821. currentStatus = 2; //OCPP Status
  1822. }
  1823. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1824. {
  1825. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1826. currentStatus = 5; //OCPP Status
  1827. }
  1828. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1829. {
  1830. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1831. currentStatus = 4; //OCPP Status
  1832. }
  1833. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1834. {
  1835. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1836. currentStatus = 7; //OCPP Status: Unavailable
  1837. }
  1838. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1839. {
  1840. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1841. currentStatus = 8; //OCPP Status: Faulted
  1842. }
  1843. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1844. {
  1845. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1846. currentStatus = 6; //OCPP Status: Reserved
  1847. }
  1848. }//end of for CHAdeMO_QUANTITY
  1849. for (int index = 0; index < CCS_QUANTITY; index++)
  1850. {
  1851. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1852. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1853. {
  1854. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1855. currentStatus = 0; //OCPP Status
  1856. }
  1857. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1858. {
  1859. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1860. currentStatus = 1; //OCPP Status
  1861. }
  1862. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1863. {
  1864. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1865. currentStatus = 2; //OCPP Status
  1866. }
  1867. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1868. {
  1869. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1870. currentStatus = 5; //OCPP Status
  1871. }
  1872. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1873. {
  1874. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1875. currentStatus = 4; //OCPP Status
  1876. }
  1877. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1878. {
  1879. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[Unavailable]);
  1880. currentStatus = 7; //OCPP Status : Unavailable
  1881. }
  1882. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1883. {
  1884. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1885. currentStatus = 8; //OCPP Status
  1886. }
  1887. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1888. {
  1889. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1890. currentStatus = 6; //OCPP Status
  1891. }
  1892. }
  1893. for (int index = 0; index < GB_QUANTITY; index++)
  1894. {
  1895. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1896. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1897. {
  1898. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1899. currentStatus = 0; //OCPP Status
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1902. {
  1903. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1904. currentStatus = 1; //OCPP Status
  1905. }
  1906. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1907. {
  1908. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1909. currentStatus = 2; //OCPP Status
  1910. }
  1911. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1912. {
  1913. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1914. currentStatus = 5; //OCPP Status
  1915. }
  1916. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1917. {
  1918. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1919. currentStatus = 4; //OCPP Status
  1920. }
  1921. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))) //S_TERMINATING ---> Unavailable
  1922. {
  1923. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1924. currentStatus = 7; //OCPP Status: Unavailable
  1925. }
  1926. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1927. {
  1928. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1929. currentStatus = 8; //OCPP Status: Faulted
  1930. }
  1931. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1932. {
  1933. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1934. currentStatus = 6; //OCPP Status: Faulted
  1935. }
  1936. }
  1937. }
  1938. else
  1939. {
  1940. for (int index = 0; index < AC_QUANTITY; index++)
  1941. {
  1942. //printf("gun_index=%d\n",gun_index);
  1943. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1944. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1945. {
  1946. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1947. currentStatus = 0; //OCPP Status
  1948. }
  1949. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1950. {
  1951. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1952. currentStatus = 1; //OCPP Status
  1953. }
  1954. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1955. {
  1956. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1957. currentStatus = 2; //OCPP Status
  1958. }
  1959. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1960. {
  1961. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1962. currentStatus = 5; //OCPP Status
  1963. }
  1964. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1965. {
  1966. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1967. currentStatus = 4; //OCPP Status
  1968. }
  1969. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) )) //S_TERMINATING ---> Unavailable
  1970. {
  1971. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1972. currentStatus = 7; //OCPP Status: Unavailable
  1973. }
  1974. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1975. {
  1976. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1977. currentStatus = 8; //OCPP Status: Faulted
  1978. }
  1979. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1980. {
  1981. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1982. currentStatus = 6; //OCPP Status: Reserved
  1983. }
  1984. }//end of for AC_QUANTITY
  1985. }//END OF ELSE
  1986. //it's option
  1987. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1988. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1989. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  1990. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1991. random_uuid(guid);
  1992. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1993. , MESSAGE_TYPE_CALL
  1994. , guid
  1995. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1996. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1997. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1998. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1999. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2000. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2001. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2002. LWS_Send(message);
  2003. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2004. 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*/)
  2005. {
  2006. //DEBUG_ERROR("statusNotification mapitem pass");
  2007. result = PASS;
  2008. }
  2009. //#ifdef SystemLogMessage
  2010. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2011. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2012. //#endif
  2013. return result;
  2014. }
  2015. int sendStopTransactionRequest(int gun_index)
  2016. {
  2017. mtrace();
  2018. int result = FAIL;
  2019. //char message[1500]={0};
  2020. char guid[37]={0};
  2021. char tempdata[65]={0};
  2022. //int idx_sample=0;
  2023. DEBUG_ERROR("sendStopTransactionRequest \n");
  2024. memset(queuedata, 0, sizeof(queuedata));
  2025. //ENERGY_ACTIVE_IMPORT_REGISTER
  2026. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2027. {
  2028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2029. {
  2030. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2031. {
  2032. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2033. //Check Status
  2034. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2035. {
  2036. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2037. }
  2038. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2039. }
  2040. }// END OF CHAdeMO_QUANTITY
  2041. for (int index = 0; index < CCS_QUANTITY; index++)
  2042. {
  2043. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2044. {
  2045. //for test
  2046. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2047. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2048. //Check Status
  2049. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2050. {
  2051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2052. }
  2053. else
  2054. {
  2055. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2056. }
  2057. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2058. }
  2059. }// END OF CCS_QUANTITY
  2060. for (int index = 0; index < GB_QUANTITY; index++)
  2061. {
  2062. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2063. {
  2064. // for test
  2065. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2066. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2067. //Check Status
  2068. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2069. {
  2070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2071. }
  2072. else
  2073. {
  2074. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2075. }
  2076. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2077. }
  2078. }// END OF GB_QUANTITY
  2079. }
  2080. else
  2081. {
  2082. for (int index = 0; index < AC_QUANTITY; index++)
  2083. {
  2084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2085. {
  2086. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2087. //Check Status
  2088. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2089. {
  2090. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2091. }
  2092. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2093. }
  2094. }// END OF AC_QUANTITY
  2095. }//END OF ELSE
  2096. //Stop Transaction Time
  2097. struct timeval tmnow;
  2098. struct tm *tm;
  2099. char buf[28];//, usec_buf[6];
  2100. gettimeofday(&tmnow, NULL);
  2101. time_t t;
  2102. t = time(NULL);
  2103. /*UTC time and date*/
  2104. tm = gmtime(&t);
  2105. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2106. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2107. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2108. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2109. random_uuid(guid);
  2110. /***********************************transactionData******************************************************/
  2111. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2112. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2113. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2114. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2115. //=================================
  2116. // Transaction_Begin
  2117. //=================================
  2118. // Energy.Active.Export.Interval
  2119. //idx_sample=0;
  2120. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)*1000); // MeterStart is 0~6553.5 kWh
  2121. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2122. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2123. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Export_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2124. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2125. {
  2126. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2127. }
  2128. else
  2129. {
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2131. }
  2132. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2133. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2134. //=================================
  2135. // Transaction_End
  2136. //=================================
  2137. //Current.Export
  2138. //idx_sample=1;
  2139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2140. {
  2141. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2142. {
  2143. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2144. {
  2145. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2146. }
  2147. }
  2148. for (int index = 0; index < CCS_QUANTITY; index++)
  2149. {
  2150. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2151. {
  2152. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2153. }
  2154. }
  2155. for (int index = 0; index < GB_QUANTITY; index++)
  2156. {
  2157. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2158. {
  2159. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2160. }
  2161. }
  2162. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2163. }
  2164. else
  2165. {
  2166. for (int index = 0; index < AC_QUANTITY; index++)
  2167. {
  2168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2169. {
  2170. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2171. }
  2172. }
  2173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2174. }// END FOR AC ELSE
  2175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2178. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2179. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2181. //Energy.Active.Export.Interval
  2182. //idx_sample=2;
  2183. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2184. {
  2185. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2186. {
  2187. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2188. {
  2189. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2190. }
  2191. }
  2192. for (int index = 0; index < CCS_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2195. {
  2196. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2197. }
  2198. }
  2199. for (int index = 0; index < GB_QUANTITY; index++)
  2200. {
  2201. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2202. {
  2203. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2204. }
  2205. }
  2206. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2207. }
  2208. else
  2209. {
  2210. for (int index = 0; index < AC_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2213. {
  2214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2215. }
  2216. }
  2217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2218. }// END FOR AC ELSE
  2219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2222. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2223. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2224. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2225. //Power.Active.Export
  2226. //idx_sample=3;
  2227. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2228. {
  2229. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2230. {
  2231. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2232. {
  2233. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2234. }
  2235. }
  2236. for (int index = 0; index < CCS_QUANTITY; index++)
  2237. {
  2238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2239. {
  2240. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2241. }
  2242. }
  2243. for (int index = 0; index < GB_QUANTITY; index++)
  2244. {
  2245. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2246. {
  2247. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2248. }
  2249. }
  2250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2251. }
  2252. else
  2253. {
  2254. for (int index = 0; index < AC_QUANTITY; index++)
  2255. {
  2256. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2257. {
  2258. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2259. }
  2260. }
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2262. }// END FOR AC ELSE
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2266. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2268. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2269. //Voltage
  2270. //idx_sample=4;
  2271. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2272. {
  2273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2274. {
  2275. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2276. {
  2277. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2278. }
  2279. }
  2280. for (int index = 0; index < CCS_QUANTITY; index++)
  2281. {
  2282. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2283. {
  2284. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2285. }
  2286. }
  2287. for (int index = 0; index < GB_QUANTITY; index++)
  2288. {
  2289. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2290. {
  2291. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2292. }
  2293. }
  2294. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2295. }
  2296. else
  2297. {
  2298. for (int index = 0; index < AC_QUANTITY; index++)
  2299. {
  2300. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2301. {
  2302. 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
  2303. }
  2304. }
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2306. }// END FOR AC ELSE
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2308. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2310. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2313. //SoC
  2314. //idx_sample=5;
  2315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2316. {
  2317. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2318. {
  2319. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2320. {
  2321. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2322. }
  2323. }
  2324. for (int index = 0; index < CCS_QUANTITY; index++)
  2325. {
  2326. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2327. {
  2328. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2329. }
  2330. }
  2331. for (int index = 0; index < GB_QUANTITY; index++)
  2332. {
  2333. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2334. {
  2335. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2336. }
  2337. }
  2338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2342. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2343. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2344. } // END FOR DC CASE
  2345. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2346. {
  2347. 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\" } ] } ] } ]"
  2348. ,MESSAGE_TYPE_CALL
  2349. ,guid
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2353. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2355. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2398. );
  2399. }
  2400. else
  2401. {
  2402. 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\" } ] } ] } ]"
  2403. ,MESSAGE_TYPE_CALL
  2404. ,guid
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2410. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2444. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2446. );
  2447. }
  2448. LWS_Send(queuedata);
  2449. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2450. if(hashmap_operation(0, guid, tempdata) == 1)
  2451. {
  2452. result = PASS;
  2453. DEBUG_INFO("StopTransaction mapitem pass\n");
  2454. }
  2455. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2456. //for test
  2457. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2458. return result;
  2459. }
  2460. int sendMeterValuesRequest(int gun_index)
  2461. {
  2462. mtrace();
  2463. int result = FAIL;
  2464. // char message[1500]={0};
  2465. char guid[37]={0};
  2466. //int idx_sample=0;
  2467. //int length = 0;
  2468. char tempdata[65]={0};
  2469. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2470. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2471. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2472. {
  2473. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2474. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2475. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2476. return result;
  2477. }
  2478. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2479. {
  2480. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2481. }
  2482. memset(queuedata, 0, sizeof(queuedata));
  2483. //set value
  2484. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2485. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2486. random_uuid(guid);
  2487. //UTC Date time
  2488. struct timeval tmnow;
  2489. struct tm *tm;
  2490. char buf[28];//, usec_buf[6];
  2491. gettimeofday(&tmnow, NULL);
  2492. time_t t;
  2493. t = time(NULL);
  2494. /*UTC time and date*/
  2495. tm = gmtime(&t);
  2496. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2497. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2498. //idx_sample=0;
  2499. //********************************(1)Current.Export************************************************/
  2500. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2501. {
  2502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2503. {
  2504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2505. {
  2506. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2507. }
  2508. }
  2509. for (int index = 0; index < CCS_QUANTITY; index++)
  2510. {
  2511. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2512. {
  2513. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2514. }
  2515. }
  2516. for (int index = 0; index < GB_QUANTITY; index++)
  2517. {
  2518. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2519. {
  2520. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2521. }
  2522. }
  2523. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2524. }
  2525. else
  2526. {
  2527. for (int index = 0; index < AC_QUANTITY; index++)
  2528. {
  2529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2530. {
  2531. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2532. }
  2533. }
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2535. }// END FOR AC ELSE
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2537. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2539. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2540. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2542. //idx_sample=1;
  2543. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2544. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2545. {
  2546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2547. {
  2548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2549. {
  2550. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2551. }
  2552. }
  2553. for (int index = 0; index < CCS_QUANTITY; index++)
  2554. {
  2555. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2556. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2557. {
  2558. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2560. }
  2561. }
  2562. for (int index = 0; index < GB_QUANTITY; index++)
  2563. {
  2564. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2565. {
  2566. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2567. }
  2568. }
  2569. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2570. }
  2571. else
  2572. {
  2573. for (int index = 0; index < AC_QUANTITY; index++)
  2574. {
  2575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2576. {
  2577. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2578. }
  2579. }
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2581. }//END FOR AC ELSE
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2583. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2585. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2586. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2588. //idx_sample=2;
  2589. //********************************(4)Power.Active.Export************************************************/
  2590. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2591. {
  2592. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2593. {
  2594. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2595. {
  2596. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2597. }
  2598. }
  2599. for (int index = 0; index < CCS_QUANTITY; index++)
  2600. {
  2601. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2602. {
  2603. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2604. }
  2605. }
  2606. for (int index = 0; index < GB_QUANTITY; index++)
  2607. {
  2608. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2609. {
  2610. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2611. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2612. }
  2613. }
  2614. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2615. }
  2616. else
  2617. {
  2618. for (int index = 0; index < AC_QUANTITY; index++)
  2619. {
  2620. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2621. {
  2622. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2623. }
  2624. }
  2625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2626. }// END FOR AC ELSE
  2627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2630. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2631. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2632. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2633. //idx_sample=3;
  2634. //***********************************************(5)VOLTAGE******************************************************/
  2635. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2636. {
  2637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2638. {
  2639. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2640. {
  2641. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2642. }
  2643. }
  2644. for (int index = 0; index < CCS_QUANTITY; index++)
  2645. {
  2646. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2647. {
  2648. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2649. }
  2650. }
  2651. for (int index = 0; index < GB_QUANTITY; index++)
  2652. {
  2653. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2654. {
  2655. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2656. }
  2657. }
  2658. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2659. }
  2660. else
  2661. {
  2662. for (int index = 0; index < AC_QUANTITY; index++)
  2663. {
  2664. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2665. {
  2666. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2667. }
  2668. }
  2669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2670. }//END FOR AC ELSE
  2671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2672. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2674. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2675. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2676. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2677. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2678. {
  2679. //idx_sample=4;
  2680. //sampledValue = NULL;
  2681. //***********************************************(6)SOC******************************************************/
  2682. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2683. {
  2684. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2685. {
  2686. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2687. }
  2688. }
  2689. for (int index = 0; index < CCS_QUANTITY; index++)
  2690. {
  2691. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2692. {
  2693. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2694. }
  2695. }
  2696. for (int index = 0; index < GB_QUANTITY; index++)
  2697. {
  2698. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2699. {
  2700. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2701. }
  2702. }
  2703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2707. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2708. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2709. }
  2710. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2711. {
  2712. 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\"}]}]}]"
  2713. ,MESSAGE_TYPE_CALL
  2714. ,guid
  2715. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2716. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2717. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2753. );
  2754. }
  2755. else
  2756. {
  2757. 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\"}]}]}]"
  2758. ,MESSAGE_TYPE_CALL
  2759. ,guid
  2760. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2761. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2762. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2791. );
  2792. }
  2793. LWS_Send(queuedata);
  2794. // Put request guid to hash map
  2795. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2796. 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*/)
  2797. {
  2798. result = PASS;
  2799. DEBUG_INFO("MeterValues mapitem pass\n");
  2800. }
  2801. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2802. return result;
  2803. }
  2804. //==========================================
  2805. // send confirm routine
  2806. //==========================================
  2807. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2808. {
  2809. mtrace();
  2810. int result = FAIL;
  2811. char message[100]={0};
  2812. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2813. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2814. LWS_Send(message);
  2815. result = TRUE;
  2816. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2817. return result;
  2818. }
  2819. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2820. {
  2821. mtrace();
  2822. int result = FAIL;
  2823. char message[100]={0};
  2824. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2825. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2826. LWS_Send(message);
  2827. result = TRUE;
  2828. return result;
  2829. }
  2830. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2831. {
  2832. mtrace();
  2833. int result = FAIL;
  2834. char message[100]={0};
  2835. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2836. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2837. LWS_Send(message);
  2838. result = TRUE;
  2839. return result;
  2840. }
  2841. int sendClearCacheConfirmation(char *uuid,char *payload)
  2842. {
  2843. mtrace();
  2844. int result = FAIL;
  2845. char message[500]={0};
  2846. // int count = 0;
  2847. // int gun_index = 0;
  2848. // char guid[37];
  2849. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2850. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2851. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2852. LWS_Send(message);
  2853. return result;
  2854. }
  2855. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2856. {
  2857. mtrace();
  2858. int result = FAIL;
  2859. char message[500]={0};
  2860. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2861. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2862. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2863. LWS_Send(message);
  2864. return result;
  2865. }
  2866. int sendDataTransferConfirmation(char *uuid,char *payload)
  2867. {
  2868. mtrace();
  2869. char statusStr[20]={0};
  2870. char dataStr[10]={0};
  2871. char sstr[20]={0};
  2872. int c = 0;
  2873. char *loc;
  2874. int result = FAIL;
  2875. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2876. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2877. /**********************status**************************/
  2878. loc = strstr(payload, "status");
  2879. memset(sstr ,0, sizeof(sstr) );
  2880. c = 0;
  2881. while (loc[3+strlen("status")+c] != '\"')
  2882. {
  2883. sstr[c] = loc[3+strlen("status")+c];
  2884. c++;
  2885. }
  2886. sstr[c] = '\0';
  2887. strcpy(statusStr, sstr);
  2888. /**********************data**************************/
  2889. loc = strstr(payload, "data");
  2890. memset(sstr ,0, sizeof(sstr) );
  2891. c = 0;
  2892. while (loc[3+strlen("data")+c] != '\"')
  2893. {
  2894. sstr[c] = loc[3+strlen("data")+c];
  2895. c++;
  2896. }
  2897. sstr[c] = '\0';
  2898. strcpy(dataStr, sstr);
  2899. return result;
  2900. }
  2901. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2902. {
  2903. mtrace();
  2904. int result = FAIL;
  2905. char message[1000]={0};
  2906. double diff_f = 0.0;
  2907. int diff_i = 0;
  2908. int diffSeconds = 0;
  2909. struct tm tp;
  2910. int TimeZero = FALSE;
  2911. int CompositeScheduleIndex = 0;
  2912. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2913. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2914. {
  2915. TimeZero = TRUE;
  2916. }
  2917. else
  2918. {
  2919. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2920. }
  2921. if(TimeZero == FALSE)
  2922. {
  2923. tp.tm_isdst = -1;
  2924. time_t utc = mktime(&tp);
  2925. time_t t = time(NULL);
  2926. diff_f = difftime(t, utc);
  2927. diff_i = (int)diff_f;
  2928. diffSeconds = diff_i % 86400;//86400 seconds/day
  2929. }
  2930. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2931. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2932. #if 0 //remove temporally
  2933. 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}"
  2934. ,MESSAGE_TYPE_CALLRESULT
  2935. ,uuid
  2936. ,payload
  2937. ,connectorIdInt
  2938. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2939. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2940. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2941. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2942. #endif
  2943. if(nPeriod == 0)
  2944. {
  2945. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2946. ,MESSAGE_TYPE_CALLRESULT
  2947. ,uuid
  2948. ,payload
  2949. ,connectorIdInt
  2950. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2951. }
  2952. else
  2953. {
  2954. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2955. ,MESSAGE_TYPE_CALLRESULT
  2956. ,uuid
  2957. ,payload
  2958. ,connectorIdInt
  2959. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2960. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2961. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2962. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2963. int len = nPeriod;
  2964. //Last Period StartPriod is less than diffSeconds
  2965. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2966. {
  2967. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2968. , 0
  2969. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2970. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2971. }
  2972. else
  2973. {
  2974. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2975. {
  2976. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2977. {
  2978. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2979. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2980. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2981. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2982. }
  2983. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2984. {
  2985. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2986. , (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - 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*/))
  2987. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2988. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2989. }
  2990. }
  2991. }
  2992. sprintf(message + strlen(message), "]}}]");
  2993. }
  2994. LWS_Send(message);
  2995. result = TRUE;
  2996. return result;
  2997. }
  2998. int sendGetConfigurationConfirmation(char *uuid)
  2999. {
  3000. mtrace();
  3001. int result = FAIL;
  3002. int MaxKeySupported = 0;
  3003. int sentConfigurationNumber= 0;
  3004. int sentunConfigurationNumber= 0;
  3005. char message[4000]={0};
  3006. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3007. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3008. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3009. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3010. ,MESSAGE_TYPE_CALLRESULT
  3011. ,uuid );
  3012. //configuration key
  3013. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3014. {
  3015. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3016. {
  3017. if (sentConfigurationNumber == 0)
  3018. {
  3019. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3020. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3021. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3022. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3023. }
  3024. else
  3025. {
  3026. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3027. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3028. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3029. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3030. }
  3031. sentConfigurationNumber = sentConfigurationNumber + 1;
  3032. }
  3033. }
  3034. sprintf(message + strlen(message), "]");
  3035. if(UnknownKeynum != 0)
  3036. {
  3037. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3038. //unkown key
  3039. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3040. {
  3041. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3042. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3043. if(sentunConfigurationNumber == 0)
  3044. {
  3045. sprintf(message + strlen(message), "\"%s\""
  3046. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3047. }
  3048. else
  3049. {
  3050. sprintf(message + strlen(message), ",\"%s\""
  3051. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3052. }
  3053. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3054. }
  3055. sprintf(message + strlen(message), "]");
  3056. }
  3057. sprintf(message + strlen(message), "} ]");
  3058. LWS_Send(message);
  3059. return result;
  3060. }
  3061. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3062. {
  3063. mtrace();
  3064. int result = FAIL;
  3065. char message[400]={0};
  3066. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3067. if(strcmp(payload,"")==0)
  3068. {
  3069. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3070. }
  3071. else
  3072. {
  3073. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3074. }
  3075. LWS_Send(message);
  3076. result = TRUE;
  3077. return result;
  3078. }
  3079. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3080. {
  3081. mtrace();
  3082. int result = FAIL;
  3083. char message[80]={0};
  3084. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3085. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3086. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3087. LWS_Send(message);
  3088. result = TRUE;
  3089. return result;
  3090. }
  3091. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3092. {
  3093. mtrace();
  3094. int result = FAIL;
  3095. char message[80]={0};
  3096. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3097. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3098. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3099. LWS_Send(message);
  3100. result = TRUE;
  3101. return result;
  3102. }
  3103. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3104. {
  3105. mtrace();
  3106. int result = FAIL;
  3107. char message[80]={0};
  3108. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3109. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3110. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3111. LWS_Send(message);
  3112. result = TRUE;
  3113. return result;
  3114. }
  3115. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3116. {
  3117. mtrace();
  3118. int result = FAIL;
  3119. char message[80]={0};
  3120. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3121. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3122. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3123. LWS_Send(message);
  3124. result = TRUE;
  3125. return result;
  3126. }
  3127. int sendResetConfirmation(char *uuid,char *payload)
  3128. {
  3129. mtrace();
  3130. int result = FAIL;
  3131. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3132. char message[80]={0};
  3133. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3134. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3135. LWS_Send(message);
  3136. result = TRUE;
  3137. return result;
  3138. }
  3139. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3140. {
  3141. mtrace();
  3142. int result = FAIL;
  3143. char message[500]={0};
  3144. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3145. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3146. LWS_Send(message);
  3147. result = TRUE;
  3148. return result;
  3149. }
  3150. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3151. {
  3152. mtrace();
  3153. int result = FAIL;
  3154. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3155. char message[80]={0};
  3156. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3157. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3158. LWS_Send(message);
  3159. result = TRUE;
  3160. return result;
  3161. }
  3162. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3163. {
  3164. mtrace();
  3165. int result = FAIL;
  3166. char message[80]={0};
  3167. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3168. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3169. LWS_Send(message);
  3170. result = TRUE;
  3171. return result;
  3172. }
  3173. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3174. {
  3175. mtrace();
  3176. int result = FAIL;
  3177. char message[80]={0};
  3178. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3179. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3180. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3181. LWS_Send(message);
  3182. result = TRUE;
  3183. return result;
  3184. }
  3185. int sendUpdateFirmwareConfirmation(char *uuid)
  3186. {
  3187. mtrace();
  3188. int result = FAIL;
  3189. char message[60]={0};
  3190. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3191. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3192. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3193. LWS_Send(message);
  3194. result = TRUE;
  3195. return result;
  3196. }
  3197. //==========================================
  3198. // send CallError routine
  3199. //==========================================
  3200. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3201. {
  3202. mtrace();
  3203. //int result = FAIL;
  3204. char message[220]={0};
  3205. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3206. #ifdef SystemLogMessage
  3207. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3208. uniqueId, action, errorCode, errorDescription);
  3209. #endif
  3210. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3211. LWS_Send(message);
  3212. //result = TRUE;
  3213. }
  3214. //==========================================
  3215. // Handle server request routine Start
  3216. //==========================================
  3217. #define GUN_NUM 1
  3218. int handleCancelReservationRequest(char *uuid, char *payload)
  3219. {
  3220. mtrace();
  3221. int result = FAIL;
  3222. int gunNO = 0;
  3223. int reservationIdInt =0;
  3224. char comfirmstr[20];
  3225. int c = 0;
  3226. char *loc;
  3227. char sstr[100]={0};
  3228. DEBUG_INFO("handle CancelReservationRequest\n");
  3229. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3230. c = 0;
  3231. loc = strstr(payload, "reservationId");
  3232. memset(sstr ,0, sizeof(sstr) );
  3233. while (loc[strlen("reservationId")+2+c] != '}')
  3234. {
  3235. sstr[c] = loc[strlen("reservationId")+2+c];
  3236. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3237. c++;
  3238. }
  3239. sstr[c] = '\0';
  3240. reservationIdInt = atoi(sstr);
  3241. memset(comfirmstr, 0, sizeof comfirmstr);
  3242. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3243. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3244. //check Transaction active
  3245. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3246. {
  3247. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3248. {
  3249. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3250. {
  3251. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3252. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3253. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3254. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3255. goto end;
  3256. }
  3257. }
  3258. for (int index = 0; index < CCS_QUANTITY; index++)
  3259. {
  3260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3261. {
  3262. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3263. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3264. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3265. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3266. goto end;
  3267. }
  3268. }
  3269. for (int index = 0; index < GB_QUANTITY; index++)
  3270. {
  3271. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3272. {
  3273. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3274. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3275. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3276. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3277. goto end;
  3278. }
  3279. }
  3280. }
  3281. else
  3282. {
  3283. for (int index = 0; index < AC_QUANTITY; index++)
  3284. {
  3285. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3286. {
  3287. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3288. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3289. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3290. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3291. goto end;
  3292. }
  3293. }
  3294. }// END FOR AC ELSE
  3295. //The reservationId does NOT match the reservationId
  3296. sendCancelReservationConfirmation(uuid, comfirmstr);
  3297. end:
  3298. // Fill in ocpp packet uuid
  3299. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3300. return result;
  3301. }
  3302. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3303. {
  3304. mtrace();
  3305. int result = FAIL;
  3306. int gunIndex = 0;
  3307. char sstr[90]={0};
  3308. char typeStr[16]={0};
  3309. char comfirmstr[20];
  3310. int specificId = FALSE;
  3311. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3312. char *loc;
  3313. //int intervalInt = 0;
  3314. int c = 0;
  3315. /*** connectorId ****/
  3316. c = 0;
  3317. loc = strstr(payload, "connectorId");
  3318. memset(sstr ,0, sizeof(sstr) );
  3319. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3320. {
  3321. sstr[c] = loc[strlen("connectorId")+2+c];
  3322. c++;
  3323. }
  3324. sstr[c] = '\0';
  3325. gunIndex = atoi(sstr);
  3326. /***type ****/
  3327. loc = strstr(payload, "type");
  3328. memset(sstr ,0, sizeof(sstr) );
  3329. c = 0;
  3330. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3331. {
  3332. sstr[c] = loc[3+strlen("type")+c];
  3333. c++;
  3334. }
  3335. sstr[c] = '\0';
  3336. strcpy(typeStr, sstr);
  3337. if(gunIndex != 0)
  3338. {
  3339. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3340. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3341. }
  3342. else
  3343. {
  3344. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3345. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3346. }
  3347. memset(comfirmstr, 0, sizeof comfirmstr);
  3348. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3349. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3350. {
  3351. specificId = TRUE;
  3352. }
  3353. if(specificId == FALSE)
  3354. goto end;
  3355. if(gunIndex != 0)
  3356. {
  3357. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3358. }
  3359. else
  3360. {
  3361. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3362. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3363. }
  3364. /*
  3365. enum _SYSTEM_STATUS
  3366. {
  3367. S_BOOTING = 0,
  3368. S_IDLE, = 1
  3369. S_AUTHORIZING, =2
  3370. S_REASSIGN_CHECK, =3
  3371. S_REASSIGN, =4
  3372. S_PRECHARGE, =5
  3373. S_PREPARING_FOR_EV, =6
  3374. S_PREPARING_FOR_EVSE, =7
  3375. S_CHARGING, =8
  3376. S_TERMINATING, =9
  3377. S_COMPLETE, =10
  3378. S_ALARM, =11
  3379. S_FAULT =12
  3380. }
  3381. */
  3382. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3383. {
  3384. //check Transaction active
  3385. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3386. {
  3387. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3388. {
  3389. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3390. {
  3391. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3392. {
  3393. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3394. }
  3395. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3396. {
  3397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3398. }
  3399. else
  3400. {
  3401. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3402. }
  3403. goto end;
  3404. }
  3405. }//END FOR CHAdeMO_QUANTITY
  3406. for (int index = 0; index < CCS_QUANTITY; index++)
  3407. {
  3408. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3409. {
  3410. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3411. {
  3412. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3413. }
  3414. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3415. {
  3416. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3417. }
  3418. else
  3419. {
  3420. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3421. }
  3422. goto end;
  3423. }
  3424. }//END FOR CCS_QUANTITY
  3425. for (int index = 0; index < GB_QUANTITY; index++)
  3426. {
  3427. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3428. {
  3429. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3430. {
  3431. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3432. }
  3433. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3434. {
  3435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3436. }
  3437. else
  3438. {
  3439. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3440. }
  3441. goto end;
  3442. }
  3443. }// END FOR GB_QUANTITY
  3444. }
  3445. else
  3446. {
  3447. for (int index = 0; index < AC_QUANTITY; index++)
  3448. {
  3449. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3450. {
  3451. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3452. {
  3453. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3454. }
  3455. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3456. {
  3457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3458. }
  3459. else
  3460. {
  3461. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3462. }
  3463. goto end;
  3464. }
  3465. }//END FOR AC_QUANTITY
  3466. }// END FOR AC ELSE
  3467. }//END FOR AvailabilityTypeStr[Inoperative]
  3468. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3469. {
  3470. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3471. //check Transaction active
  3472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3473. {
  3474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3475. {
  3476. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3477. {
  3478. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3479. goto end;
  3480. }
  3481. }//END FOR CHAdeMO_QUANTITY
  3482. for (int index = 0; index < CCS_QUANTITY; index++)
  3483. {
  3484. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3485. {
  3486. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3487. goto end;
  3488. }
  3489. }//END FOR CCS_QUANTITY
  3490. for (int index = 0; index < GB_QUANTITY; index++)
  3491. {
  3492. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3493. {
  3494. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3496. goto end;
  3497. }
  3498. }// END FOR GB_QUANTITY
  3499. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3500. }
  3501. else
  3502. {
  3503. for (int index = 0; index < AC_QUANTITY; index++)
  3504. {
  3505. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3506. {
  3507. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3508. goto end;
  3509. }
  3510. }//END FOR CHAdeMO_QUANTITY
  3511. }//END FOR AC ELSE
  3512. }//END FOR AvailabilityTypeStr[Operative]
  3513. end:
  3514. if(gunIndex != 0)
  3515. {
  3516. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3517. }
  3518. else
  3519. {
  3520. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3521. }
  3522. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3523. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3524. return result;
  3525. }
  3526. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3527. {
  3528. mtrace();
  3529. int result = FAIL;
  3530. char sstr[100]={0};
  3531. char keystr[40]={0};
  3532. char valuestr[100]={0};
  3533. char *loc;
  3534. int c = 0;
  3535. char comfirmstr[20]={0};
  3536. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3537. /***key ****/
  3538. loc = strstr(payload, "key");
  3539. memset(sstr ,0, sizeof(sstr) );
  3540. c = 0;
  3541. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3542. {
  3543. sstr[c] = loc[3+strlen("key")+c];
  3544. c++;
  3545. }
  3546. sstr[c] = '\0';
  3547. strcpy(keystr, sstr);
  3548. //DEBUG_INFO( "keystr=%s\n",keystr);
  3549. /***value ****/
  3550. loc = strstr(payload, "value");
  3551. memset(sstr ,0, sizeof(sstr) );
  3552. c = 0;
  3553. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3554. {
  3555. sstr[c] = loc[3+strlen("value")+c];
  3556. c++;
  3557. }
  3558. sstr[c] = '\0';
  3559. strcpy(valuestr, sstr);
  3560. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3561. if((uuid==NULL) || (payload ==NULL) )
  3562. {
  3563. #ifdef Debug
  3564. DEBUG_INFO("payload is null\n");
  3565. #endif
  3566. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3567. }
  3568. else
  3569. {
  3570. int status = setKeyValue(keystr, valuestr);
  3571. switch(status)
  3572. {
  3573. case ConfigurationStatus_Accepted:
  3574. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3575. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3576. StoreConfigurationTable();
  3577. break;
  3578. case ConfigurationStatus_Rejected:
  3579. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3580. break;
  3581. case RebootRequired:
  3582. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3583. StoreConfigurationTable();
  3584. break;
  3585. case NotSupported:
  3586. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3587. break;
  3588. default:
  3589. break;
  3590. }
  3591. }
  3592. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3593. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3594. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3595. return result;
  3596. }
  3597. int handleClearCacheRequest(char *uuid, char *payload)
  3598. {
  3599. mtrace();
  3600. int result = FAIL;
  3601. char comfirmstr[20];
  3602. int fd;
  3603. char rmFileCmd[100]={0};
  3604. struct stat stats;
  3605. DEBUG_INFO("handle ClearCacheRequest\n");
  3606. stat("../Storage/OCPP", &stats);
  3607. // Check for directory existence
  3608. if (S_ISDIR(stats.st_mode) == 1)
  3609. {
  3610. //DEBUG_ERROR("\n OCPP directory exist \n");
  3611. }
  3612. else
  3613. {
  3614. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3615. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3616. system(rmFileCmd);
  3617. }
  3618. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3619. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3620. {
  3621. DEBUG_INFO("AuthorizationCache file exist.\n");
  3622. }
  3623. else
  3624. {
  3625. DEBUG_INFO("AuthorizationCache file not exist\n");
  3626. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3627. if(log == NULL)
  3628. {
  3629. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3630. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3631. goto end;
  3632. }
  3633. else
  3634. {
  3635. fclose(log);
  3636. }
  3637. }
  3638. fd = open(AuthorizationCache_JSON,O_RDWR);
  3639. if(fd < 0)
  3640. {
  3641. DEBUG_INFO("open AuthorizationCache file failed\n");
  3642. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3643. }
  3644. else
  3645. {
  3646. DEBUG_INFO("open AuthorizationCache file successful\n");
  3647. //* 清空? 件 */
  3648. ftruncate(fd,0);
  3649. //* ? 新设置? 件? 移??*/
  3650. lseek(fd,0,SEEK_SET);
  3651. close(fd);
  3652. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3653. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3654. }
  3655. end:
  3656. sendClearCacheConfirmation(uuid, comfirmstr);
  3657. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3658. return result;
  3659. }
  3660. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3661. {
  3662. mtrace();
  3663. int result = FAIL;
  3664. int resultRename;
  3665. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3666. char chargingProfilePurposeStr[26]={0};
  3667. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3668. char tempchargingProfilePurposeStr[26]={0};
  3669. char sstr[160]={0};//sstr[200]={ 0 };
  3670. char str[100]={0};
  3671. int c = 0;
  3672. //int i = 0;
  3673. //char * pch;
  3674. char *loc;
  3675. char fname[200];
  3676. char comfirmstr[20]={0};
  3677. char word[1000]={0};
  3678. int clearflag = FALSE;
  3679. int chargingProfileIdIsNULL = FALSE;
  3680. int connectorIsNULL = FALSE;
  3681. int chargingProfilePurposeIsNULL = FALSE;
  3682. int stackLevelIsNULL = FALSE;
  3683. FILE *fptr1, *fptr2;
  3684. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3685. int n_chargingProfile=0;
  3686. char sLineWord[1060]={0};
  3687. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3688. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3689. //***id ****/
  3690. c = 0;
  3691. loc = strstr(payload, "id");
  3692. memset(sstr ,0, sizeof(sstr) );
  3693. if(loc == NULL)
  3694. {
  3695. chargingProfileIdIsNULL = TRUE;
  3696. }
  3697. else
  3698. {
  3699. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3700. {
  3701. sstr[c] = loc[strlen("id")+2+c];
  3702. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3703. c++;
  3704. }
  3705. sstr[c] = '\0';
  3706. chargingProfileIdInt = atoi(sstr);
  3707. }
  3708. //***connectorId ****/
  3709. c=0;
  3710. loc = strstr(payload, "connectorId");
  3711. memset(sstr ,0, sizeof(sstr) );
  3712. if(loc == NULL)
  3713. {
  3714. connectorIsNULL = TRUE;
  3715. }
  3716. else
  3717. {
  3718. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3719. {
  3720. sstr[c] = loc[strlen("connectorId")+2+c];
  3721. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3722. c++;
  3723. }
  3724. sstr[c] = '\0';
  3725. connectorIdInt = atoi(sstr);
  3726. }
  3727. //***chargingProfilePurpose ****/
  3728. loc = strstr(payload, "chargingProfilePurpose");
  3729. memset(sstr ,0, sizeof(sstr) );
  3730. c = 0;
  3731. if(loc == NULL)
  3732. {
  3733. chargingProfilePurposeIsNULL = TRUE;
  3734. }
  3735. else
  3736. {
  3737. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3738. {
  3739. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3740. c++;
  3741. }
  3742. sstr[c] = '\0';
  3743. strcpy(chargingProfilePurposeStr, sstr);
  3744. }
  3745. //***stackLevel ****/
  3746. c=0;
  3747. loc = strstr(payload, "stackLevel");
  3748. memset(sstr ,0, sizeof(sstr) );
  3749. if(loc == NULL)
  3750. {
  3751. stackLevelIsNULL = TRUE;
  3752. }
  3753. else
  3754. {
  3755. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3756. {
  3757. sstr[c] = loc[strlen("stackLevel")+2+c];
  3758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3759. c++;
  3760. }
  3761. sstr[c] = '\0';
  3762. stackLevelInt = atoi(sstr);
  3763. }
  3764. if(connectorIsNULL == FALSE)
  3765. {
  3766. switch(connectorIdInt)
  3767. {
  3768. case 0:
  3769. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3770. {
  3771. strcpy(fname, ChargePointMaxProfile_JSON);
  3772. }
  3773. // else
  3774. // {
  3775. // strcpy(fname, TxDefaultProfile_0_JSON);
  3776. // }
  3777. break;
  3778. case 1:
  3779. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3780. {
  3781. strcpy(fname, TxDefaultProfile_1_JSON);
  3782. }
  3783. // else
  3784. // {
  3785. // strcpy(fname, TxProfile_1_JSON);
  3786. // }
  3787. break;
  3788. case 2:
  3789. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3790. {
  3791. strcpy(fname, TxDefaultProfile_2_JSON);
  3792. }
  3793. // else
  3794. // {
  3795. // strcpy(fname, TxProfile_2_JSON);
  3796. // }
  3797. break;
  3798. default:
  3799. strcpy(fname, ChargePointMaxProfile_JSON );
  3800. break;
  3801. }
  3802. }
  3803. else
  3804. {
  3805. strcpy(fname, ChargePointMaxProfile_JSON );
  3806. }
  3807. fptr1 = fopen(fname, "r");
  3808. if (!fptr1)
  3809. {
  3810. //file not exist
  3811. DEBUG_INFO("Unable to open the input file!!\n");
  3812. fptr1 = fopen(fname, "w+");
  3813. }
  3814. fclose(fptr1);
  3815. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3816. {
  3817. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3818. goto end;
  3819. }
  3820. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3821. {
  3822. //clear the whole contents of a file in C
  3823. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3824. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3825. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3826. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3827. fclose(fopen(TxProfile_1_JSON, "w"));
  3828. fclose(fopen(TxProfile_2_JSON, "w"));
  3829. #if 0
  3830. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3831. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3832. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3833. #endif
  3834. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3835. }
  3836. else
  3837. {
  3838. fptr1 = fopen(fname, "r");
  3839. fptr2 = fopen(temp, "w+");
  3840. while(fscanf(fptr1, "%s", word) != EOF)
  3841. {
  3842. //DEBUG_INFO("word=%s\n",word);
  3843. if(strcmp(word, "chargingProfileId") == 0)
  3844. {
  3845. n_chargingProfile = n_chargingProfile + 1;
  3846. DEBUG_INFO("chargingProfileId Found\n");
  3847. }
  3848. }
  3849. rewind(fptr1);
  3850. //search Charging Profile Element
  3851. //int i= 0;
  3852. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3853. {
  3854. //*************************tempconnectorIdInt*********************************/
  3855. loc = strstr(sLineWord, "connectorId");
  3856. c = 0;
  3857. memset(sstr ,0, sizeof(sstr) );
  3858. while (loc[strlen("connectorId")+2+c] != ',')
  3859. {
  3860. sstr[c] = loc[strlen("connectorId")+2+c];
  3861. c++;
  3862. }
  3863. sstr[c] = '\0';
  3864. tempconnectorIdInt = atoi(sstr);
  3865. //chargingProfileId
  3866. c = 0;
  3867. loc = strstr(sLineWord, "chargingProfileId");
  3868. memset(sstr ,0, sizeof(sstr) );
  3869. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3870. {
  3871. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3872. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3873. c++;
  3874. }
  3875. sstr[c] = '\0';
  3876. tempchargingProfileIdInt = atoi(sstr);
  3877. //stackLevel
  3878. c = 0;
  3879. loc = strstr(sLineWord, "stackLevel");
  3880. memset(sstr ,0, sizeof(sstr) );
  3881. while (loc[strlen("stackLevel")+2+c] != ',')
  3882. {
  3883. sstr[c] = loc[strlen("stackLevel")+2+c];
  3884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3885. c++;
  3886. }
  3887. sstr[c] = '\0';
  3888. tempstackLevelInt = atoi(sstr);
  3889. c = 0;
  3890. loc = strstr(sLineWord, "chargingProfilePurpose");
  3891. memset(sstr ,0, sizeof(sstr) );
  3892. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3893. {
  3894. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3895. c++;
  3896. }
  3897. sstr[c] = '\0';
  3898. strcpy(tempchargingProfilePurposeStr, sstr);
  3899. if(chargingProfileIdIsNULL == FALSE)
  3900. {
  3901. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3902. {
  3903. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3904. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3905. clearflag = TRUE;
  3906. continue;
  3907. }
  3908. else
  3909. {
  3910. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3911. //json_object_array_add(newHeatMap, jsonitem);
  3912. fprintf(fptr2, sLineWord);//writing data into file
  3913. }
  3914. }
  3915. else
  3916. {
  3917. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3918. {
  3919. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3920. {
  3921. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3922. clearflag = TRUE;
  3923. continue;
  3924. }
  3925. }
  3926. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3927. {
  3928. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3929. {
  3930. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3931. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3932. {
  3933. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3934. clearflag = TRUE;
  3935. continue;
  3936. }
  3937. }
  3938. }
  3939. else
  3940. {
  3941. //json_object_array_add(newHeatMap, jsonitem);
  3942. fprintf(fptr2, sLineWord);//writing data into file
  3943. }
  3944. }
  3945. memset(sLineWord, 0, sizeof sLineWord);
  3946. }
  3947. if(clearflag == FALSE)
  3948. {
  3949. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3950. goto end;
  3951. }
  3952. fclose(fptr1);
  3953. fclose(fptr2);
  3954. sprintf(str,"rm -f %s",fname);
  3955. system(str);
  3956. resultRename = rename(temp, fname);
  3957. if(resultRename == 0)
  3958. {
  3959. DEBUG_INFO("File ChargingProfile renamed successfully");
  3960. }
  3961. else
  3962. {
  3963. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3964. }
  3965. }
  3966. end:
  3967. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3968. return result;
  3969. }
  3970. int handleDataTransferRequest(char *uuid, char *payload)
  3971. {
  3972. mtrace();
  3973. int result = FAIL;
  3974. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3975. char tempvendorId[255]={0};
  3976. char tempmessageId[50]={0};
  3977. char tempdata[50]={0};
  3978. char sstr[160]={0};//sstr[200]={ 0 };
  3979. char message[80]={0};
  3980. int c = 0;
  3981. char *loc;
  3982. DEBUG_INFO("handle DataTransferRequest\n");
  3983. if((uuid != NULL) && (payload != NULL))
  3984. {
  3985. //===============================
  3986. // vendorId
  3987. //===============================
  3988. c = 0;
  3989. loc = strstr(payload, "vendorId");
  3990. while (loc[strlen("vendorId")+3+c] != '\"')
  3991. {
  3992. sstr[c] = loc[strlen("vendorId")+3+c];
  3993. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3994. c++;
  3995. }
  3996. sstr[c] = '\0';
  3997. strcpy(tempvendorId,sstr);
  3998. //===============================
  3999. // messageId
  4000. //===============================
  4001. memset(sstr ,0, sizeof(sstr) );
  4002. c = 0;
  4003. loc = strstr(payload, "messageId");
  4004. while (loc[strlen("messageId")+3+c] != '\"')
  4005. {
  4006. sstr[c] = loc[strlen("messageId")+3+c];
  4007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4008. c++;
  4009. }
  4010. sstr[c] = '\0';
  4011. strcpy(tempmessageId,sstr);
  4012. //===============================
  4013. // data
  4014. //===============================
  4015. memset(sstr ,0, sizeof(sstr) );
  4016. c = 0;
  4017. loc = strstr(payload, "data");
  4018. printf("loc=%s\n",loc);
  4019. while (loc[strlen("data")+3+c] != '\"')
  4020. {
  4021. sstr[c] = loc[strlen("data")+3+c];
  4022. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4023. c++;
  4024. }
  4025. sstr[c] = '\0';
  4026. strcpy(tempdata,sstr);
  4027. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4028. }
  4029. else
  4030. {
  4031. char guid[37]={0};
  4032. random_uuid(guid);
  4033. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4034. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4035. }
  4036. LWS_Send(message);
  4037. return result;
  4038. }
  4039. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4040. {
  4041. mtrace();
  4042. int result = FAIL;
  4043. int connectorIdInt, durationInt;
  4044. char chargingRateUnitStr[4]={0};
  4045. //int tempconnectorIdInt,
  4046. int tempdurationInt;
  4047. float tempminChargingRateFloat = 0.0;
  4048. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4049. int tempStartPeriodInt=0;
  4050. float tempLimitInt=0.0;//0.1;
  4051. int tempNumberPhasesInt=0;
  4052. char fname[200];
  4053. char comfirmstr[20];
  4054. //float totallimit =0.0;
  4055. float MinChargingRate =0.0;
  4056. //double diff_t;
  4057. //struct tm tp;
  4058. FILE *fptr1;
  4059. int c = 0;
  4060. //int i = 0;
  4061. char * pch;
  4062. char *loc;
  4063. char sstr[200]={ 0 };
  4064. int n_chargingProfile = 0;
  4065. int n_SchedulePeriods = 0;
  4066. char SchedulePeriodList[10][200]={0};
  4067. char sLineWord[800]={0};
  4068. //int n_periods = 0;
  4069. char word[1000]={0};
  4070. int confirmPeriods = 0;
  4071. struct StructProfile ChargePointMaxProfile;
  4072. struct StructProfile TxDefaultProfile;
  4073. struct StructProfile TxProfile;
  4074. struct StructProfile TxDefaultProfiletemp[2]={0};
  4075. int TxDefaultProfileFileIsNull=FALSE;
  4076. int ChargePointMaxProfileIsNull=FALSE;
  4077. int TxProfileIsNull=FALSE;
  4078. int CompositeSceduleIndex = 0;
  4079. char ChargePointMaxProfileScheduleStr[30]={0};
  4080. char TxDefaultProfileScheduleStr[30]={0};
  4081. char TxProfileScheduleStr[30]={0};
  4082. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4083. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4084. memset(&TxProfile,0,sizeof(struct StructProfile));
  4085. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4086. c=0;
  4087. loc = strstr(payload, "connectorId");
  4088. memset(sstr ,0, sizeof(sstr) );
  4089. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4090. {
  4091. sstr[c] = loc[strlen("connectorId")+2+c];
  4092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4093. c++;
  4094. }
  4095. sstr[c] = '\0';
  4096. connectorIdInt = atoi(sstr);
  4097. c=0;
  4098. loc = strstr(payload, "duration");
  4099. memset(sstr ,0, sizeof(sstr) );
  4100. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4101. {
  4102. sstr[c] = loc[strlen("duration")+2+c];
  4103. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4104. c++;
  4105. }
  4106. sstr[c] = '\0';
  4107. durationInt = atoi(sstr);
  4108. c = 0;
  4109. loc = strstr(payload, "chargingRateUnit");
  4110. memset(sstr ,0, sizeof(sstr) );
  4111. if(loc == NULL)
  4112. {
  4113. }
  4114. else
  4115. {
  4116. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4117. {
  4118. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4119. c++;
  4120. }
  4121. sstr[c] = '\0';
  4122. strcpy(chargingRateUnitStr, sstr);
  4123. }
  4124. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4125. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4126. if(connectorIdInt==0) // connectorId is 0
  4127. {
  4128. //******************************ChargePointMaxProfile*****************************************************/
  4129. strcpy(fname, ChargePointMaxProfile_JSON );
  4130. char word[30]={0};
  4131. char sLineWord[1060]={0};
  4132. int n_chargingProfile=0;
  4133. ChargePointMaxProfileIsNull=TRUE;
  4134. if((access(fname,F_OK))!=-1)
  4135. {
  4136. fptr1 = fopen(fname, "r");
  4137. int c;
  4138. c = fgetc(fptr1);
  4139. //DEBUG_INFO("c:%d\n",c);
  4140. rewind(fptr1);
  4141. if(c == EOF)
  4142. {
  4143. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4144. ChargePointMaxProfileIsNull=TRUE;
  4145. fclose(fptr1);
  4146. }
  4147. else
  4148. {
  4149. ChargePointMaxProfileIsNull=FALSE;
  4150. while(fscanf(fptr1, "%s", word) != EOF)
  4151. {
  4152. if(strcmp(word, "chargingProfileId") == 0)
  4153. {
  4154. n_chargingProfile = n_chargingProfile + 1;
  4155. printf("Found\n");
  4156. }
  4157. }
  4158. rewind(fptr1);
  4159. //search Charging Profile Element
  4160. int i= 0;
  4161. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4162. #if 0
  4163. /***********connectorId****************/
  4164. c = 0;
  4165. loc = strstr(sLineWord, "connectorId");
  4166. // printf("loc=%s\n",loc);
  4167. memset(sstr ,0, sizeof(sstr) );
  4168. while (loc[strlen("connectorId")+2+c] != ',')
  4169. {
  4170. sstr[c] = loc[strlen("connectorId")+2+c];
  4171. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4172. c++;
  4173. }
  4174. sstr[c] = '\0';
  4175. tempconnectorIdInt = atoi(sstr);
  4176. #endif
  4177. //***********validFrom**************/
  4178. c = 0;
  4179. loc = strstr(sLineWord, "validFrom");
  4180. //DEBUG_INFO("loc=%s\n",loc);
  4181. memset(sstr ,0, sizeof(sstr) );
  4182. if(loc != NULL)
  4183. {
  4184. while (loc[3+strlen("validFrom")+c] != '\"')
  4185. {
  4186. sstr[c] = loc[3+strlen("validFrom")+c];
  4187. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4188. c++;
  4189. }
  4190. sstr[c] = '\0';
  4191. DEBUG_INFO("validFrom=%s\n",sstr);
  4192. strcpy(tempvalidFromStr,sstr);
  4193. }
  4194. else
  4195. {
  4196. strcpy(tempvalidFromStr,"");
  4197. }
  4198. //**********startSchedule**********/
  4199. c = 0;
  4200. loc = strstr(sLineWord, "startSchedule");
  4201. //DEBUG_INFO("loc=%s\n",loc);
  4202. memset(sstr ,0, sizeof(sstr) );
  4203. while (loc[3+strlen("startSchedule")+c] != '\"')
  4204. {
  4205. sstr[c] = loc[3+strlen("startSchedule")+c];
  4206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4207. c++;
  4208. }
  4209. sstr[c] = '\0';
  4210. strcpy(tempstartScheduleStr, sstr);
  4211. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4212. //**********chargingRateUnit**********/
  4213. c = 0;
  4214. loc = strstr(sLineWord, "chargingRateUnit");
  4215. memset(sstr ,0, sizeof(sstr) );
  4216. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4217. {
  4218. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4219. c++;
  4220. }
  4221. sstr[c] = '\0';
  4222. strcpy(tempchargingRateUnitStr, sstr);
  4223. //**********minChargingRate*******/
  4224. c = 0;
  4225. loc = strstr(sLineWord, "minChargingRate");
  4226. //printf("loc=%s\n",loc);
  4227. if(loc != NULL)
  4228. {
  4229. memset(sstr ,0, sizeof(sstr) );
  4230. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4231. {
  4232. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4233. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4234. c++;
  4235. }
  4236. sstr[c] = '\0';
  4237. tempminChargingRateFloat = atof(sstr);
  4238. }
  4239. else
  4240. {
  4241. tempminChargingRateFloat = 0.0;
  4242. }
  4243. //
  4244. #if 0
  4245. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4246. tp.tm_isdst = -1;
  4247. time_t utc = mktime(&tp);
  4248. // current time
  4249. time_t t = time(NULL);
  4250. #endif
  4251. //diff_t = difftime(t, utc);
  4252. //parsing strings to words
  4253. i = 0;
  4254. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4255. loc = loc+3+strlen("chargingSchedulePeriod");
  4256. pch = strtok(loc ,"{");
  4257. while (pch != NULL)
  4258. {
  4259. strcpy(SchedulePeriodList[i], pch);
  4260. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4261. //printf ("%s\n",pch);
  4262. pch = strtok (NULL, "{");
  4263. i = i + 1;
  4264. }
  4265. n_SchedulePeriods = i;
  4266. for(int i=0;i<n_SchedulePeriods;i++)
  4267. {
  4268. //*************startPeriod****************/
  4269. c = 0;
  4270. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4271. memset(sstr ,0, sizeof(sstr) );
  4272. while (loc[strlen("startPeriod")+2+c] != ',')
  4273. {
  4274. sstr[c] = loc[strlen("startPeriod")+2+c];
  4275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4276. c++;
  4277. }
  4278. sstr[c] = '\0';
  4279. tempStartPeriodInt = atoi(sstr);
  4280. //*************limit****************/
  4281. c = 0;
  4282. loc = strstr(SchedulePeriodList[i], "limit");
  4283. memset(sstr ,0, sizeof(sstr) );
  4284. while (loc[strlen("limit")+2+c] != ',')
  4285. {
  4286. sstr[c] = loc[strlen("limit")+2+c];
  4287. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4288. c++;
  4289. }
  4290. sstr[c] = '\0';
  4291. tempLimitInt = atof(sstr);
  4292. //*************numberPhases****************/
  4293. c = 0;
  4294. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4295. memset(sstr ,0, sizeof(sstr) );
  4296. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4297. {
  4298. sstr[c] = loc[strlen("numberPhases")+2+c];
  4299. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4300. c++;
  4301. }
  4302. sstr[c] = '\0';
  4303. tempNumberPhasesInt = atoi(sstr);
  4304. ChargePointMaxProfile.Duration = durationInt;
  4305. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4306. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4307. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4308. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4309. }
  4310. if(MinChargingRate < tempminChargingRateFloat)
  4311. MinChargingRate = tempminChargingRateFloat;
  4312. }
  4313. }// End of file ChargingProfile
  4314. } //THE END OF ACCESS ChargePointMaxProfile
  4315. //******************************TxDefaultProfile***********************************************/
  4316. strcpy(fname, TxDefaultProfile_0_JSON);
  4317. memset(word, 0, 30);
  4318. memset(sLineWord, 0, 1060);
  4319. //char word[30]={0};
  4320. //char sLineWord[1060]={0};
  4321. n_chargingProfile=0;
  4322. TxDefaultProfileFileIsNull=TRUE;
  4323. if((access(fname,F_OK))!=-1)
  4324. {
  4325. fptr1 = fopen(fname, "r");
  4326. c = 0;
  4327. c = fgetc(fptr1);
  4328. //DEBUG_INFO("c:%d\n",c);
  4329. rewind(fptr1);
  4330. if(c == EOF)
  4331. {
  4332. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4333. TxDefaultProfileFileIsNull=TRUE;
  4334. fclose(fptr1);
  4335. }
  4336. else
  4337. {
  4338. TxDefaultProfileFileIsNull=FALSE;
  4339. while(fscanf(fptr1, "%s", word) != EOF)
  4340. {
  4341. if(strcmp(word, "chargingProfileId") == 0)
  4342. {
  4343. n_chargingProfile = n_chargingProfile + 1;
  4344. printf("Found\n");
  4345. }
  4346. }
  4347. rewind(fptr1);
  4348. //search Charging Profile Element
  4349. int i= 0;
  4350. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4351. #if 0
  4352. /***********connectorId****************/
  4353. c = 0;
  4354. loc = strstr(sLineWord, "connectorId");
  4355. // printf("loc=%s\n",loc);
  4356. memset(sstr ,0, sizeof(sstr) );
  4357. while (loc[strlen("connectorId")+2+c] != ',')
  4358. {
  4359. sstr[c] = loc[strlen("connectorId")+2+c];
  4360. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4361. c++;
  4362. }
  4363. sstr[c] = '\0';
  4364. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4365. tempconnectorIdInt = atoi(sstr);
  4366. #endif
  4367. //***********validFrom**************/
  4368. c = 0;
  4369. loc = strstr(sLineWord, "validFrom");
  4370. //DEBUG_INFO("loc=%s\n",loc);
  4371. memset(sstr ,0, sizeof(sstr) );
  4372. if(loc != NULL)
  4373. {
  4374. while (loc[3+strlen("validFrom")+c] != '\"')
  4375. {
  4376. sstr[c] = loc[3+strlen("validFrom")+c];
  4377. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4378. c++;
  4379. }
  4380. sstr[c] = '\0';
  4381. DEBUG_INFO("validFrom=%s\n",sstr);
  4382. strcpy(tempvalidFromStr,sstr);
  4383. }
  4384. else
  4385. {
  4386. strcpy(tempvalidFromStr,"");
  4387. }
  4388. //**********startSchedule**********/
  4389. c = 0;
  4390. loc = strstr(sLineWord, "startSchedule");
  4391. //DEBUG_INFO("loc=%s\n",loc);
  4392. memset(sstr ,0, sizeof(sstr) );
  4393. while (loc[3+strlen("startSchedule")+c] != '\"')
  4394. {
  4395. sstr[c] = loc[3+strlen("startSchedule")+c];
  4396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4397. c++;
  4398. }
  4399. sstr[c] = '\0';
  4400. strcpy(tempstartScheduleStr, sstr);
  4401. strcpy(TxDefaultProfileScheduleStr, sstr);
  4402. DEBUG_INFO(" debug 3-1\n");
  4403. //**********chargingRateUnit**********/
  4404. c = 0;
  4405. loc = strstr(sLineWord, "chargingRateUnit");
  4406. memset(sstr ,0, sizeof(sstr) );
  4407. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4408. {
  4409. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4410. c++;
  4411. }
  4412. sstr[c] = '\0';
  4413. strcpy(tempchargingRateUnitStr, sstr);
  4414. //**********minChargingRate*******/
  4415. c = 0;
  4416. loc = strstr(sLineWord, "minChargingRate");
  4417. //printf("loc=%s\n",loc);
  4418. if(loc != NULL)
  4419. {
  4420. memset(sstr ,0, sizeof(sstr) );
  4421. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4422. {
  4423. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4424. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4425. c++;
  4426. }
  4427. sstr[c] = '\0';
  4428. tempminChargingRateFloat = atof(sstr);
  4429. }
  4430. else
  4431. {
  4432. tempminChargingRateFloat = 0.0;
  4433. }
  4434. #if 0
  4435. //
  4436. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4437. tp.tm_isdst = -1;
  4438. time_t utc = mktime(&tp);
  4439. // current time
  4440. time_t t = time(NULL);
  4441. //diff_t = difftime(t, utc);
  4442. #endif
  4443. //parsing strings to words
  4444. i = 0;
  4445. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4446. loc = loc+3+strlen("chargingSchedulePeriod");
  4447. pch = strtok(loc ,"{");
  4448. while (pch != NULL)
  4449. {
  4450. strcpy(SchedulePeriodList[i], pch);
  4451. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4452. //printf ("%s\n",pch);
  4453. pch = strtok (NULL, "{");
  4454. i = i + 1;
  4455. }
  4456. n_SchedulePeriods = i;
  4457. for(int i=0;i<n_SchedulePeriods;i++)
  4458. {
  4459. //*************startPeriod****************/
  4460. c = 0;
  4461. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4462. memset(sstr ,0, sizeof(sstr) );
  4463. while (loc[strlen("startPeriod")+2+c] != ',')
  4464. {
  4465. sstr[c] = loc[strlen("startPeriod")+2+c];
  4466. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4467. c++;
  4468. }
  4469. sstr[c] = '\0';
  4470. tempStartPeriodInt = atoi(sstr);
  4471. //*************limit****************/
  4472. c = 0;
  4473. loc = strstr(SchedulePeriodList[i], "limit");
  4474. memset(sstr ,0, sizeof(sstr) );
  4475. while (loc[strlen("limit")+2+c] != ',')
  4476. {
  4477. sstr[c] = loc[strlen("limit")+2+c];
  4478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4479. c++;
  4480. }
  4481. sstr[c] = '\0';
  4482. tempLimitInt = atof(sstr);
  4483. //*************numberPhases****************/
  4484. c = 0;
  4485. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4486. memset(sstr ,0, sizeof(sstr) );
  4487. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4488. {
  4489. sstr[c] = loc[strlen("numberPhases")+2+c];
  4490. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4491. c++;
  4492. }
  4493. sstr[c] = '\0';
  4494. tempNumberPhasesInt = atoi(sstr);
  4495. TxDefaultProfile.Duration = durationInt;
  4496. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4497. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4498. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4499. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4500. }
  4501. if(MinChargingRate < tempminChargingRateFloat)
  4502. MinChargingRate = tempminChargingRateFloat;
  4503. }
  4504. }
  4505. }// the end of ACCESS TxDefaultProfile
  4506. // Composite Schedule
  4507. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4508. {
  4509. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4510. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4511. {
  4512. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4513. {
  4514. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4515. }
  4516. else
  4517. {
  4518. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4519. }
  4520. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4521. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4522. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4523. }
  4524. }
  4525. //* Define temporary variables */
  4526. struct tm *gtime;
  4527. time_t now;
  4528. char buf[28];
  4529. /* Read the current system time */
  4530. time(&now);
  4531. /* Convert the system time to GMT (now UTC) */
  4532. gtime = gmtime(&now);
  4533. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4534. // make .conf
  4535. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4536. //MaxChargingProfilesInstalled is 10
  4537. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4538. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4539. //nPeriod = 1;
  4540. if(chargingRateUnitStr[0] != 0)
  4541. {
  4542. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4543. }
  4544. else
  4545. {
  4546. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4547. }
  4548. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4549. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4550. confirmPeriods = 1;
  4551. }
  4552. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4553. {
  4554. //*****************************ChargePointMaxProfile******************************************/
  4555. strcpy(fname, ChargePointMaxProfile_JSON);
  4556. ChargePointMaxProfileIsNull=TRUE;
  4557. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4558. {
  4559. fptr1 = fopen(fname, "r");
  4560. int c;
  4561. c = fgetc(fptr1);
  4562. //DEBUG_INFO("c:%d\n",c);
  4563. rewind(fptr1);
  4564. if(c == EOF)
  4565. {
  4566. DEBUG_INFO("\n End of file reached.");
  4567. ChargePointMaxProfileIsNull=TRUE;
  4568. fclose(fptr1);
  4569. }
  4570. else
  4571. {
  4572. ChargePointMaxProfileIsNull=FALSE;
  4573. while(fscanf(fptr1, "%s", word) != EOF)
  4574. {
  4575. if(strcmp(word, "chargingProfileId") == 0)
  4576. {
  4577. n_chargingProfile = n_chargingProfile + 1;
  4578. }
  4579. }
  4580. rewind(fptr1);
  4581. //search Charging Profile Element
  4582. int i = 0;
  4583. int j = 0;
  4584. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4585. #if 0
  4586. /***********connectorId****************/
  4587. c = 0;
  4588. loc = strstr(sLineWord, "connectorId");
  4589. memset(sstr ,0, sizeof(sstr) );
  4590. while (loc[strlen("connectorId")+2+c] != ',')
  4591. {
  4592. sstr[c] = loc[strlen("connectorId")+2+c];
  4593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4594. c++;
  4595. }
  4596. sstr[c] = '\0';
  4597. tempconnectorIdInt = atoi(sstr);
  4598. #endif
  4599. //***********validFrom**************/
  4600. c = 0;
  4601. loc = strstr(sLineWord, "validFrom");
  4602. if(loc != NULL)
  4603. {
  4604. memset(sstr ,0, sizeof(sstr) );
  4605. while (loc[3+strlen("validFrom")+c] != '\"')
  4606. {
  4607. sstr[c] = loc[3+strlen("validFrom")+c];
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. strcpy(tempvalidFromStr,sstr);
  4612. }
  4613. else
  4614. {
  4615. strcpy(tempvalidFromStr,"");
  4616. }
  4617. //***********validFrom**************/
  4618. c = 0;
  4619. loc = strstr(sLineWord, "duration");
  4620. if(loc != NULL)
  4621. {
  4622. memset(sstr ,0, sizeof(sstr) );
  4623. while (loc[2+strlen("duration")+c] != ',')
  4624. {
  4625. sstr[c] = loc[2+strlen("duration")+c];
  4626. c++;
  4627. }
  4628. sstr[c] = '\0';
  4629. tempdurationInt = atoi(sstr);
  4630. }
  4631. else
  4632. {
  4633. tempdurationInt = 0;
  4634. }
  4635. //**********startSchedule**********/
  4636. c = 0;
  4637. loc = strstr(sLineWord, "startSchedule");
  4638. memset(sstr ,0, sizeof(sstr) );
  4639. while (loc[3+strlen("startSchedule")+c] != '\"')
  4640. {
  4641. sstr[c] = loc[3+strlen("startSchedule")+c];
  4642. c++;
  4643. }
  4644. sstr[c] = '\0';
  4645. strcpy(tempstartScheduleStr, sstr);
  4646. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4647. //**********chargingRateUnit**********/
  4648. c = 0;
  4649. loc = strstr(sLineWord, "chargingRateUnit");
  4650. memset(sstr ,0, sizeof(sstr) );
  4651. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4652. {
  4653. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4654. c++;
  4655. }
  4656. sstr[c] = '\0';
  4657. strcpy(tempchargingRateUnitStr, sstr);
  4658. //**********minChargingRate*******/
  4659. c = 0;
  4660. loc = strstr(sLineWord, "minChargingRate");
  4661. if(loc != NULL)
  4662. {
  4663. memset(sstr ,0, sizeof(sstr) );
  4664. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4665. {
  4666. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4667. c++;
  4668. }
  4669. sstr[c] = '\0';
  4670. tempminChargingRateFloat = atof(sstr);
  4671. }
  4672. else
  4673. {
  4674. tempminChargingRateFloat = 0.0;
  4675. }
  4676. #if 0
  4677. //
  4678. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4679. tp.tm_isdst = -1;
  4680. time_t utc = mktime(&tp);
  4681. time_t t = time(NULL);
  4682. //diff_t = difftime(t, utc);
  4683. #endif
  4684. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4685. //DEBUG_INFO(" debug 5 -1\n");
  4686. //parsing strings to words
  4687. i = 0;
  4688. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4689. loc = loc+3+strlen("chargingSchedulePeriod");
  4690. pch = strtok(loc ,"{");
  4691. while (pch != NULL)
  4692. {
  4693. strcpy(SchedulePeriodList[i], pch);
  4694. pch = strtok (NULL, "{");
  4695. i = i + 1;
  4696. }
  4697. n_SchedulePeriods = i;
  4698. for(int i=0;i<n_SchedulePeriods;i++)
  4699. {
  4700. //*************startPeriod****************/
  4701. c = 0;
  4702. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4703. memset(sstr ,0, sizeof(sstr) );
  4704. while (loc[strlen("startPeriod")+2+c] != ',')
  4705. {
  4706. sstr[c] = loc[strlen("startPeriod")+2+c];
  4707. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4708. c++;
  4709. }
  4710. sstr[c] = '\0';
  4711. tempStartPeriodInt = atoi(sstr);
  4712. //*************limit****************/
  4713. c = 0;
  4714. loc = strstr(SchedulePeriodList[i], "limit");
  4715. memset(sstr ,0, sizeof(sstr) );
  4716. while (loc[strlen("limit")+2+c] != ',')
  4717. {
  4718. sstr[c] = loc[strlen("limit")+2+c];
  4719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4720. c++;
  4721. }
  4722. sstr[c] = '\0';
  4723. tempLimitInt = atof(sstr);
  4724. //*************numberPhases****************/
  4725. c = 0;
  4726. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4727. memset(sstr ,0, sizeof(sstr) );
  4728. while (loc[strlen("numberPhases")+2+c] != '}')
  4729. {
  4730. sstr[c] = loc[strlen("numberPhases")+2+c];
  4731. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4732. c++;
  4733. }
  4734. sstr[c] = '\0';
  4735. tempNumberPhasesInt = atoi(sstr);
  4736. if(j == 0)
  4737. {
  4738. ChargePointMaxProfile.Duration = tempdurationInt;
  4739. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4740. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4741. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4742. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4743. }
  4744. }
  4745. if(MinChargingRate < tempminChargingRateFloat)
  4746. {
  4747. MinChargingRate = tempminChargingRateFloat;
  4748. }
  4749. if(confirmPeriods < n_SchedulePeriods)
  4750. {
  4751. confirmPeriods = n_SchedulePeriods;
  4752. }
  4753. j = j + 1;
  4754. }
  4755. fclose(fptr1);
  4756. }
  4757. }// the end of access file ChargePointMaxProfile
  4758. //****************************TxDefaultProfile************************************************/
  4759. switch(connectorIdInt)
  4760. {
  4761. case 0:
  4762. break;
  4763. case 1:
  4764. strcpy(fname, TxDefaultProfile_1_JSON );
  4765. break;
  4766. case 2:
  4767. strcpy(fname, TxDefaultProfile_2_JSON );
  4768. break;
  4769. default:
  4770. strcpy(fname, TxDefaultProfile_1_JSON );
  4771. break;
  4772. }
  4773. TxDefaultProfileFileIsNull=TRUE;
  4774. if((access(fname,F_OK))!=-1)
  4775. {
  4776. fptr1 = fopen(fname, "r");
  4777. c = 0;
  4778. c = fgetc(fptr1);
  4779. //DEBUG_INFO("c:%d\n",c);
  4780. rewind(fptr1);
  4781. if(c == EOF)
  4782. {
  4783. DEBUG_INFO("\n End of file reached.");
  4784. TxDefaultProfileFileIsNull=TRUE;
  4785. fclose(fptr1);
  4786. }
  4787. else
  4788. {
  4789. TxDefaultProfileFileIsNull=FALSE;
  4790. while(fscanf(fptr1, "%s", word) != EOF)
  4791. {
  4792. if(strcmp(word, "chargingProfileId") == 0)
  4793. {
  4794. n_chargingProfile = n_chargingProfile + 1;
  4795. }
  4796. }
  4797. rewind(fptr1);
  4798. //search Charging Profile Element
  4799. int i = 0;
  4800. int j = 0;
  4801. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4802. //DEBUG_INFO(" 1-1\n");
  4803. #if 0
  4804. /***********connectorId****************/
  4805. c = 0;
  4806. loc = strstr(sLineWord, "connectorId");
  4807. memset(sstr ,0, sizeof(sstr) );
  4808. while (loc[strlen("connectorId")+2+c] != ',')
  4809. {
  4810. sstr[c] = loc[strlen("connectorId")+2+c];
  4811. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4812. c++;
  4813. }
  4814. sstr[c] = '\0';
  4815. tempconnectorIdInt = atoi(sstr);
  4816. #endif
  4817. //***********validFrom**************/
  4818. c = 0;
  4819. loc = strstr(sLineWord, "validFrom");
  4820. if(loc != NULL)
  4821. {
  4822. memset(sstr ,0, sizeof(sstr) );
  4823. while (loc[3+strlen("validFrom")+c] != '\"')
  4824. {
  4825. sstr[c] = loc[3+strlen("validFrom")+c];
  4826. c++;
  4827. }
  4828. sstr[c] = '\0';
  4829. strcpy(tempvalidFromStr,sstr);
  4830. }
  4831. else
  4832. {
  4833. strcpy(tempvalidFromStr,"");
  4834. }
  4835. //***********validFrom**************/
  4836. c = 0;
  4837. loc = strstr(sLineWord, "duration");
  4838. if(loc != NULL)
  4839. {
  4840. memset(sstr ,0, sizeof(sstr) );
  4841. while (loc[2+strlen("duration")+c] != ',')
  4842. {
  4843. sstr[c] = loc[2+strlen("duration")+c];
  4844. c++;
  4845. }
  4846. sstr[c] = '\0';
  4847. tempdurationInt = atoi(sstr);
  4848. }
  4849. else
  4850. {
  4851. tempdurationInt = 0;
  4852. }
  4853. //**********startSchedule**********/
  4854. c = 0;
  4855. loc = strstr(sLineWord, "startSchedule");
  4856. memset(sstr ,0, sizeof(sstr) );
  4857. while (loc[3+strlen("startSchedule")+c] != '\"')
  4858. {
  4859. sstr[c] = loc[3+strlen("startSchedule")+c];
  4860. c++;
  4861. }
  4862. sstr[c] = '\0';
  4863. strcpy(tempstartScheduleStr, sstr);
  4864. strcpy(TxDefaultProfileScheduleStr, sstr);
  4865. //**********chargingRateUnit**********/
  4866. c = 0;
  4867. loc = strstr(sLineWord, "chargingRateUnit");
  4868. memset(sstr ,0, sizeof(sstr) );
  4869. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4870. {
  4871. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4872. c++;
  4873. }
  4874. sstr[c] = '\0';
  4875. strcpy(tempchargingRateUnitStr, sstr);
  4876. //**********minChargingRate*******/
  4877. c = 0;
  4878. loc = strstr(sLineWord, "minChargingRate");
  4879. if(loc != NULL)
  4880. {
  4881. memset(sstr ,0, sizeof(sstr) );
  4882. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4883. {
  4884. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4885. c++;
  4886. }
  4887. sstr[c] = '\0';
  4888. tempminChargingRateFloat = atof(sstr);
  4889. }
  4890. else
  4891. {
  4892. tempminChargingRateFloat = 0.0;
  4893. }
  4894. #if 0
  4895. //
  4896. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4897. tp.tm_isdst = -1;
  4898. time_t utc = mktime(&tp);
  4899. time_t t = time(NULL);
  4900. //diff_t = difftime(t, utc);
  4901. #endif
  4902. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4903. //parsing strings to words
  4904. i = 0;
  4905. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4906. loc = loc+3+strlen("chargingSchedulePeriod");
  4907. pch = strtok(loc ,"{");
  4908. while (pch != NULL)
  4909. {
  4910. strcpy(SchedulePeriodList[i], pch);
  4911. pch = strtok (NULL, "{");
  4912. i = i + 1;
  4913. }
  4914. n_SchedulePeriods = i;
  4915. for(int i=0;i<n_SchedulePeriods;i++)
  4916. {
  4917. //*************startPeriod****************/
  4918. c = 0;
  4919. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4920. memset(sstr ,0, sizeof(sstr) );
  4921. while (loc[strlen("startPeriod")+2+c] != ',')
  4922. {
  4923. sstr[c] = loc[strlen("startPeriod")+2+c];
  4924. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4925. c++;
  4926. }
  4927. sstr[c] = '\0';
  4928. tempStartPeriodInt = atoi(sstr);
  4929. //*************limit****************/
  4930. c = 0;
  4931. loc = strstr(SchedulePeriodList[i], "limit");
  4932. memset(sstr ,0, sizeof(sstr) );
  4933. while (loc[strlen("limit")+2+c] != ',')
  4934. {
  4935. sstr[c] = loc[strlen("limit")+2+c];
  4936. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4937. c++;
  4938. }
  4939. sstr[c] = '\0';
  4940. tempLimitInt = atof(sstr);
  4941. //*************numberPhases****************/
  4942. c = 0;
  4943. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4944. memset(sstr ,0, sizeof(sstr) );
  4945. while (loc[strlen("numberPhases")+2+c] != '}')
  4946. {
  4947. sstr[c] = loc[strlen("numberPhases")+2+c];
  4948. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4949. c++;
  4950. }
  4951. sstr[c] = '\0';
  4952. tempNumberPhasesInt = atoi(sstr);
  4953. if(j == 0)
  4954. {
  4955. TxDefaultProfile.Duration = tempdurationInt;
  4956. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4957. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4958. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4959. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4960. }
  4961. else
  4962. {
  4963. //other stack level charging Profile
  4964. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4965. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4966. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4967. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4968. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4969. }
  4970. }
  4971. if(MinChargingRate < tempminChargingRateFloat)
  4972. MinChargingRate = tempminChargingRateFloat;
  4973. if(confirmPeriods < n_SchedulePeriods)
  4974. confirmPeriods = n_SchedulePeriods;
  4975. j = j + 1;
  4976. //DEBUG_INFO(" 1-2\n");
  4977. }
  4978. fclose(fptr1);
  4979. //Stacking Charging Profiles
  4980. for(int l=0; l <(j-1) ;l++)
  4981. {
  4982. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4983. {
  4984. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4985. {
  4986. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4987. {
  4988. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4989. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4990. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4991. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4992. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4993. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4994. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4995. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4996. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4997. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4998. }
  4999. else
  5000. {
  5001. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5002. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5003. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5004. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5005. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5006. }
  5007. }
  5008. }
  5009. }
  5010. //end of Stacking Charging Profiles
  5011. }
  5012. }// the end of ACCESS TxDefaultProfile
  5013. //****************************TxProfile************************************************/
  5014. switch(connectorIdInt)
  5015. {
  5016. case 0:
  5017. break;
  5018. case 1:
  5019. strcpy(fname, TxProfile_1_JSON );
  5020. break;
  5021. case 2:
  5022. strcpy(fname, TxProfile_2_JSON );
  5023. break;
  5024. default:
  5025. strcpy(fname, TxProfile_1_JSON );
  5026. break;
  5027. }
  5028. TxProfileIsNull=TRUE;
  5029. if((access(fname,F_OK))!=-1)
  5030. {
  5031. fptr1 = fopen(fname, "r");
  5032. c = 0;
  5033. c = fgetc(fptr1);
  5034. //DEBUG_INFO("c:%d\n",c);
  5035. rewind(fptr1);
  5036. if(c == EOF)
  5037. {
  5038. DEBUG_INFO("\n End of file reached.");
  5039. TxProfileIsNull=TRUE;
  5040. fclose(fptr1);
  5041. }
  5042. else
  5043. {
  5044. TxProfileIsNull=FALSE;
  5045. while(fscanf(fptr1, "%s", word) != EOF)
  5046. {
  5047. if(strcmp(word, "chargingProfileId") == 0)
  5048. {
  5049. n_chargingProfile = n_chargingProfile + 1;
  5050. }
  5051. }
  5052. rewind(fptr1);
  5053. //search Charging Profile Element
  5054. int i= 0;
  5055. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5056. #if 0
  5057. /***********connectorId****************/
  5058. c = 0;
  5059. loc = strstr(sLineWord, "connectorId");
  5060. memset(sstr ,0, sizeof(sstr) );
  5061. while (loc[strlen("connectorId")+2+c] != ',')
  5062. {
  5063. sstr[c] = loc[strlen("connectorId")+2+c];
  5064. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5065. c++;
  5066. }
  5067. sstr[c] = '\0';
  5068. tempconnectorIdInt = atoi(sstr);
  5069. #endif
  5070. //***********validFrom**************/
  5071. c = 0;
  5072. loc = strstr(sLineWord, "validFrom");
  5073. if(loc != NULL)
  5074. {
  5075. memset(sstr ,0, sizeof(sstr) );
  5076. while (loc[3+strlen("validFrom")+c] != '\"')
  5077. {
  5078. sstr[c] = loc[3+strlen("validFrom")+c];
  5079. c++;
  5080. }
  5081. sstr[c] = '\0';
  5082. strcpy(tempvalidFromStr,sstr);
  5083. }
  5084. else
  5085. {
  5086. strcpy(tempvalidFromStr,"");
  5087. }
  5088. //**********startSchedule**********/
  5089. c = 0;
  5090. loc = strstr(sLineWord, "startSchedule");
  5091. memset(sstr ,0, sizeof(sstr) );
  5092. while (loc[3+strlen("startSchedule")+c] != '\"')
  5093. {
  5094. sstr[c] = loc[3+strlen("startSchedule")+c];
  5095. c++;
  5096. }
  5097. sstr[c] = '\0';
  5098. strcpy(tempstartScheduleStr, sstr);
  5099. strcpy(TxProfileScheduleStr, sstr);
  5100. //**********chargingRateUnit**********/
  5101. c = 0;
  5102. loc = strstr(sLineWord, "chargingRateUnit");
  5103. memset(sstr ,0, sizeof(sstr) );
  5104. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5105. {
  5106. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5107. c++;
  5108. }
  5109. sstr[c] = '\0';
  5110. strcpy(tempchargingRateUnitStr, sstr);
  5111. //**********minChargingRate*******/
  5112. c = 0;
  5113. loc = strstr(sLineWord, "minChargingRate");
  5114. if(loc != NULL)
  5115. {
  5116. memset(sstr ,0, sizeof(sstr) );
  5117. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5118. {
  5119. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5120. c++;
  5121. }
  5122. sstr[c] = '\0';
  5123. tempminChargingRateFloat = atof(sstr);
  5124. }
  5125. else
  5126. {
  5127. tempminChargingRateFloat = 0.0;
  5128. }
  5129. #if 0
  5130. //
  5131. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5132. tp.tm_isdst = -1;
  5133. time_t utc = mktime(&tp);
  5134. time_t t = time(NULL);
  5135. //diff_t = difftime(t, utc);
  5136. #endif
  5137. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5138. //parsing strings to words
  5139. i = 0;
  5140. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5141. loc = loc+3+strlen("chargingSchedulePeriod");
  5142. pch = strtok(loc ,"{");
  5143. while (pch != NULL)
  5144. {
  5145. strcpy(SchedulePeriodList[i], pch);
  5146. pch = strtok (NULL, "{");
  5147. i = i + 1;
  5148. }
  5149. n_SchedulePeriods = i;
  5150. for(int i=0;i<n_SchedulePeriods;i++)
  5151. {
  5152. //*************startPeriod****************/
  5153. c = 0;
  5154. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5155. memset(sstr ,0, sizeof(sstr) );
  5156. while (loc[strlen("startPeriod")+2+c] != ',')
  5157. {
  5158. sstr[c] = loc[strlen("startPeriod")+2+c];
  5159. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5160. c++;
  5161. }
  5162. sstr[c] = '\0';
  5163. tempStartPeriodInt = atoi(sstr);
  5164. //*************limit****************/
  5165. c = 0;
  5166. loc = strstr(SchedulePeriodList[i], "limit");
  5167. memset(sstr ,0, sizeof(sstr) );
  5168. while (loc[strlen("limit")+2+c] != ',')
  5169. {
  5170. sstr[c] = loc[strlen("limit")+2+c];
  5171. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5172. c++;
  5173. }
  5174. sstr[c] = '\0';
  5175. tempLimitInt = atof(sstr);
  5176. //*************numberPhases****************/
  5177. c = 0;
  5178. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5179. memset(sstr ,0, sizeof(sstr) );
  5180. while (loc[strlen("numberPhases")+2+c] != '}')
  5181. {
  5182. sstr[c] = loc[strlen("numberPhases")+2+c];
  5183. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5184. c++;
  5185. }
  5186. sstr[c] = '\0';
  5187. tempNumberPhasesInt = atoi(sstr);
  5188. TxProfile.Duration = durationInt;
  5189. TxProfile.TotalPeriod = n_SchedulePeriods;
  5190. TxProfile.Period[i].Limit = tempLimitInt;
  5191. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5192. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5193. }
  5194. if(MinChargingRate < tempminChargingRateFloat)
  5195. MinChargingRate = tempminChargingRateFloat;
  5196. if(confirmPeriods < n_SchedulePeriods)
  5197. confirmPeriods = n_SchedulePeriods;
  5198. }
  5199. fclose(fptr1);
  5200. }
  5201. }// the end of ACCESS TxProfile
  5202. //CompositeSchedule
  5203. int period=0;
  5204. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5205. {
  5206. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5207. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5208. {
  5209. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5210. {
  5211. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5212. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5213. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5214. period = period + 1;
  5215. }
  5216. else
  5217. {
  5218. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5219. {
  5220. }
  5221. else
  5222. {
  5223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5224. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5226. period = period + 1;
  5227. }
  5228. }
  5229. }
  5230. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5231. {
  5232. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5233. {
  5234. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5235. {
  5236. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5237. }
  5238. else
  5239. {
  5240. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5241. }
  5242. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5243. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5244. period = period + 1;
  5245. }
  5246. }
  5247. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5248. {
  5249. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5250. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5251. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5252. period = period + 1;
  5253. }
  5254. }
  5255. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5256. {
  5257. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5258. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5259. {
  5260. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5261. {
  5262. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5263. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5264. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5265. period = period + 1;
  5266. }
  5267. else
  5268. {
  5269. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5270. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5271. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5272. period = period + 1;
  5273. }
  5274. }
  5275. }
  5276. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5277. {
  5278. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5279. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5280. {
  5281. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5282. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5283. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5284. period = period + 1;
  5285. }
  5286. }
  5287. confirmPeriods = period;
  5288. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5289. //* Define temporary variables */
  5290. struct tm *gtime;
  5291. time_t now;
  5292. char buf[28];
  5293. //* Read the current system time */
  5294. time(&now);
  5295. //* Convert the system time to GMT (now UTC) */
  5296. gtime = gmtime(&now);
  5297. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5298. // make .conf
  5299. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5300. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5301. //DEBUG_INFO(" debug 11\n");
  5302. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5303. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5304. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5305. }
  5306. else
  5307. {
  5308. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5309. }
  5310. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5311. return result;
  5312. }
  5313. int handleGetConfigurationRequest(char *uuid, char *payload)
  5314. {
  5315. mtrace();
  5316. int result = FAIL;
  5317. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5318. //struct json_object *jsonitem;
  5319. int MaxKeySupported = 0;
  5320. int n_keys = 0;
  5321. char requestKey[43][50]={0};
  5322. char search[]="[";
  5323. char sstr[500]={ 0 };
  5324. //int pos;
  5325. int l, c = 0;
  5326. int i = 0;
  5327. char *delim = "\",\"";
  5328. char * pch;
  5329. char *loc = strstr(payload, search);
  5330. //********************* Parsing String ***********************************/
  5331. if(loc == NULL) {
  5332. DEBUG_INFO("no key match in Configuration \n");
  5333. }
  5334. else {
  5335. //pos = loc - payload;
  5336. l = strlen(loc)-4;
  5337. while (c < l)
  5338. {
  5339. sstr[c] = loc[c+2];
  5340. c++;
  5341. }
  5342. sstr[c] = '\0';
  5343. //parsing strings to words
  5344. pch = strtok(sstr,delim);
  5345. if(pch == NULL)
  5346. {
  5347. strcpy(requestKey[0], sstr);
  5348. }
  5349. else
  5350. {
  5351. while (pch != NULL)
  5352. {
  5353. strcpy(requestKey[i], pch);
  5354. pch = strtok (NULL, delim);
  5355. i = i + 1;
  5356. }
  5357. n_keys = i;
  5358. }
  5359. }
  5360. UnknownKeynum = 0;
  5361. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5362. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5363. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5364. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5365. if(n_keys != 0)
  5366. {
  5367. for(int i=0;i<n_keys;i++)
  5368. {
  5369. getKeyValue(requestKey[i]);
  5370. //json_object_put(jsonitem);
  5371. }
  5372. }
  5373. else
  5374. {
  5375. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5376. getKeyValue("");
  5377. }
  5378. processUnkownKey();
  5379. sendGetConfigurationConfirmation(uuid);
  5380. return result;
  5381. }
  5382. static char GetDiagnosticspayloadData[300]={0};
  5383. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5384. {
  5385. mtrace();
  5386. int result = FAIL;
  5387. //void *ret; //
  5388. char fnamePlusPath[100]="";
  5389. char fname[40]="";
  5390. pthread_t t; // pthread 變數
  5391. time_t rawtime;
  5392. struct tm * timeinfo;
  5393. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5394. system("exec /root/logPackTools 'log' 6");
  5395. //char buffer [128];
  5396. time (&rawtime);
  5397. //printf("%ld\n", rawtime);
  5398. timeinfo = localtime (&rawtime);
  5399. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5400. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5401. if((access(fnamePlusPath,F_OK))!=-1)
  5402. {
  5403. DEBUG_INFO("fnamePlusPath exist.\n");
  5404. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5405. }
  5406. else
  5407. {
  5408. DEBUG_INFO("fnamePlusPath not exist!\n");
  5409. }
  5410. memset(GetDiagnosticspayloadData, 0, 300);
  5411. strcpy(GetDiagnosticspayloadData, payload);
  5412. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5413. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5414. // pthread_join(t, NULL/*&ret*/);
  5415. return result;
  5416. }
  5417. void* GetDiagnosticsProcess(void* data)
  5418. {
  5419. pthread_detach(pthread_self());
  5420. mtrace();
  5421. int retriesInt=0, retryIntervalInt=0;
  5422. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5423. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5424. 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};
  5425. int port=0;
  5426. char fnamePlusPath[100]="";//="00000_2019-06-09_160902_CSULog.zip";
  5427. char fname[40]="";
  5428. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5429. int c = 0;
  5430. char *loc;
  5431. int isSuccess = FALSE;
  5432. char ftpbuf[200]={0};
  5433. //char temp[100]={0};
  5434. char * pch;
  5435. // [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"}]
  5436. //char *str = (char*) data; // ? ?輸入資 ?
  5437. char str[300]={ 0 };
  5438. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5439. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5440. DEBUG_INFO("GetDiagnosticsProcess\n");
  5441. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5442. //****************location*******************/
  5443. c = 0;
  5444. memset(sstr ,0, sizeof(sstr) );
  5445. loc = strstr(str, "location");
  5446. while (loc[3+strlen("location")+c] != '\"')
  5447. {
  5448. sstr[c] = loc[3+strlen("location")+c];
  5449. c++;
  5450. }
  5451. sstr[c] = '\0';
  5452. strcpy(locationstr,sstr);
  5453. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5454. if(strcmp(locationstr,"")==0)
  5455. {
  5456. DEBUG_INFO("location is <Empty>!\n");
  5457. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5458. goto end;
  5459. }
  5460. //****************retries*******************/
  5461. c = 0;
  5462. loc = strstr(str, "retries");
  5463. if(loc == NULL)
  5464. {
  5465. retriesIsNULL = TRUE;
  5466. }
  5467. else
  5468. {
  5469. while (loc[strlen("retries")+2+c] != ',')
  5470. {
  5471. sstr[c] = loc[strlen("retries")+2+c];
  5472. c++;
  5473. }
  5474. sstr[c] = '\0';
  5475. retriesInt = atoi(sstr);
  5476. }
  5477. if(retriesIsNULL == TRUE)
  5478. {
  5479. retriesInt = 0;
  5480. }
  5481. //****************retryInterval*******************/
  5482. c = 0;
  5483. loc = strstr(str, "retryInterval");
  5484. if(loc == NULL)
  5485. {
  5486. retryIntervalIsNULL = TRUE;
  5487. }
  5488. else
  5489. {
  5490. while (loc[strlen("retryInterval")+2+c] != ',')
  5491. {
  5492. sstr[c] = loc[strlen("retryInterval")+2+c];
  5493. c++;
  5494. }
  5495. sstr[c] = '\0';
  5496. retryIntervalInt = atoi(sstr);
  5497. }
  5498. //****************startTime*******************/
  5499. c = 0;
  5500. memset(sstr ,0, sizeof(sstr) );
  5501. loc = strstr(str, "startTime");
  5502. if(loc == NULL)
  5503. {
  5504. startTimeIsNULL = TRUE;
  5505. }
  5506. else
  5507. {
  5508. while (loc[3+strlen("startTime")+c] != '\"')
  5509. {
  5510. sstr[c] = loc[3+strlen("startTime")+c];
  5511. c++;
  5512. }
  5513. sstr[c] = '\0';
  5514. strcpy(startTimestr,sstr);
  5515. }
  5516. //****************stopTime*******************/
  5517. c = 0;
  5518. memset(sstr ,0, sizeof(sstr) );
  5519. loc = strstr(str, "stopTime");
  5520. if(loc == NULL)
  5521. {
  5522. stopTimeIsNULL = TRUE;
  5523. }
  5524. else
  5525. {
  5526. while (loc[3+strlen("stopTime")+c] != '\"')
  5527. {
  5528. sstr[c] = loc[3+strlen("stopTime")+c];
  5529. c++;
  5530. }
  5531. sstr[c] = '\0';
  5532. strcpy(stopTimestr,sstr);
  5533. }
  5534. memset(protocol, 0, sizeof(protocol));
  5535. memset(user, 0, sizeof(user) );
  5536. memset(password, 0, sizeof(password));
  5537. memset(host, 0, sizeof(host));
  5538. memset(path, 0, sizeof(path));
  5539. memset(ftppath, 0, sizeof(ftppath));
  5540. memset(host1, 0, sizeof(host1));
  5541. memset(path1, 0, sizeof(path1));
  5542. /*location: ftp://user:password@host:port/path*/
  5543. time_t rawtime;
  5544. struct tm * timeinfo;
  5545. //char buffer [128];
  5546. time (&rawtime);
  5547. //printf("%ld\n", rawtime);
  5548. timeinfo = localtime (&rawtime);
  5549. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5550. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5551. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5552. if((access(fnamePlusPath,F_OK))!=-1)
  5553. {
  5554. DEBUG_INFO("fnamePlusPath exist.\n");
  5555. }
  5556. else
  5557. {
  5558. DEBUG_INFO("fnamePlusPath not exist!\n");
  5559. goto end;
  5560. }
  5561. pch=strchr(locationstr,'@');
  5562. if(pch==NULL)
  5563. {
  5564. sscanf(locationstr,
  5565. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5566. protocol, host, &port, path);
  5567. strcpy(user,"anonymous");
  5568. strcpy(password,"");
  5569. }
  5570. else
  5571. {
  5572. DEBUG_INFO("pch=%s\n", pch);
  5573. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5574. protocol, user, password, host, &port, path);
  5575. }
  5576. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5577. {
  5578. DEBUG_INFO("protocol is not ftp/http ! \n");
  5579. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5580. goto end;
  5581. }
  5582. if(strncmp(locationstr,"http", 4) == 0)
  5583. {
  5584. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5585. protocol, host, path);
  5586. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5587. // protocol, user, password, host, path);
  5588. sprintf(ftppath,"/%s", path);
  5589. //DEBUG_INFO("protocol =%s\n",protocol);
  5590. //DEBUG_INFO("host =%s\n",host);
  5591. //DEBUG_INFO("path =%s\n",path);
  5592. //DEBUG_INFO("ftppath=%s\n",ftppath);
  5593. //int ftppathlen=strlen(ftppath);
  5594. //int i=1;
  5595. //char filenametemp[50];
  5596. //while(i < ftppathlen)
  5597. //{
  5598. // int len=ftppathlen-i;
  5599. // if(ftppath[len]== 47) // '/' ascll code: 47
  5600. // {
  5601. // DEBUG_INFO("compare '/' all right\n");
  5602. // break;
  5603. // }
  5604. // i=i+1;
  5605. //}
  5606. //memset(filenametemp, 0, sizeof(filenametemp));
  5607. //strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5608. //filenametemp[i+1] = 0;
  5609. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5610. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5611. strftime (fnamePlusPath,sizeof(fnamePlusPath),"/mnt/%4Y-%2m.zip",timeinfo);
  5612. do{
  5613. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);//httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5614. sleep(retryIntervalInt);
  5615. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5616. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5617. if(!isSuccess)
  5618. {
  5619. //BulldogUtil.sleepMs(interval*1000);
  5620. DEBUG_INFO("Diagnostics fail.\n");
  5621. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5622. }
  5623. else
  5624. {
  5625. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5626. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5627. //isUpdateRequest = TRUE;
  5628. }
  5629. }
  5630. else
  5631. {
  5632. sscanf(host,"%[^/]%s",host1, path1);
  5633. sprintf(ftppath,"%s", path1);
  5634. DEBUG_INFO("protocol =%s\n",protocol);
  5635. DEBUG_INFO("user =%s\n",user);
  5636. DEBUG_INFO("password =%s\n",password);
  5637. DEBUG_INFO("host1 =%s\n",host1);
  5638. DEBUG_INFO("port =%d\n",port);
  5639. DEBUG_INFO("path1 =%s\n",path1);
  5640. DEBUG_INFO("ftppath=%s\n",ftppath);
  5641. int ftppathlen=strlen(ftppath);
  5642. int i=1;
  5643. char filenametemp[50];
  5644. while(i < ftppathlen)
  5645. {
  5646. int len=ftppathlen-i;
  5647. if(ftppath[len]== 47) // '/' ascll code: 47
  5648. {
  5649. DEBUG_INFO("find '/' all right\n");
  5650. break;
  5651. }
  5652. i=i+1;
  5653. }
  5654. memset(filenametemp, 0, sizeof(filenametemp));
  5655. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5656. filenametemp[i+1] = 0;
  5657. memset(ftpbuf, 0, sizeof(ftpbuf));
  5658. if(port == 0)
  5659. port = 21;
  5660. do{
  5661. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5662. sleep(retryIntervalInt);
  5663. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5664. if(!isSuccess)
  5665. {
  5666. //BulldogUtil.sleepMs(interval*1000);
  5667. DEBUG_INFO("Diagnostics fail.\n");
  5668. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5669. }
  5670. else
  5671. {
  5672. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5673. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5674. //isUpdateRequest = TRUE;
  5675. }
  5676. }
  5677. end:
  5678. // json_object_put(obj);
  5679. DiagnosticsStatusNotificationStatus = 0; //Idle
  5680. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5681. }
  5682. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5683. {
  5684. mtrace();
  5685. int result = FAIL;
  5686. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5687. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5688. {
  5689. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5690. localversion = -1;
  5691. }
  5692. else
  5693. {
  5694. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5695. OCPP_getListVerion();
  5696. }
  5697. //from db.OCPP_getListVerion
  5698. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5699. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5700. sendGetLocalListVersionConfirmation(uuid,"");
  5701. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5702. return result;
  5703. }
  5704. int handleRemoteStartRequest(char *uuid, char *payload)
  5705. {
  5706. mtrace();
  5707. int result = FAIL;
  5708. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5709. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5710. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5711. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5712. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5713. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5714. int chargingSchedulePeriodCount = 0;
  5715. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5716. int c = 0;
  5717. char *loc;
  5718. char comfirmstr[20]={0};
  5719. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5720. if(server_pending == TRUE)
  5721. {
  5722. return 0;
  5723. }
  5724. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5725. //**********connectorId****************/
  5726. c = 0;
  5727. memset(sstr ,0, sizeof(sstr) );
  5728. loc = strstr(payload, "connectorId");
  5729. if(loc == NULL)
  5730. {
  5731. connectorIdIsNULL = TRUE;
  5732. }
  5733. else
  5734. {
  5735. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5736. {
  5737. sstr[c] = loc[strlen("connectorId")+2+c];
  5738. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5739. c++;
  5740. }
  5741. sstr[c] = '\0';
  5742. connectorIdInt = atoi(sstr);
  5743. }
  5744. if(connectorIdIsNULL == TRUE) // need to discussion
  5745. {
  5746. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5747. goto end;
  5748. }
  5749. //****************idTag*******************/
  5750. c = 0;
  5751. memset(sstr ,0, sizeof(sstr) );
  5752. loc = strstr(payload, "idTag");
  5753. while (loc[3+strlen("idTag")+c] != '\"')
  5754. {
  5755. sstr[c] = loc[3+strlen("idTag")+c];
  5756. c++;
  5757. }
  5758. sstr[c] = '\0';
  5759. strcpy(idTagstr,sstr);
  5760. //****************chargingProfile*******************/
  5761. c = 0;
  5762. memset(sstr ,0, sizeof(sstr) );
  5763. loc = strstr(payload, "chargingProfile");
  5764. if(loc == NULL)
  5765. {
  5766. chargingProfileIsNULL = TRUE;
  5767. }
  5768. else
  5769. {
  5770. //****************chargingProfileId*******************/
  5771. c=0;
  5772. loc = strstr(payload, "chargingProfileId");
  5773. memset(sstr ,0, sizeof(sstr) );
  5774. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5775. {
  5776. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5777. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5778. c++;
  5779. }
  5780. sstr[c] = '\0';
  5781. chargingProfileIdInt = atoi(sstr);
  5782. //****************transactionId*******************/
  5783. loc = strstr(payload, "transactionId");
  5784. if(loc == NULL)
  5785. {
  5786. transactionIdIsNULL = TRUE;
  5787. }
  5788. else
  5789. {
  5790. c=0;
  5791. memset(sstr ,0, sizeof(sstr) );
  5792. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5793. {
  5794. sstr[c] = loc[strlen("transactionId")+2+c];
  5795. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5796. c++;
  5797. }
  5798. sstr[c] = '\0';
  5799. transactionIdInt = atoi(sstr);
  5800. }
  5801. //****************stackLevel*******************/
  5802. c=0;
  5803. loc = strstr(payload, "stackLevel");
  5804. memset(sstr ,0, sizeof(sstr) );
  5805. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5806. {
  5807. sstr[c] = loc[strlen("stackLevel")+2+c];
  5808. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5809. c++;
  5810. }
  5811. sstr[c] = '\0';
  5812. stackLevelInt = atoi(sstr);
  5813. //****************chargingProfilePurpose*******************/
  5814. c = 0;
  5815. memset(sstr ,0, sizeof(sstr) );
  5816. loc = strstr(payload, "chargingProfilePurpose");
  5817. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5818. {
  5819. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5820. c++;
  5821. }
  5822. sstr[c] = '\0';
  5823. strcpy(chargingProfilePurposestr,sstr);
  5824. //****************chargingProfileKind*******************/
  5825. c = 0;
  5826. memset(sstr ,0, sizeof(sstr) );
  5827. loc = strstr(payload, "chargingProfileKind");
  5828. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5829. {
  5830. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5831. c++;
  5832. }
  5833. sstr[c] = '\0';
  5834. strcpy(chargingProfileKindstr,sstr);
  5835. //****************recurrencyKind*******************/
  5836. loc = strstr(payload, "recurrencyKind");
  5837. if(loc == NULL)
  5838. {
  5839. recurrencyKindIsNULL = TRUE;
  5840. }
  5841. else
  5842. {
  5843. c = 0;
  5844. memset(sstr ,0, sizeof(sstr) );
  5845. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5846. {
  5847. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5848. c++;
  5849. }
  5850. sstr[c] = '\0';
  5851. strcpy(recurrencyKindstr,sstr);
  5852. }
  5853. //****************validFrom*******************/
  5854. loc = strstr(payload, "validFrom");
  5855. if(loc == NULL)
  5856. {
  5857. validFromIsNULL = TRUE;
  5858. }
  5859. else
  5860. {
  5861. c = 0;
  5862. memset(sstr ,0, sizeof(sstr) );
  5863. while (loc[3+strlen("validFrom")+c] != '\"')
  5864. {
  5865. sstr[c] = loc[3+strlen("validFrom")+c];
  5866. c++;
  5867. }
  5868. sstr[c] = '\0';
  5869. strcpy(validFromstr,sstr);
  5870. }
  5871. //****************validTo*******************/
  5872. loc = strstr(payload, "validTo");
  5873. if(loc == NULL)
  5874. {
  5875. validToIsNULL = TRUE;
  5876. }
  5877. else
  5878. {
  5879. c = 0;
  5880. memset(sstr ,0, sizeof(sstr) );
  5881. while (loc[3+strlen("validTo")+c] != '\"')
  5882. {
  5883. sstr[c] = loc[3+strlen("validTo")+c];
  5884. c++;
  5885. }
  5886. sstr[c] = '\0';
  5887. strcpy(validTostr,sstr);
  5888. }
  5889. //****************chargingSchedule*******************/
  5890. loc = strstr(payload, "chargingSchedule");
  5891. if(loc != NULL)
  5892. {
  5893. //****************duration*******************/
  5894. loc = strstr(payload, "duration");
  5895. if(loc == NULL)
  5896. {
  5897. durationIsNULL = TRUE;
  5898. }
  5899. else
  5900. {
  5901. c=0;
  5902. memset(sstr ,0, sizeof(sstr) );
  5903. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5904. {
  5905. sstr[c] = loc[strlen("duration")+2+c];
  5906. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5907. c++;
  5908. }
  5909. sstr[c] = '\0';
  5910. durationInt = atoi(sstr);
  5911. }
  5912. //****************startSchedule******************/
  5913. loc = strstr(payload, "startSchedule");
  5914. if(loc == NULL)
  5915. {
  5916. startScheduleIsNULL = TRUE;
  5917. }
  5918. else
  5919. {
  5920. c = 0;
  5921. memset(sstr ,0, sizeof(sstr) );
  5922. while (loc[3+strlen("startSchedule")+c] != '\"')
  5923. {
  5924. sstr[c] = loc[3+strlen("startSchedule")+c];
  5925. c++;
  5926. }
  5927. sstr[c] = '\0';
  5928. strcpy(startSchedulestr,sstr);
  5929. }
  5930. //****************chargingRateUnit*******************/
  5931. c = 0;
  5932. memset(sstr ,0, sizeof(sstr) );
  5933. loc = strstr(payload, "chargingRateUnit");
  5934. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5935. {
  5936. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5937. c++;
  5938. }
  5939. sstr[c] = '\0';
  5940. strcpy(chargingRateUnitstr,sstr);
  5941. //****************minChargingRate*******************/
  5942. loc = strstr(payload, "minChargingRate");
  5943. if(loc == NULL)
  5944. {
  5945. minChargingRateIsNULL = TRUE;
  5946. }
  5947. else
  5948. {
  5949. c=0;
  5950. memset(sstr ,0, sizeof(sstr) );
  5951. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5952. {
  5953. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5955. c++;
  5956. }
  5957. sstr[c] = '\0';
  5958. minChargingRateflaot = atof(sstr);
  5959. }
  5960. //****************chargingSchedulePeriod count*******************/
  5961. int what_len = strlen("startPeriod");
  5962. char *where = payload;
  5963. while ((where = strstr(where, "startPeriod"))) {
  5964. where += what_len;
  5965. chargingSchedulePeriodCount++;
  5966. }
  5967. where = payload;
  5968. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5969. {
  5970. //****************startPeriod*******************/
  5971. c=0;
  5972. loc = strstr(where, "startPeriod");
  5973. memset(sstr ,0, sizeof(sstr) );
  5974. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5975. {
  5976. sstr[c] = loc[strlen("startPeriod")+2+c];
  5977. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5978. c++;
  5979. }
  5980. sstr[c] = '\0';
  5981. startPeriodInt[periodNums] = atoi(sstr);
  5982. //****************limit*******************/
  5983. c=0;
  5984. loc = strstr(where, "limit");
  5985. memset(sstr ,0, sizeof(sstr) );
  5986. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5987. {
  5988. sstr[c] = loc[strlen("limit")+2+c];
  5989. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5990. c++;
  5991. }
  5992. sstr[c] = '\0';
  5993. limitflaot[periodNums] = atof(sstr);
  5994. //****************numberPhases*******************/
  5995. loc = strstr(where, "numberPhases");
  5996. if(loc == NULL)
  5997. {
  5998. numberPhasesIsNULL = TRUE;
  5999. }
  6000. else
  6001. {
  6002. c=0;
  6003. memset(sstr ,0, sizeof(sstr) );
  6004. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6005. {
  6006. sstr[c] = loc[strlen("numberPhases")+2+c];
  6007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6008. c++;
  6009. }
  6010. sstr[c] = '\0';
  6011. numberPhasesInt[periodNums] = atoi(sstr);
  6012. }
  6013. where = loc;
  6014. }
  6015. }
  6016. }
  6017. /*
  6018. enum _SYSTEM_STATUS
  6019. {
  6020. S_BOOTING = 0,
  6021. S_IDLE, = 1
  6022. S_AUTHORIZING, =2
  6023. S_REASSIGN_CHECK, =3
  6024. S_REASSIGN, =4
  6025. S_PRECHARGE, =5
  6026. S_PREPARING_FOR_EV, =6
  6027. S_PREPARING_FOR_EVSE, =7
  6028. S_CHARGING, =8
  6029. S_TERMINATING, =9
  6030. S_COMPLETE, =10
  6031. S_ALARM, =11
  6032. S_FAULT =12
  6033. }
  6034. */
  6035. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6036. {
  6037. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6038. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6039. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6040. //check Transaction active
  6041. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6042. {
  6043. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6044. {
  6045. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6046. {
  6047. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6048. {
  6049. //Reserved
  6050. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6051. }
  6052. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6053. {
  6054. //Reserved
  6055. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6056. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6057. goto end;
  6058. }
  6059. else
  6060. {
  6061. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6062. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6063. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6064. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6065. {
  6066. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6067. goto end;
  6068. }
  6069. }//END FOR ELSE
  6070. }
  6071. }// END FOR CHAdeMO_QUANTITY
  6072. for (int index = 0; index < CCS_QUANTITY; index++)
  6073. {
  6074. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6075. {
  6076. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6077. {
  6078. //Reserved
  6079. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6080. }
  6081. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6082. {
  6083. //Reserved
  6084. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6085. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6086. goto end;
  6087. }
  6088. else
  6089. {
  6090. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6091. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6092. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6093. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6094. {
  6095. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6096. goto end;
  6097. }
  6098. }// END FOR ELSE
  6099. }
  6100. }// END FOR CCS_QUANTITY
  6101. for (int index = 0; index < GB_QUANTITY; index++)
  6102. {
  6103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6104. {
  6105. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6106. {
  6107. //Reserved
  6108. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6109. }
  6110. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6111. {
  6112. //Reserved
  6113. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6114. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6115. goto end;
  6116. }
  6117. else
  6118. {
  6119. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6120. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6121. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6122. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6123. {
  6124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6125. goto end;
  6126. }
  6127. }// END FOR ELSE
  6128. }
  6129. } // END FOR GB_QUANTITY
  6130. }
  6131. else
  6132. {
  6133. for (int index = 0; index < AC_QUANTITY; index++)
  6134. {
  6135. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6136. {
  6137. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6138. {
  6139. //Reserved
  6140. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6141. }
  6142. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6143. {
  6144. //Reserved
  6145. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6146. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6147. goto end;
  6148. }
  6149. else
  6150. {
  6151. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6152. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6153. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6154. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6155. {
  6156. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6157. goto end;
  6158. }
  6159. }//END FOR ELSE
  6160. }
  6161. }// END FOR AC_QUANTITY
  6162. }
  6163. if(chargingProfileIsNULL == FALSE)
  6164. {
  6165. //ChargingProfile
  6166. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6167. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6168. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6169. if(recurrencyKindIsNULL == FALSE) //OPTION
  6170. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6172. if(transactionIdIsNULL == FALSE) // OPTION
  6173. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6174. if(validFromIsNULL == FALSE) // OPTION
  6175. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6176. if(validToIsNULL == FALSE) //OPTION
  6177. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6178. //ChargingSchedule
  6179. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6180. if(durationIsNULL == FALSE) //OPTION
  6181. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6182. if(minChargingRateIsNULL == FALSE) //OPTION
  6183. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6184. if(startScheduleIsNULL == FALSE) //OPTION
  6185. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6186. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6187. {
  6188. //ChargingSchedulePeriod
  6189. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6190. if(numberPhasesIsNULL == FALSE)
  6191. {
  6192. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6193. }
  6194. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6195. }
  6196. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6197. {
  6198. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6199. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6200. //memset idTag
  6201. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6202. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6203. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6204. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6205. }
  6206. else
  6207. {
  6208. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6209. }
  6210. }
  6211. else
  6212. {
  6213. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6215. //memset idTag
  6216. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6217. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6218. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6219. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6220. }
  6221. }
  6222. else
  6223. {
  6224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6225. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6226. }
  6227. end:
  6228. if(connectorIdIsNULL == FALSE)
  6229. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6230. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6231. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6232. //OCPP send RemoteStartConfirmation by first.
  6233. sendRemoteStartConfirmation(uuid, comfirmstr);
  6234. return result;
  6235. }
  6236. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6237. {
  6238. mtrace();
  6239. int result = FAIL;
  6240. int match = FALSE;
  6241. int GunNO = 0;
  6242. int transactionIdInt=0;
  6243. int transactionIdIsNULL= FALSE;
  6244. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6245. int c = 0;
  6246. char *loc;
  6247. char comfirmstr[20];
  6248. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6249. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6250. if(server_pending == TRUE)
  6251. {
  6252. return 0;
  6253. }
  6254. c=0;
  6255. loc = strstr(payload, "transactionId");
  6256. if(loc == NULL)
  6257. {
  6258. transactionIdIsNULL= TRUE;
  6259. }
  6260. else
  6261. {
  6262. memset(sstr ,0, sizeof(sstr) );
  6263. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6264. {
  6265. sstr[c] = loc[strlen("transactionId")+2+c];
  6266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6267. c++;
  6268. }
  6269. sstr[c] = '\0';
  6270. transactionIdInt = atoi(sstr);
  6271. }
  6272. if(transactionIdIsNULL == FALSE)
  6273. {
  6274. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6275. {
  6276. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6277. {
  6278. //check Transaction active
  6279. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6280. {
  6281. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6282. {
  6283. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6284. {
  6285. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6286. {
  6287. match = TRUE;
  6288. GunNO = gun_index;
  6289. }
  6290. }
  6291. }// END FOR CHAdeMO_QUANTITY
  6292. for (int index = 0; index < CCS_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6295. {
  6296. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6297. {
  6298. match = TRUE;
  6299. GunNO = gun_index;
  6300. }
  6301. }
  6302. }// END FOR CCS_QUANTITY
  6303. for (int index = 0; index < GB_QUANTITY; index++)
  6304. {
  6305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6306. {
  6307. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6308. {
  6309. match = TRUE;
  6310. GunNO = gun_index;
  6311. }
  6312. }
  6313. }// END FOR GB_QUANTITY
  6314. }
  6315. else
  6316. {
  6317. for (int index = 0; index < AC_QUANTITY; index++)
  6318. {
  6319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6320. {
  6321. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6322. {
  6323. match = TRUE;
  6324. GunNO = gun_index;
  6325. }
  6326. }
  6327. }// END FOR CHAdeMO_QUANTITY
  6328. }// END FOR AC ELSE
  6329. }// CHECK IF ResponseTransactionId == transactionIdInt
  6330. }//END FOR
  6331. if( match == TRUE)
  6332. {
  6333. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6335. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6336. }
  6337. else
  6338. {
  6339. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6340. }
  6341. }
  6342. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6343. return result;
  6344. }
  6345. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6346. {
  6347. mtrace();
  6348. int result = FAIL;
  6349. int connectorIdInt=0, reservationIdInt=0;
  6350. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6351. char comfirmstr[20]={0};
  6352. char sstr[180]={ 0 };
  6353. int c = 0;
  6354. char *loc;
  6355. //char *ptr;
  6356. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6357. //***(1)connectorId ****/
  6358. c=0;
  6359. loc = strstr(payload, "connectorId");
  6360. memset(sstr ,0, sizeof(sstr) );
  6361. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6362. {
  6363. sstr[c] = loc[strlen("connectorId")+2+c];
  6364. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6365. c++;
  6366. }
  6367. sstr[c] = '\0';
  6368. connectorIdInt = atoi(sstr);
  6369. //***(2)expiryDate ****/
  6370. loc = strstr(payload, "expiryDate");
  6371. memset(sstr ,0, sizeof(sstr) );
  6372. c = 0;
  6373. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6374. {
  6375. sstr[c] = loc[3+strlen("expiryDate")+c];
  6376. c++;
  6377. }
  6378. sstr[c] = '\0';
  6379. strcpy(expiryDatestr, sstr);
  6380. //***(3)idTag ****/
  6381. loc = strstr(payload, "idTag");
  6382. memset(sstr ,0, sizeof(sstr) );
  6383. c = 0;
  6384. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6385. {
  6386. sstr[c] = loc[3+strlen("idTag")+c];
  6387. c++;
  6388. }
  6389. sstr[c] = '\0';
  6390. strcpy(idTagstr, sstr);
  6391. //***(4)parentIdTag ****/
  6392. loc = strstr(payload, "parentIdTag");
  6393. memset(sstr ,0, sizeof(sstr) );
  6394. c = 0;
  6395. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6396. {
  6397. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6398. c++;
  6399. }
  6400. sstr[c] = '\0';
  6401. strcpy(parentIdTagstr, sstr);
  6402. //***(5)reservationId ****/
  6403. c=0;
  6404. loc = strstr(payload, "reservationId");
  6405. memset(sstr ,0, sizeof(sstr) );
  6406. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6407. {
  6408. sstr[c] = loc[strlen("reservationId")+2+c];
  6409. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6410. c++;
  6411. }
  6412. sstr[c] = '\0';
  6413. reservationIdInt = atoi(sstr);
  6414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6415. /*
  6416. enum _SYSTEM_STATUS
  6417. {
  6418. S_BOOTING = 0,
  6419. S_IDLE, = 1
  6420. S_AUTHORIZING, =2
  6421. S_REASSIGN_CHECK, =3
  6422. S_REASSIGN, =4
  6423. S_PRECHARGE, =5
  6424. S_PREPARING_FOR_EV, =6
  6425. S_PREPARING_FOR_EVSE, =7
  6426. S_CHARGING, =8
  6427. S_TERMINATING, =9
  6428. S_COMPLETE, =10
  6429. S_ALARM, =11
  6430. S_FAULT =12
  6431. }
  6432. */
  6433. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6434. {
  6435. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6436. goto end;
  6437. }
  6438. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6439. {
  6440. //check Transaction active
  6441. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6442. {
  6443. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6444. {
  6445. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6446. {
  6447. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6448. {
  6449. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6451. {
  6452. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6453. {
  6454. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6456. }
  6457. 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'))
  6458. {
  6459. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6460. }
  6461. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6462. {
  6463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6464. }
  6465. else
  6466. {
  6467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6468. }
  6469. }
  6470. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6471. {
  6472. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6473. }
  6474. }
  6475. else
  6476. {
  6477. //replace reservation
  6478. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6479. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6480. }
  6481. }
  6482. } // END FOR CHAdeMO_QUANTITY
  6483. for (int index = 0; index < CCS_QUANTITY; index++)
  6484. {
  6485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6486. {
  6487. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6488. {
  6489. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6491. {
  6492. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6493. {
  6494. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6496. }
  6497. 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'))
  6498. {
  6499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6500. }
  6501. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6502. {
  6503. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6504. }
  6505. else
  6506. {
  6507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6508. }
  6509. }
  6510. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6511. {
  6512. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6513. }
  6514. }
  6515. else
  6516. {
  6517. //replace reservation
  6518. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6519. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6520. }
  6521. }
  6522. } // END FOR CCS_QUANTITY
  6523. for (int index = 0; index < GB_QUANTITY; index++)
  6524. {
  6525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6526. {
  6527. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6528. {
  6529. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6530. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6531. {
  6532. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6533. {
  6534. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6535. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6536. }
  6537. 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'))
  6538. {
  6539. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6540. }
  6541. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6542. {
  6543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6544. }
  6545. else
  6546. {
  6547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6548. }
  6549. }
  6550. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6551. {
  6552. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6553. }
  6554. }
  6555. else
  6556. {
  6557. //replace reservation
  6558. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6559. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6560. }
  6561. }
  6562. }// END FOR GB_QUANTITY
  6563. }
  6564. else
  6565. {
  6566. for (int index = 0; index < AC_QUANTITY; index++)
  6567. {
  6568. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6569. {
  6570. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6571. {
  6572. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6573. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6574. {
  6575. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6576. {
  6577. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6578. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6579. }
  6580. 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'))
  6581. {
  6582. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6583. }
  6584. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6585. {
  6586. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6587. }
  6588. else
  6589. {
  6590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6591. }
  6592. }
  6593. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6594. {
  6595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6596. }
  6597. }
  6598. else
  6599. {
  6600. //replace reservation
  6601. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6602. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6603. }
  6604. }
  6605. } // END FOR AC_QUANTITY
  6606. }//END FOR AC ELSE
  6607. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6608. }
  6609. else if(connectorIdInt == 0)
  6610. {
  6611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6612. {
  6613. //check Transaction active
  6614. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6615. {
  6616. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6617. {
  6618. 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'))
  6619. {
  6620. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6621. goto end;
  6622. }
  6623. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6624. {
  6625. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6626. goto end;
  6627. }
  6628. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6629. {
  6630. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6631. goto end;
  6632. }
  6633. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6634. {
  6635. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6636. goto end;
  6637. }
  6638. }
  6639. }// END FOR CHAdeMO_QUANTITY
  6640. for (int index = 0; index < CCS_QUANTITY; index++)
  6641. {
  6642. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6643. {
  6644. 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'))
  6645. {
  6646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6647. }
  6648. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6649. {
  6650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6651. }
  6652. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6653. {
  6654. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6655. }
  6656. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6657. {
  6658. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6659. }
  6660. }
  6661. } // END FOR CCS_QUANTITY
  6662. for (int index = 0; index < GB_QUANTITY; index++)
  6663. {
  6664. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6665. {
  6666. 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'))
  6667. {
  6668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6669. }
  6670. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6671. {
  6672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6673. }
  6674. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6675. {
  6676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6677. }
  6678. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6679. {
  6680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6681. }
  6682. }
  6683. } // END FOR GB_QUANTITY
  6684. }
  6685. else
  6686. {
  6687. for (int index = 0; index < AC_QUANTITY; index++)
  6688. {
  6689. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6690. {
  6691. 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'))
  6692. {
  6693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6694. goto end;
  6695. }
  6696. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6697. {
  6698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6699. goto end;
  6700. }
  6701. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6702. {
  6703. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6704. goto end;
  6705. }
  6706. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6707. {
  6708. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6709. goto end;
  6710. }
  6711. }
  6712. }// END FOR AC_QUANTITY
  6713. }
  6714. //The connectorId is 0
  6715. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6717. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6718. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6719. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6720. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6721. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6722. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6723. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6724. result = TRUE;
  6725. return result;
  6726. }
  6727. else
  6728. {
  6729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6730. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6731. }
  6732. if(strcmp(comfirmstr,"Accepted") == 0)
  6733. {
  6734. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6735. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6736. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6737. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6738. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6739. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6740. result = TRUE;
  6741. return result;
  6742. }
  6743. end:
  6744. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6745. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6746. return result;
  6747. }
  6748. int handleResetRequest(char *uuid, char *payload)
  6749. {
  6750. mtrace();
  6751. int result = FAIL;
  6752. char sstr[10]={0};
  6753. char typestr[10]={0};
  6754. char comfirmstr[20]={0};
  6755. int c = 0;
  6756. char *loc;
  6757. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6758. DEBUG_INFO("handleResetRequest ...\n");
  6759. loc = strstr(payload, "type");
  6760. memset(sstr ,0, sizeof(sstr) );
  6761. c = 0;
  6762. while (loc[3+strlen("type")+c] != '\"')
  6763. {
  6764. sstr[c] = loc[3+strlen("type")+c];
  6765. c++;
  6766. }
  6767. sstr[c] = '\0';
  6768. strcpy(typestr,sstr);
  6769. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6770. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6771. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6772. {
  6773. //check Transaction active
  6774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6775. {
  6776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6777. {
  6778. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6779. {
  6780. //0: unplug, 1: Plug-in
  6781. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6782. }
  6783. }
  6784. for (int index = 0; index < CCS_QUANTITY; index++)
  6785. {
  6786. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6787. {
  6788. //0: unplug, 1: Plug-in
  6789. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6790. }
  6791. }
  6792. for (int index = 0; index < GB_QUANTITY; index++)
  6793. {
  6794. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6795. {
  6796. //0: unplug, 1: Plug-in
  6797. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6798. }
  6799. }
  6800. }
  6801. else
  6802. {
  6803. for (int index = 0; index < AC_QUANTITY; index++)
  6804. {
  6805. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6806. {
  6807. //0: unplug, 1: Plug-in
  6808. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6809. }
  6810. }
  6811. }// END FOR AC ELSE
  6812. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6813. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6814. result = TRUE;
  6815. return result;
  6816. }
  6817. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6818. {
  6819. //check Transaction active
  6820. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6821. {
  6822. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6823. {
  6824. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6825. {
  6826. //0: unplug, 1: Plug-in
  6827. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6828. }
  6829. }
  6830. for (int index = 0; index < CCS_QUANTITY; index++)
  6831. {
  6832. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6833. {
  6834. //0: unplug, 1: Plug-in
  6835. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6836. }
  6837. }
  6838. for (int index = 0; index < GB_QUANTITY; index++)
  6839. {
  6840. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6841. {
  6842. //0: unplug, 1: Plug-in
  6843. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6844. }
  6845. }
  6846. }
  6847. else
  6848. {
  6849. for (int index = 0; index < AC_QUANTITY; index++)
  6850. {
  6851. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6852. {
  6853. //0: unplug, 1: Plug-in
  6854. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6855. }
  6856. }
  6857. }// END FOR AC ELSE
  6858. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6859. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6860. result = TRUE;
  6861. return result;
  6862. }
  6863. else
  6864. {
  6865. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6866. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6867. goto errorend;
  6868. }
  6869. errorend:
  6870. sendResetConfirmation(uuid, comfirmstr);
  6871. return result;
  6872. }
  6873. int handleSendLocalListRequest(char *uuid, char *payload)
  6874. {
  6875. mtrace();
  6876. int result = FAIL;
  6877. int listVersionInt;
  6878. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6879. char listsearch[]="listVersion";
  6880. char updateTypesearch[]="updateType";
  6881. char localAuthorizationListsearch[]="localAuthorizationList";
  6882. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6883. char CardList[500][160]={0};
  6884. char updateTypestr[15]={0};
  6885. char idTagstr[20]={0};
  6886. char parentIdTag[20]={0};
  6887. char expiryDate[30]={0};
  6888. char idTagstatus[16]={0};
  6889. int c = 0;
  6890. int i = 0;
  6891. char *delim1 = "}";
  6892. char * pch;
  6893. char *loc;
  6894. //char *ptr;
  6895. char comfirmstr[20];
  6896. //int n_localAuthorizations = 0;
  6897. int checkState_Faulted = FALSE;
  6898. DEBUG_INFO("handleSendLocalListRequest\n");
  6899. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6900. {
  6901. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6902. goto end;
  6903. }
  6904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6905. {
  6906. //check Charge Point state
  6907. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6908. {
  6909. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6910. {
  6911. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6912. }
  6913. }
  6914. for (int index = 0; index < CCS_QUANTITY; index++)
  6915. {
  6916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6917. {
  6918. checkState_Faulted = TRUE; //OCPP Status
  6919. }
  6920. }
  6921. for (int index = 0; index < GB_QUANTITY; index++)
  6922. {
  6923. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6924. {
  6925. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6926. }
  6927. }
  6928. }
  6929. else
  6930. {
  6931. //check Charge Point state
  6932. for (int index = 0; index < AC_QUANTITY; index++)
  6933. {
  6934. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6935. {
  6936. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6937. }
  6938. }
  6939. }// END FOR AC ELSE
  6940. if(checkState_Faulted == TRUE)
  6941. {
  6942. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6943. goto end;
  6944. }
  6945. //listVersion
  6946. c = 0;
  6947. loc = strstr(payload, listsearch);
  6948. while (loc[strlen("listVersion")+2+c] != ',')
  6949. {
  6950. sstr[c] = loc[strlen("listVersion")+2+c];
  6951. c++;
  6952. }
  6953. sstr[c] = '\0';
  6954. listVersionInt = atoi(sstr);
  6955. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6956. //updateType
  6957. loc = strstr(payload, updateTypesearch);
  6958. c = 0;
  6959. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6960. {
  6961. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6962. c++;
  6963. }
  6964. sstr[c] = '\0';
  6965. strcpy(updateTypestr, sstr);
  6966. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6967. //localAuthorizationList
  6968. memset(sstr ,0, sizeof(sstr) );
  6969. loc = strstr(payload, localAuthorizationListsearch);
  6970. if(loc != NULL) // localAuthorizationList is not NULL
  6971. {
  6972. //Check UpdateType
  6973. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6974. {
  6975. //Local list full update
  6976. printf("Local list full update.\n");
  6977. OCPP_cleanLocalList();
  6978. }
  6979. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6980. {
  6981. //Local list different update
  6982. printf("Local list different update.\n");
  6983. OCPP_getListVerion();
  6984. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6985. {
  6986. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6987. goto end;
  6988. }
  6989. }
  6990. else
  6991. {
  6992. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6993. goto end;
  6994. }
  6995. c = 0;
  6996. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6997. {
  6998. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6999. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7000. c++;
  7001. }
  7002. sstr[c] = '\0';
  7003. //parsing strings to words
  7004. i = 0;
  7005. pch = strtok(sstr,delim1);
  7006. while (pch != NULL)
  7007. {
  7008. strcpy(CardList[i], pch);
  7009. pch = strtok (NULL, delim1);
  7010. i = i + 1;
  7011. }
  7012. //local Authorizations List Numbers
  7013. //n_localAuthorizations = i;
  7014. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7015. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7016. c= 0;
  7017. while(c < i)
  7018. {
  7019. //Search "IdToken"
  7020. memset(sstr ,0, sizeof(sstr) );
  7021. loc = strstr(CardList[c], "idTag");
  7022. int j = 0;
  7023. while (loc[3+strlen("idTag")+j] != '\"')
  7024. {
  7025. sstr[j] = loc[3+strlen("idTag")+j];
  7026. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7027. j++;
  7028. }
  7029. sstr[j] = '\0';
  7030. strcpy(idTagstr, sstr);
  7031. //Search "expiryDate"
  7032. memset(sstr ,0, sizeof(sstr) );
  7033. loc = strstr(CardList[c], "expiryDate");
  7034. j = 0;
  7035. while (loc[3+strlen("expiryDate")+j] != '\"')
  7036. {
  7037. sstr[j] = loc[3+strlen("expiryDate")+j];
  7038. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7039. j++;
  7040. }
  7041. sstr[j] = '\0';
  7042. strcpy(expiryDate, sstr);
  7043. //Search "parentIdTag"
  7044. memset(sstr ,0, sizeof(sstr) );
  7045. loc = strstr(CardList[c], "parentIdTag");
  7046. j = 0;
  7047. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7048. {
  7049. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7050. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7051. j++;
  7052. }
  7053. sstr[j] = '\0';
  7054. strcpy(parentIdTag, sstr);
  7055. //Search "status"
  7056. memset(sstr ,0, sizeof(sstr) );
  7057. loc = strstr(CardList[c], "status");
  7058. j = 0;
  7059. while (loc[3+strlen("status")+j] != '\"')
  7060. {
  7061. sstr[j] = loc[3+strlen("status")+j];
  7062. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7063. j++;
  7064. }
  7065. sstr[j] = '\0';
  7066. strcpy(idTagstatus, sstr);
  7067. OCPP_getIdTag(idTagstr);
  7068. //OCPP_getIdTag("test"); For Test
  7069. DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7070. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7071. {
  7072. //Local list full update
  7073. DEBUG_INFO("Local list full update.\n");
  7074. // update list
  7075. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7076. OCPP_get_TableAuthlocalAllData();
  7077. }
  7078. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7079. {
  7080. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7081. {
  7082. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7083. }
  7084. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7085. {
  7086. OCPP_deleteIdTag(idTagstr);
  7087. }
  7088. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7089. {
  7090. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7091. }
  7092. }
  7093. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7094. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7095. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7096. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7097. c++;
  7098. }
  7099. }
  7100. else
  7101. {
  7102. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7103. {
  7104. //Local list different update
  7105. DEBUG_INFO("Local list different update.\n");
  7106. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7107. goto end;
  7108. }
  7109. }
  7110. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7111. end:
  7112. sendSendLocalListConfirmation(uuid, comfirmstr);
  7113. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7114. #if 0
  7115. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7116. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7117. #endif
  7118. return result;
  7119. }
  7120. /*
  7121. enum _SYSTEM_STATUS
  7122. {
  7123. S_BOOTING = 0,
  7124. S_IDLE, =1
  7125. S_AUTHORIZING, =2
  7126. S_REASSIGN_CHECK, =3
  7127. S_REASSIGN, =4
  7128. S_PRECHARGE, =5
  7129. S_PREPARING_FOR_EV, =6
  7130. S_PREPARING_FOR_EVSE, =7
  7131. S_CHARGING, =8
  7132. S_TERMINATING, =9
  7133. S_COMPLETE, =10
  7134. S_ALARM, =11
  7135. S_FAULT =12
  7136. };
  7137. */
  7138. #define MAX 200
  7139. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7140. {
  7141. mtrace();
  7142. int result = FAIL;
  7143. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7144. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7145. char chargingProfilePurposeStr[30]={0};
  7146. char chargingProfileKindStr[16]={0};
  7147. char recurrencyKindStr[10]={0};
  7148. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7149. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7150. int chargingSchedulePeriodCount = 0;
  7151. //int updateflag = FALSE;
  7152. char comfirmstr[20]={0};
  7153. int meet= FALSE;
  7154. char sstr[10]={0};
  7155. int c = 0;
  7156. char *loc;
  7157. FILE *fptr1;//, *fptr2;
  7158. //int lno=0;//, linectr = 0;
  7159. //int modifyflag = FALSE;
  7160. char filename[MAX]={0};
  7161. char tempfile[] = "../Storage/OCPP/temp.json";
  7162. //int resultRename=0;
  7163. char rmFileCmd[50]={0};
  7164. char tempchargingProfilePurposeStr[30]={0};
  7165. //[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}}}]
  7166. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7167. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7168. //*********************connectorId***************************/
  7169. loc = strstr(payload, "connectorId");
  7170. c = 0;
  7171. memset(sstr ,0, sizeof(sstr) );
  7172. while (loc[strlen("connectorId")+2+c] != ',')
  7173. {
  7174. sstr[c] = loc[strlen("connectorId")+2+c];
  7175. c++;
  7176. }
  7177. sstr[c] = '\0';
  7178. connectorIdInt = atoi(sstr);
  7179. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7180. {
  7181. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7182. }
  7183. else
  7184. {
  7185. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7186. }
  7187. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7188. //*********************chargingProfileId***************************/
  7189. loc = strstr(payload, "chargingProfileId");
  7190. c = 0;
  7191. memset(sstr ,0, sizeof(sstr) );
  7192. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7193. {
  7194. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7195. c++;
  7196. }
  7197. sstr[c] = '\0';
  7198. chargingProfileIdInt = atoi(sstr);
  7199. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7200. {
  7201. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7202. }
  7203. else
  7204. {
  7205. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7206. }
  7207. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7208. //*********************transactionId***************************/
  7209. loc = strstr(payload, "transactionId");
  7210. if(loc != NULL)
  7211. {
  7212. c = 0;
  7213. memset(sstr ,0, sizeof(sstr) );
  7214. while (loc[strlen("transactionId")+2+c] != ',')
  7215. {
  7216. sstr[c] = loc[strlen("transactionId")+2+c];
  7217. c++;
  7218. }
  7219. sstr[c] = '\0';
  7220. transactionIdInt = atoi(sstr);
  7221. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7222. {
  7223. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7224. }
  7225. else
  7226. {
  7227. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7228. }
  7229. }
  7230. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7231. //*********************stackLevel***************************/
  7232. loc = strstr(payload, "stackLevel");
  7233. c = 0;
  7234. memset(sstr ,0, sizeof(sstr) );
  7235. while (loc[strlen("stackLevel")+2+c] != ',')
  7236. {
  7237. sstr[c] = loc[strlen("stackLevel")+2+c];
  7238. c++;
  7239. }
  7240. sstr[c] = '\0';
  7241. stackLevelInt = atoi(sstr);
  7242. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7243. {
  7244. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7245. }
  7246. else
  7247. {
  7248. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7249. }
  7250. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7251. //*********************chargingProfilePurpose***************************/
  7252. loc = strstr(payload, "chargingProfilePurpose");
  7253. c = 0;
  7254. memset(sstr ,0, sizeof(sstr) );
  7255. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7256. {
  7257. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7258. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7259. c++;
  7260. }
  7261. sstr[c] = '\0';
  7262. strcpy(chargingProfilePurposeStr,sstr);
  7263. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7264. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7265. {
  7266. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7267. }
  7268. else
  7269. {
  7270. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7271. }
  7272. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7273. //*********************chargingProfileKind***************************/
  7274. loc = strstr(payload, "chargingProfileKind");
  7275. c = 0;
  7276. memset(sstr ,0, sizeof(sstr) );
  7277. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7278. {
  7279. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7280. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7281. c++;
  7282. }
  7283. sstr[c] = '\0';
  7284. strcpy(chargingProfileKindStr,sstr);
  7285. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7286. {
  7287. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7288. }
  7289. else
  7290. {
  7291. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7292. }
  7293. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7294. //*********************recurrencyKind***************************/
  7295. loc = strstr(payload, "recurrencyKind");
  7296. if(loc != NULL)
  7297. {
  7298. c = 0;
  7299. memset(sstr ,0, sizeof(sstr) );
  7300. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7301. {
  7302. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7303. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7304. c++;
  7305. }
  7306. sstr[c] = '\0';
  7307. strcpy(recurrencyKindStr,sstr);
  7308. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7309. {
  7310. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7311. }
  7312. else
  7313. {
  7314. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7315. }
  7316. }
  7317. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7318. //*********************validFrom***************************/
  7319. loc = strstr(payload, "validFrom");
  7320. if(loc != NULL)
  7321. {
  7322. c = 0;
  7323. memset(sstr ,0, sizeof(sstr) );
  7324. while (loc[3+strlen("validFrom")+c] != '\"')
  7325. {
  7326. sstr[c] = loc[3+strlen("validFrom")+c];
  7327. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7328. c++;
  7329. }
  7330. sstr[c] = '\0';
  7331. strcpy(validFromStr,sstr);
  7332. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7333. {
  7334. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7335. }
  7336. else
  7337. {
  7338. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7339. }
  7340. }
  7341. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7342. //*********************validTo***************************/
  7343. loc = strstr(payload, "validTo");
  7344. if(loc != NULL)
  7345. {
  7346. c = 0;
  7347. memset(sstr ,0, sizeof(sstr) );
  7348. while (loc[3+strlen("validTo")+c] != '\"')
  7349. {
  7350. sstr[c] = loc[3+strlen("validTo")+c];
  7351. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7352. c++;
  7353. }
  7354. sstr[c] = '\0';
  7355. strcpy(validToStr,sstr);
  7356. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7357. {
  7358. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7359. }
  7360. else
  7361. {
  7362. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7363. }
  7364. }
  7365. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7366. //*********************duration***************************/
  7367. loc = strstr(payload, "duration");
  7368. if(loc != NULL)
  7369. {
  7370. c = 0;
  7371. memset(sstr ,0, sizeof(sstr) );
  7372. while (loc[strlen("duration")+2+c] != ',')
  7373. {
  7374. sstr[c] = loc[strlen("duration")+2+c];
  7375. c++;
  7376. }
  7377. sstr[c] = '\0';
  7378. durationInt = atoi(sstr);
  7379. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7380. {
  7381. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7382. }
  7383. else
  7384. {
  7385. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7386. }
  7387. }
  7388. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7389. //*********************startSchedule***************************/
  7390. loc = strstr(payload, "startSchedule");
  7391. if(loc != NULL)
  7392. {
  7393. c = 0;
  7394. memset(sstr ,0, sizeof(sstr) );
  7395. while (loc[3+strlen("startSchedule")+c] != '\"')
  7396. {
  7397. sstr[c] = loc[3+strlen("startSchedule")+c];
  7398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7399. c++;
  7400. }
  7401. sstr[c] = '\0';
  7402. strcpy(startScheduleStr,sstr);
  7403. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7404. {
  7405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7406. }
  7407. else
  7408. {
  7409. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7410. }
  7411. }
  7412. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7413. //*********************chargingRateUnit***************************/
  7414. loc = strstr(payload, "chargingRateUnit");
  7415. if(loc != NULL)
  7416. {
  7417. c = 0;
  7418. memset(sstr ,0, sizeof(sstr) );
  7419. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7420. {
  7421. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7423. c++;
  7424. }
  7425. sstr[c] = '\0';
  7426. strcpy(chargingRateUnitStr,sstr);
  7427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7428. {
  7429. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7430. }
  7431. else
  7432. {
  7433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7434. }
  7435. }
  7436. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7437. //****************chargingSchedulePeriod count start*******************/
  7438. int what_len = strlen("startPeriod");
  7439. char *where = payload;
  7440. if (what_len)
  7441. while ((where = strstr(where, "startPeriod"))) {
  7442. where += what_len;
  7443. chargingSchedulePeriodCount++;
  7444. }
  7445. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7446. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7447. where = payload;
  7448. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7449. {
  7450. //****************startPeriod*******************/
  7451. c=0;
  7452. loc = strstr(where, "startPeriod");
  7453. memset(sstr ,0, sizeof(sstr) );
  7454. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7455. {
  7456. sstr[c] = loc[strlen("startPeriod")+2+c];
  7457. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7458. c++;
  7459. }
  7460. sstr[c] = '\0';
  7461. startPeriodInt[periodNums] = atoi(sstr);
  7462. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7463. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7464. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7465. {
  7466. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7467. }
  7468. else
  7469. {
  7470. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7471. }
  7472. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7473. //****************limit*******************/
  7474. c=0;
  7475. loc = strstr(where, "limit");
  7476. memset(sstr ,0, sizeof(sstr) );
  7477. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7478. {
  7479. sstr[c] = loc[strlen("limit")+2+c];
  7480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7481. c++;
  7482. }
  7483. sstr[c] = '\0';
  7484. limitflaot[periodNums] = atof(sstr);
  7485. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7486. {
  7487. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7488. }
  7489. else
  7490. {
  7491. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7492. }
  7493. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7494. //****************numberPhases*******************/
  7495. loc = strstr(where, "numberPhases");
  7496. if(loc != NULL)
  7497. {
  7498. c=0;
  7499. memset(sstr ,0, sizeof(sstr) );
  7500. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7501. {
  7502. sstr[c] = loc[strlen("numberPhases")+2+c];
  7503. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7504. c++;
  7505. }
  7506. sstr[c] = '\0';
  7507. numberPhasesInt[periodNums] = atoi(sstr);
  7508. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7509. {
  7510. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7511. }
  7512. else
  7513. {
  7514. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7515. }
  7516. }
  7517. where = loc;
  7518. }
  7519. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7520. //****************chargingSchedulePeriod count end*******************/
  7521. //*********************minChargingRate***************************/
  7522. loc = strstr(payload, "minChargingRate");
  7523. if(loc != NULL)
  7524. {
  7525. c = 0;
  7526. memset(sstr ,0, sizeof(sstr) );
  7527. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7528. {
  7529. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7530. c++;
  7531. }
  7532. sstr[c] = '\0';
  7533. minChargingRateFloat = atof(sstr);
  7534. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7535. {
  7536. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7537. }
  7538. else
  7539. {
  7540. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7541. }
  7542. }
  7543. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7544. {
  7545. //printf("set chargingProfile 1-2\n");
  7546. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7547. if(connectorIdInt != 0)
  7548. {
  7549. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7550. goto end;
  7551. }
  7552. strcpy(filename, ChargePointMaxProfile_JSON );
  7553. fptr1 = fopen(filename, "r");
  7554. if (!fptr1)
  7555. {
  7556. //file not exist
  7557. DEBUG_INFO("Unable to open the input file!!\n");
  7558. fptr1 = fopen(filename, "w+");
  7559. }
  7560. fclose(fptr1);
  7561. }
  7562. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7563. {
  7564. //printf("set chargingProfile 1-3\n");
  7565. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7566. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7567. {
  7568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7569. goto end;
  7570. }
  7571. switch(connectorIdInt)
  7572. {
  7573. case 0:
  7574. strcpy(filename, TxDefaultProfile_0_JSON );
  7575. break;
  7576. case 1:
  7577. strcpy(filename, TxDefaultProfile_1_JSON );
  7578. break;
  7579. case 2:
  7580. strcpy(filename, TxDefaultProfile_2_JSON );
  7581. break;
  7582. default:
  7583. strcpy(filename, TxDefaultProfile_0_JSON );
  7584. break;
  7585. }
  7586. fptr1 = fopen(filename, "r");
  7587. if (!fptr1)
  7588. {
  7589. //file not exist
  7590. //DEBUG_INFO("Unable to open the input file!!\n");
  7591. fptr1 = fopen(filename, "w+");
  7592. }
  7593. fclose(fptr1);
  7594. }
  7595. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7596. {
  7597. //printf("set chargingProfile 1-4\n");
  7598. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7599. //check Transaction active
  7600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7601. {
  7602. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7603. {
  7604. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7605. {
  7606. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7607. {
  7608. meet = TRUE;
  7609. break;
  7610. }
  7611. }
  7612. }
  7613. }
  7614. for (int index = 0; index < CCS_QUANTITY; index++)
  7615. {
  7616. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7617. {
  7618. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7619. {
  7620. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7621. {
  7622. meet = TRUE;
  7623. break;
  7624. }
  7625. }
  7626. }
  7627. }
  7628. for (int index = 0; index < GB_QUANTITY; index++)
  7629. {
  7630. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7631. {
  7632. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7633. {
  7634. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7635. {
  7636. meet = TRUE;
  7637. break;
  7638. }
  7639. }
  7640. }
  7641. }
  7642. if(meet == FALSE)
  7643. {
  7644. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7645. goto end;
  7646. }
  7647. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7648. {
  7649. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7650. goto end;
  7651. }
  7652. switch(connectorIdInt)
  7653. {
  7654. case 0:
  7655. break;
  7656. case 1:
  7657. strcpy(filename, TxProfile_1_JSON);
  7658. break;
  7659. case 2:
  7660. strcpy(filename, TxProfile_2_JSON);
  7661. break;
  7662. default:
  7663. strcpy(filename, TxProfile_1_JSON);
  7664. break;
  7665. }
  7666. fptr1 = fopen(filename, "r");
  7667. if (!fptr1)
  7668. {
  7669. //file not exist
  7670. DEBUG_INFO("Unable to open the input file!!\n");
  7671. fptr1 = fopen(filename, "w+");
  7672. }
  7673. fclose(fptr1);
  7674. }
  7675. //**********************************Write to File********************************************************/
  7676. FILE *infile;
  7677. FILE *outfile;
  7678. // open file for writing
  7679. infile = fopen (filename, "r");
  7680. outfile = fopen (tempfile, "w");
  7681. int d =0;
  7682. d = fgetc(infile);
  7683. //DEBUG_INFO("d:%d\n",d);
  7684. rewind(infile);
  7685. //*检测到文件结束标识返回1,否则返回0。*/
  7686. if(d == EOF)
  7687. {
  7688. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7689. fprintf(outfile,"%s\n",payload);
  7690. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7691. fclose(infile);
  7692. fclose(outfile);
  7693. sprintf(rmFileCmd,"rm -f %s",filename);
  7694. system(rmFileCmd);
  7695. rename(tempfile, filename);
  7696. #if 0
  7697. resultRename = rename(tempfile, filename);
  7698. if(resultRename == 0)
  7699. {
  7700. DEBUG_INFO("File chargingProfile renamed successfully");
  7701. }
  7702. else
  7703. {
  7704. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7705. }
  7706. #endif
  7707. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7708. //system(rmFileCmd);
  7709. }
  7710. else
  7711. {
  7712. char buf[1000]={0};
  7713. int ChargingProfileAdded = FALSE;
  7714. while (fgets(buf, sizeof(buf), infile) != NULL)
  7715. {
  7716. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7717. //*************************tempconnectorIdInt*********************************/
  7718. loc = strstr(buf, "connectorId");
  7719. c = 0;
  7720. memset(sstr ,0, sizeof(sstr) );
  7721. while (loc[strlen("connectorId")+2+c] != ',')
  7722. {
  7723. sstr[c] = loc[strlen("connectorId")+2+c];
  7724. c++;
  7725. }
  7726. sstr[c] = '\0';
  7727. tempconnectorIdInt = atoi(sstr);
  7728. //*************************tempchargingProfileIdInt*********************************/
  7729. loc = strstr(buf, "chargingProfileId");
  7730. c = 0;
  7731. memset(sstr ,0, sizeof(sstr) );
  7732. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7733. {
  7734. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7735. c++;
  7736. }
  7737. sstr[c] = '\0';
  7738. tempchargingProfileIdInt = atoi(sstr);
  7739. //*************************tempstackLevelInt*********************************/
  7740. loc = strstr(buf, "stackLevel");
  7741. c = 0;
  7742. memset(sstr ,0, sizeof(sstr) );
  7743. while (loc[strlen("stackLevel")+2+c] != ',')
  7744. {
  7745. sstr[c] = loc[strlen("stackLevel")+2+c];
  7746. c++;
  7747. }
  7748. sstr[c] = '\0';
  7749. tempstackLevelInt = atoi(sstr);
  7750. //*************************tempchargingProfilePurposeStr*********************************/
  7751. loc = strstr(payload, "chargingProfilePurpose");
  7752. c = 0;
  7753. memset(sstr ,0, sizeof(sstr) );
  7754. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7755. {
  7756. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7758. c++;
  7759. }
  7760. sstr[c] = '\0';
  7761. strcpy(tempchargingProfilePurposeStr,sstr);
  7762. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7763. {
  7764. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7765. {
  7766. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7767. if(ChargingProfileAdded == FALSE)
  7768. {
  7769. fprintf(outfile,"%s\n",payload);
  7770. ChargingProfileAdded = TRUE;
  7771. }
  7772. }
  7773. else
  7774. {
  7775. if(tempstackLevelInt < stackLevelInt)
  7776. {
  7777. if(ChargingProfileAdded == FALSE)
  7778. {
  7779. fprintf(outfile,"%s\n",payload);
  7780. ChargingProfileAdded = TRUE;
  7781. fprintf(outfile,"%s\n",buf);
  7782. }
  7783. else
  7784. {
  7785. fprintf(outfile,"%s\n",buf);
  7786. }
  7787. }
  7788. else
  7789. {
  7790. if(ChargingProfileAdded == FALSE)
  7791. {
  7792. fprintf(outfile,"%s\n",buf);
  7793. fprintf(outfile,"%s\n",payload);
  7794. ChargingProfileAdded = TRUE;
  7795. }
  7796. else
  7797. {
  7798. fprintf(outfile,"%s\n",buf);
  7799. }
  7800. }
  7801. }
  7802. }
  7803. else
  7804. {
  7805. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7806. {
  7807. if(ChargingProfileAdded == FALSE)
  7808. {
  7809. fprintf(outfile,"%s\n",payload);
  7810. ChargingProfileAdded = TRUE;
  7811. fprintf(outfile,"%s\n",buf);
  7812. }
  7813. else
  7814. {
  7815. fprintf(outfile,"%s\n",buf);
  7816. }
  7817. }
  7818. else if(tempstackLevelInt < stackLevelInt)
  7819. {
  7820. if(ChargingProfileAdded == FALSE)
  7821. {
  7822. fprintf(outfile,"%s\n",payload);
  7823. ChargingProfileAdded = TRUE;
  7824. fprintf(outfile,"%s\n",buf);
  7825. }
  7826. else
  7827. {
  7828. fprintf(outfile,"%s\n",buf);
  7829. }
  7830. }
  7831. else
  7832. {
  7833. if(ChargingProfileAdded == FALSE)
  7834. {
  7835. fprintf(outfile,"%s\n",buf);
  7836. fprintf(outfile,"%s\n",payload);
  7837. ChargingProfileAdded = TRUE;
  7838. }
  7839. else
  7840. {
  7841. fprintf(outfile,"%s\n",buf);
  7842. }
  7843. }
  7844. }
  7845. } // end of while loop
  7846. fclose(infile);
  7847. fclose(outfile);
  7848. sprintf(rmFileCmd,"rm -f %s",filename);
  7849. system(rmFileCmd);
  7850. rename(tempfile, filename);
  7851. #if 0
  7852. resultRename = rename(tempfile, filename);
  7853. if(resultRename == 0)
  7854. {
  7855. DEBUG_INFO("File chargingProfile renamed successfully");
  7856. }
  7857. else
  7858. {
  7859. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7860. }
  7861. #endif
  7862. result = TRUE;
  7863. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7864. }
  7865. end:
  7866. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7867. return result;
  7868. return result;
  7869. }
  7870. int handleTriggerMessageRequest(char *uuid, char *payload)
  7871. {
  7872. mtrace();
  7873. int result = FAIL;
  7874. int connectorIdIsNULL = FALSE;
  7875. int connectorIdInt =0;
  7876. char sstr[40]={0};
  7877. char requestedMessagestr[40]={0};
  7878. char comfirmstr[20]={0};
  7879. int c = 0;
  7880. char *loc;
  7881. DEBUG_INFO("handleTriggerMessageRequest\n");
  7882. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7883. c = 0;
  7884. loc = strstr(payload, "requestedMessage");
  7885. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7886. {
  7887. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7888. c++;
  7889. }
  7890. sstr[c] = '\0';
  7891. strcpy(requestedMessagestr, sstr);
  7892. c = 0;
  7893. loc = strstr(payload, "connectorId");
  7894. if(loc == NULL)
  7895. {
  7896. connectorIdIsNULL = TRUE;
  7897. }
  7898. else
  7899. {
  7900. memset(sstr ,0, sizeof(sstr) );
  7901. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7902. {
  7903. sstr[c] = loc[strlen("connectorId")+2+c];
  7904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7905. c++;
  7906. }
  7907. sstr[c] = '\0';
  7908. connectorIdInt = atoi(sstr);
  7909. }
  7910. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7911. {
  7912. //connectorIdInt = json_object_get_int(connectorId);
  7913. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7914. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7915. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7916. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7917. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7918. }
  7919. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7920. {
  7921. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7922. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7923. return TRUE;
  7924. }
  7925. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7926. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7927. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7928. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7929. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7930. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7931. {
  7932. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7933. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7934. return TRUE;
  7935. }
  7936. else
  7937. {
  7938. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7939. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7940. }
  7941. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7942. {
  7943. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7944. {
  7945. FirmwareStatusNotificationStatus = 3;
  7946. }
  7947. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7948. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7949. }
  7950. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7951. {
  7952. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7953. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7954. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7955. }
  7956. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7957. {
  7958. sendBootNotificationRequest();
  7959. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7960. }
  7961. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7962. {
  7963. sendHeartbeatRequest(connectorIdInt);
  7964. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7965. }
  7966. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7967. {
  7968. if(connectorIdIsNULL == FALSE)
  7969. {
  7970. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7971. {
  7972. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7973. sendMeterValuesRequest(connectorIdInt -1);
  7974. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7975. }
  7976. }
  7977. else
  7978. {
  7979. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7980. {
  7981. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  7982. sendMeterValuesRequest(idx);
  7983. }
  7984. }
  7985. }
  7986. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  7987. {
  7988. if(connectorIdIsNULL == FALSE)
  7989. {
  7990. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7991. {
  7992. sendStatusNotificationRequest(connectorIdInt -1);
  7993. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7994. }
  7995. }
  7996. else
  7997. {
  7998. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  7999. sendStatusNotificationRequest(idx);
  8000. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8001. }
  8002. }
  8003. return result;
  8004. }
  8005. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8006. {
  8007. mtrace();
  8008. int result = FAIL;
  8009. char sstr[6]={0};
  8010. int connectorIdInt =0;
  8011. char comfirmstr[20]={0};
  8012. int c = 0;
  8013. char *loc;
  8014. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8015. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8016. c = 0;
  8017. loc = strstr(payload, "connectorId");
  8018. memset(sstr ,0, sizeof(sstr) );
  8019. while (loc[strlen("connectorId")+2+c] != '}')
  8020. {
  8021. sstr[c] = loc[strlen("connectorId")+2+c];
  8022. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8023. c++;
  8024. }
  8025. sstr[c] = '\0';
  8026. connectorIdInt = atoi(sstr);
  8027. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8028. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8029. {
  8030. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8031. goto end;
  8032. }
  8033. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8034. {
  8035. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8036. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8037. goto end;
  8038. }
  8039. else
  8040. {
  8041. //check Transaction active
  8042. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8043. {
  8044. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8045. {
  8046. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8047. {
  8048. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8049. }
  8050. }
  8051. for (int index = 0; index < CCS_QUANTITY; index++)
  8052. {
  8053. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8054. {
  8055. //stop Transaction
  8056. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8057. }
  8058. }
  8059. for (int index = 0; index < GB_QUANTITY; index++)
  8060. {
  8061. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8062. {
  8063. //stop Transaction
  8064. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8065. }
  8066. }
  8067. }
  8068. else
  8069. {
  8070. for (int index = 0; index < AC_QUANTITY; index++)
  8071. {
  8072. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8073. {
  8074. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8075. }
  8076. }
  8077. }// END FOR AC ELSE
  8078. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8079. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8080. result = TRUE;
  8081. return result;
  8082. }
  8083. end:
  8084. //json_object_put(obj); --- remove temporally
  8085. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8086. return result;
  8087. }
  8088. static char UpdateFirmwarepayloadData[300]={0};
  8089. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8090. {
  8091. mtrace();
  8092. int result = FAIL;
  8093. pthread_t t;
  8094. sendUpdateFirmwareConfirmation(uuid);
  8095. memset(UpdateFirmwarepayloadData, 0, 300);
  8096. strcpy(UpdateFirmwarepayloadData, payload);
  8097. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8098. ////pthread_join(t, NULL); //
  8099. //pthread_detach(t);
  8100. //sendUpdateFirmwareConfirmation(uuid);
  8101. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8102. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8103. return result;
  8104. }
  8105. void *UpdateFirmwareProcess(void *data)
  8106. {
  8107. pthread_detach(pthread_self());
  8108. mtrace();
  8109. int retriesInt =0, retryIntervalInt=0;
  8110. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8111. int port=0;
  8112. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8113. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8114. //char comfirmstr[20];
  8115. int isSuccess = 0;
  8116. char ftpbuf[200];
  8117. char temp[100];
  8118. char * pch;
  8119. int retriesISNULL=FALSE;
  8120. int retryInterval=FALSE;
  8121. int c = 0;
  8122. //int i = 0;
  8123. char *loc;
  8124. char sstr[300]={ 0 };
  8125. char str[300]={ 0 };
  8126. //char *str = (char*) data; // ? ?輸入資 ?
  8127. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8128. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8129. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8130. //***************location **************/
  8131. loc = strstr(str, "location");
  8132. memset(sstr ,0, sizeof(sstr) );
  8133. c = 0;
  8134. while (loc[3+strlen("location")+c] != '\"')
  8135. {
  8136. sstr[c] = loc[3+strlen("location")+c];
  8137. c++;
  8138. }
  8139. sstr[c] = '\0';
  8140. strcpy(locationstr, sstr);
  8141. //***************retries**************/
  8142. c = 0;
  8143. loc = strstr(str, "retries");
  8144. if(loc == NULL)
  8145. {
  8146. retriesISNULL=TRUE;
  8147. }
  8148. else
  8149. {
  8150. memset(sstr ,0, sizeof(sstr) );
  8151. while (loc[strlen("retries")+2+c] != ',')
  8152. {
  8153. sstr[c] = loc[strlen("retries")+2+c];
  8154. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8155. c++;
  8156. }
  8157. sstr[c] = '\0';
  8158. }
  8159. if(retriesISNULL == FALSE)
  8160. {
  8161. retriesInt = atoi(sstr);
  8162. }
  8163. //***************retrieveDate **************/
  8164. loc = strstr(str, "retrieveDate");
  8165. memset(sstr ,0, sizeof(sstr) );
  8166. c = 0;
  8167. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8168. {
  8169. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8170. c++;
  8171. }
  8172. sstr[c] = '\0';
  8173. strcpy(retrieveDatestr, sstr);
  8174. //***************retryInterval **************/
  8175. c = 0;
  8176. loc = strstr(str, "retryInterval");
  8177. memset(sstr ,0, sizeof(sstr) );
  8178. if(loc == NULL)
  8179. {
  8180. retryInterval=TRUE;
  8181. }
  8182. else
  8183. {
  8184. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8185. {
  8186. sstr[c] = loc[strlen("retryInterval")+2+c];
  8187. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8188. c++;
  8189. }
  8190. sstr[c] = '\0';
  8191. }
  8192. if(retryInterval==FALSE)
  8193. {
  8194. retryIntervalInt = atoi(sstr);
  8195. }
  8196. memset(ftppath, 0, sizeof(ftppath));
  8197. memset(path, 0, sizeof(path));
  8198. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8199. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8200. if(strncmp(locationstr,"http", 4) == 0)
  8201. {
  8202. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8203. protocol, host, path);
  8204. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8205. // protocol, user, password, host, path);
  8206. sprintf(ftppath,"/%s", path);
  8207. //DEBUG_INFO("protocol =%s\n",protocol);
  8208. //DEBUG_INFO("host =%s\n",host);
  8209. //DEBUG_INFO("path =%s\n",path);
  8210. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8211. int ftppathlen=strlen(ftppath);
  8212. int i=1;
  8213. char filenametemp[50];
  8214. while(i < ftppathlen)
  8215. {
  8216. int len=ftppathlen-i;
  8217. if(ftppath[len]== 47) // '/' ascll code: 47
  8218. {
  8219. DEBUG_INFO("compare '/' all right\n");
  8220. break;
  8221. }
  8222. i=i+1;
  8223. }
  8224. memset(filenametemp, 0, sizeof(filenametemp));
  8225. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8226. filenametemp[i+1] = 0;
  8227. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8228. do{
  8229. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8230. sleep(retryIntervalInt);
  8231. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8232. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8233. if(!isSuccess)
  8234. {
  8235. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8236. }
  8237. else
  8238. {
  8239. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8240. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8241. isUpdateRequest = TRUE;
  8242. }
  8243. }
  8244. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8245. {
  8246. memset(ftpbuf, 0, sizeof(ftpbuf));
  8247. memset(temp, 0, sizeof(temp));
  8248. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8249. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8250. int ftppathlen=strlen(ftpbuf);
  8251. int i=1;
  8252. char filenametemp[50];
  8253. while(i < ftppathlen)
  8254. {
  8255. int len=ftppathlen-i;
  8256. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8257. {
  8258. DEBUG_INFO(" compare '/' all right\n");
  8259. break;
  8260. }
  8261. i=i+1;
  8262. }
  8263. memset(filenametemp, 0, sizeof(filenametemp));
  8264. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8265. filenametemp[i+1] = 0;
  8266. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8267. pch=strchr(temp,'@');
  8268. if(pch==NULL)
  8269. {
  8270. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8271. protocol, host, &port, path);
  8272. strcpy(user,"anonymous");
  8273. strcpy(password,"");
  8274. }
  8275. else
  8276. {
  8277. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8278. protocol, user, password, host, &port, path);
  8279. }
  8280. sscanf(host,"%[^/]%s",host1, path1);
  8281. sprintf(ftppath,"%s", path1);
  8282. //DEBUG_INFO("protocol =%s\n",protocol);
  8283. //DEBUG_INFO("user =%s\n",user);
  8284. //DEBUG_INFO("password =%s\n",password);
  8285. //DEBUG_INFO("host1 =%s\n",host1);
  8286. //DEBUG_INFO("port =%d\n",port);
  8287. //DEBUG_INFO("path1 =%s\n",path1);
  8288. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8289. //ftpFile(host, user, password, port, ftppath, fname);
  8290. //download firmware pthred
  8291. if(port == 0)
  8292. {
  8293. port = 21;
  8294. }
  8295. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8296. do{
  8297. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8298. sleep(retryIntervalInt);
  8299. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8300. if(!isSuccess)
  8301. {
  8302. //BulldogUtil.sleepMs(interval*1000);
  8303. DEBUG_INFO("Update firmware request and download file fail.\n");
  8304. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8305. }
  8306. else
  8307. {
  8308. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8309. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8310. isUpdateRequest = TRUE;
  8311. }
  8312. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8313. }
  8314. else
  8315. {
  8316. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8317. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8318. }
  8319. pthread_exit(NULL);
  8320. }
  8321. //==========================================
  8322. // Handle server response routine
  8323. //==========================================
  8324. void handleAuthorizeResponse(char *payload, int gun_index)
  8325. {
  8326. mtrace();
  8327. char expiryDatestr[30]={0};
  8328. char parentIdTagstr[20]={0};
  8329. char statusstr[20]={0};
  8330. char expiryDatestrtemp[30]={0};
  8331. char parentIdTagstrtemp[20]={0};
  8332. char IdTagstrtemp[20]={0};
  8333. char statusstrtemp[20]={0};
  8334. int expiryDateISNULL=FALSE;
  8335. int parentIdTagISNULL=FALSE;
  8336. char sstr[160]={ 0 };
  8337. char* filename = AuthorizationCache_JSON;
  8338. char tempfile[] = "../Storage/OCPP/temp.json";
  8339. int c = 0;
  8340. char *loc;
  8341. int resultRename=0;
  8342. int responseIdTagInfoAsZero= 0;
  8343. char rmFileCmd[50]={0};
  8344. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8345. //***********expiryDate*************/
  8346. loc = strstr(payload, "expiryDate");
  8347. memset(sstr ,0, sizeof(sstr) );
  8348. c = 0;
  8349. if(loc == NULL)
  8350. {
  8351. expiryDateISNULL = TRUE;
  8352. }
  8353. else
  8354. {
  8355. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8356. {
  8357. sstr[c] = loc[3+strlen("expiryDate")+c];
  8358. c++;
  8359. }
  8360. sstr[c] = '\0';
  8361. strcpy(expiryDatestr, sstr);
  8362. }
  8363. //***********parentIdTag*************/
  8364. loc = strstr(payload, "parentIdTag");
  8365. memset(sstr ,0, sizeof(sstr) );
  8366. c = 0;
  8367. if(loc == NULL)
  8368. {
  8369. parentIdTagISNULL = TRUE;
  8370. }
  8371. else
  8372. {
  8373. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8374. {
  8375. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8376. c++;
  8377. }
  8378. sstr[c] = '\0';
  8379. strcpy(parentIdTagstr, sstr);
  8380. }
  8381. //***********status*************/
  8382. loc = strstr(payload, "status");
  8383. memset(sstr ,0, sizeof(sstr) );
  8384. c = 0;
  8385. while (loc[3+strlen("status")+c] != '\"')
  8386. {
  8387. sstr[c] = loc[3+strlen("status")+c];
  8388. c++;
  8389. }
  8390. sstr[c] = '\0';
  8391. strcpy(statusstr, sstr);
  8392. //#ifdef SystemLogMessage
  8393. // if(expiryDateISNULL == FALSE)
  8394. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8395. // if(parentIdTagISNULL == FALSE)
  8396. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8397. // DEBUG_INFO("status: %s\n", statusstr);
  8398. //#endif
  8399. if(expiryDateISNULL == FALSE)
  8400. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8401. if(parentIdTagISNULL == FALSE)
  8402. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8403. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8404. //Update idTag information to authorization cache if supproted
  8405. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8406. {
  8407. if((access(filename,F_OK))!=-1)
  8408. {
  8409. DEBUG_INFO("AuthorizationCache exist.\n");
  8410. }
  8411. else
  8412. {
  8413. DEBUG_INFO("AuthorizationCache not exist\n");
  8414. FILE *log = fopen(filename, "w+");
  8415. if(log == NULL)
  8416. {
  8417. DEBUG_INFO("log is NULL\n");
  8418. goto out;
  8419. }
  8420. else
  8421. {
  8422. fclose(log);
  8423. }
  8424. }
  8425. FILE *infile;
  8426. FILE *outfile;
  8427. // open file for writing
  8428. infile = fopen (filename, "r");
  8429. outfile = fopen (tempfile, "w");
  8430. //*检测到文件结束标识返回1,否则返回0。*/
  8431. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8432. int c;
  8433. c = fgetc(infile);
  8434. //DEBUG_INFO("c:%d\n",c);
  8435. rewind(infile);
  8436. if(c == EOF)
  8437. {
  8438. DEBUG_INFO("Orignal File is NULL\n");
  8439. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8440. {
  8441. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8442. }
  8443. else
  8444. {
  8445. strcpy(expiryDatestrtemp, "");
  8446. }
  8447. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8448. {
  8449. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8450. }
  8451. else
  8452. {
  8453. //write Authorize IdTag
  8454. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8455. }
  8456. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8457. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8458. fclose(infile);
  8459. fclose(outfile);
  8460. sprintf(rmFileCmd,"rm -f %s",filename);
  8461. system(rmFileCmd);
  8462. resultRename = rename(tempfile, filename);
  8463. if(resultRename == 0)
  8464. {
  8465. DEBUG_INFO("File renamed successfully");
  8466. }
  8467. else
  8468. {
  8469. DEBUG_INFO("Error: unable to rename the file");
  8470. }
  8471. }
  8472. else
  8473. {
  8474. char buf[160]={0};
  8475. //DEBUG_INFO("Orignal File is not NULL\n");
  8476. while (fgets(buf, sizeof(buf), infile) != NULL)
  8477. {
  8478. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8479. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8480. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8481. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8482. memset(statusstr, 0, sizeof(statusstrtemp));
  8483. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8484. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8485. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8486. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8487. //------------------IdTag-----------------------
  8488. loc = strstr(buf, "idTag");
  8489. memset(sstr ,0, sizeof(sstr) );
  8490. c = 0;
  8491. while (loc[3+strlen("idTag")+c] != '\"')
  8492. {
  8493. sstr[c] = loc[3+strlen("idTag")+c];
  8494. c++;
  8495. }
  8496. sstr[c] = '\0';
  8497. strcpy(IdTagstrtemp,sstr);
  8498. //*********************expiryDate***************/
  8499. loc = strstr(buf, "expiryDate");
  8500. memset(sstr ,0, sizeof(sstr) );
  8501. c = 0;
  8502. while (loc[3+strlen("expiryDate")+c] != '\"')
  8503. {
  8504. sstr[c] = loc[3+strlen("expiryDate")+c];
  8505. c++;
  8506. }
  8507. sstr[c] = '\0';
  8508. strcpy(expiryDatestr,sstr);
  8509. //*********************parentIdTag***************/
  8510. loc = strstr(buf, "parentIdTag");
  8511. memset(sstr ,0, sizeof(sstr) );
  8512. c = 0;
  8513. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8514. {
  8515. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8516. c++;
  8517. }
  8518. sstr[c] = '\0';
  8519. strcpy(parentIdTagstr,sstr);
  8520. //*********************status***************/
  8521. loc = strstr(buf, "status");
  8522. memset(sstr ,0, sizeof(sstr) );
  8523. c = 0;
  8524. while (loc[3+strlen("status")+c] != '\"')
  8525. {
  8526. sstr[c] = loc[3+strlen("status")+c];
  8527. c++;
  8528. }
  8529. sstr[c] = '\0';
  8530. strcpy(statusstr,sstr);
  8531. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8532. {
  8533. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8534. responseIdTagInfoAsZero = 1;
  8535. }
  8536. else
  8537. {
  8538. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8539. }
  8540. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8541. {
  8542. //modify item
  8543. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8544. {
  8545. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8546. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8547. }
  8548. else
  8549. {
  8550. strcpy(expiryDatestrtemp, "");
  8551. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8552. }
  8553. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8554. {
  8555. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8556. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8557. }
  8558. else
  8559. {
  8560. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8561. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8562. }
  8563. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8564. }
  8565. else
  8566. {
  8567. //wrie original item
  8568. strcpy(expiryDatestrtemp, expiryDatestr);
  8569. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8570. strcpy(statusstrtemp, statusstr);
  8571. }
  8572. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8573. }
  8574. fclose(infile);
  8575. fclose(outfile);
  8576. sprintf(rmFileCmd,"rm -f %s",filename);
  8577. system(rmFileCmd);
  8578. resultRename = rename(tempfile, filename);
  8579. if(resultRename == 0)
  8580. {
  8581. DEBUG_INFO("File renamed successfully");
  8582. }
  8583. else
  8584. {
  8585. DEBUG_INFO("Error: unable to rename the file");
  8586. }
  8587. }
  8588. }
  8589. out:
  8590. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8591. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8592. authorizeRetryTimes = 0;
  8593. }
  8594. void handleBootNotificationResponse(char *payload, int gun_index)
  8595. {
  8596. mtrace();
  8597. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8598. char statusStr[12]={0};
  8599. char currentTimeStr[30]={0};
  8600. char *loc;
  8601. int intervalInt = 0;
  8602. int c = 0;
  8603. //double diff_t;
  8604. struct tm tp;
  8605. char buf[28]={0};
  8606. char timebuf[50]={0};
  8607. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8608. //*** interval ****/
  8609. c = 0;
  8610. loc = strstr(payload, "interval");
  8611. //printf("loc=%s\n",loc);
  8612. memset(sstr ,0, sizeof(sstr) );
  8613. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8614. {
  8615. sstr[c] = loc[strlen("interval")+2+c];
  8616. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8617. c++;
  8618. }
  8619. sstr[c] = '\0';
  8620. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8621. intervalInt = atoi(sstr);
  8622. //***status ****/
  8623. loc = strstr(payload, "status");
  8624. memset(sstr ,0, sizeof(sstr) );
  8625. c = 0;
  8626. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8627. {
  8628. sstr[c] = loc[3+strlen("status")+c];
  8629. c++;
  8630. }
  8631. sstr[c] = '\0';
  8632. strcpy(statusStr, sstr);
  8633. //***currentTime ****/
  8634. loc = strstr(payload, "currentTime");
  8635. //printf("loc=%s\n",loc);
  8636. memset(sstr ,0, sizeof(sstr) );
  8637. c = 0;
  8638. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8639. {
  8640. sstr[c] = loc[3+strlen("currentTime")+c];
  8641. c++;
  8642. }
  8643. sstr[c] = '\0';
  8644. strcpy(currentTimeStr, sstr);
  8645. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8646. HeartBeatWaitTime = BootNotificationInterval;
  8647. clientTime.Heartbeat=time((time_t*)NULL);
  8648. //#ifdef SystemLogMessage
  8649. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8650. // DEBUG_INFO("interval: %d\n", intervalInt);
  8651. // DEBUG_INFO("status: %s\n", statusStr);
  8652. //#endif
  8653. //write back to ShmOCPP16Data->BootNotification
  8654. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8655. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8656. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8657. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8658. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8659. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8660. {
  8661. server_sign = TRUE;
  8662. server_pending =FALSE;
  8663. }
  8664. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8665. {
  8666. server_pending = TRUE;
  8667. }
  8668. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8669. tp.tm_isdst = -1;
  8670. //time_t utc = mktime(&tp);
  8671. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8672. memset(timebuf, 0, sizeof timebuf);
  8673. sprintf(timebuf,"date -s '%s'",buf);
  8674. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8675. system(timebuf);
  8676. //==============================================
  8677. // RTC sync
  8678. //==============================================
  8679. system("/sbin/hwclock -w --systohc");
  8680. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8681. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8682. }
  8683. void handleDataTransferResponse(char *payload, int gun_index)
  8684. {
  8685. char sstr[160]={0};//sstr[200]={ 0 };
  8686. int c = 0;
  8687. char *loc;
  8688. DEBUG_INFO("handleDataTransferResponse ...\n");
  8689. loc = strstr(payload, "status");
  8690. printf("loc=%s\n",loc);
  8691. c = 0;
  8692. while (loc[3+strlen("status")+c] != '\"')
  8693. {
  8694. sstr[c] = loc[3+strlen("status")+c];
  8695. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8696. c++;
  8697. }
  8698. sstr[c] = '\0';
  8699. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8700. //#ifdef SystemLogMessage
  8701. //DEBUG_INFO("data: %s\n", payload);
  8702. //#endif
  8703. }
  8704. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8705. {
  8706. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8707. //struct json_object *obj;
  8708. // obj = json_tokener_parse(payload);
  8709. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8710. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8711. //No fields are defined.
  8712. }
  8713. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8714. {
  8715. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8716. //struct json_object *obj;
  8717. // obj = json_tokener_parse(payload);
  8718. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8719. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8720. //No fields are defined.
  8721. }
  8722. void handleHeartbeatResponse(char *payload, int gun_index)
  8723. {
  8724. mtrace();
  8725. //double diff_t;
  8726. struct tm tp;
  8727. char buf[28]={0};
  8728. char timebuf[50]={0};
  8729. char sstr[30]={ 0 };
  8730. int c = 0;
  8731. char *loc;
  8732. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8733. if((HeartBeatCount%360) == 0)
  8734. {
  8735. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8736. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8737. }
  8738. HeartBeatCount = HeartBeatCount + 1;
  8739. c = 0;
  8740. loc = strstr(payload, "currentTime");
  8741. memset(sstr ,0, sizeof(sstr) );
  8742. while (loc[3+strlen("currentTime")+c] != '\"')
  8743. {
  8744. sstr[c] = loc[3+strlen("currentTime")+c];
  8745. c++;
  8746. }
  8747. sstr[c] = '\0';
  8748. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8749. // #ifdef SystemLogMessage
  8750. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8751. // #endif
  8752. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8753. tp.tm_isdst = -1;
  8754. //time_t utc = mktime(&tp);
  8755. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8756. memset(timebuf, 0, sizeof timebuf);
  8757. sprintf(timebuf,"date -s '%s'",buf);
  8758. system(timebuf);
  8759. //==============================================
  8760. // RTC sync
  8761. //==============================================
  8762. system("/sbin/hwclock -w --systohc");
  8763. if(FirstHeartBeat == 0)
  8764. {
  8765. FirstHeartBeat = 1;
  8766. }
  8767. HeartBeatWithNOResponse = 0;
  8768. }
  8769. void handleMeterValuesResponse(char *payload, int gun_index)
  8770. {
  8771. mtrace();
  8772. //struct json_object *obj;
  8773. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8774. //No fields are defined.
  8775. }
  8776. void handleStartTransactionResponse(char *payload, int gun_index)
  8777. {
  8778. mtrace();
  8779. char sstr[28]={ 0 };
  8780. int c = 0;
  8781. char *loc;
  8782. int transactionIdInt = 0;
  8783. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8784. DEBUG_INFO("handleStartTransactionResponse\n");
  8785. //****************expiryDate********************/
  8786. loc = strstr(payload, "expiryDate");
  8787. if(loc == NULL)
  8788. {
  8789. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8790. }
  8791. else
  8792. {
  8793. c = 0;
  8794. memset(sstr ,0, sizeof(sstr) );
  8795. while (loc[3+strlen("expiryDate")+c] != '\"')
  8796. {
  8797. sstr[c] = loc[3+strlen("expiryDate")+c];
  8798. c++;
  8799. }
  8800. sstr[c] = '\0';
  8801. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8802. }
  8803. //****************parentIdTag********************/
  8804. loc = strstr(payload, "parentIdTag");
  8805. if(loc == NULL)
  8806. {
  8807. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8808. }
  8809. else
  8810. {
  8811. c = 0;
  8812. memset(sstr ,0, sizeof(sstr) );
  8813. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8814. {
  8815. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8816. c++;
  8817. }
  8818. sstr[c] = '\0';
  8819. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8820. }
  8821. //****************status********************/
  8822. loc = strstr(payload, "status");
  8823. if(loc == NULL)
  8824. {
  8825. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8826. }
  8827. else
  8828. {
  8829. c = 0;
  8830. memset(sstr ,0, sizeof(sstr) );
  8831. while (loc[3+strlen("status")+c] != '\"')
  8832. {
  8833. sstr[c] = loc[3+strlen("status")+c];
  8834. c++;
  8835. }
  8836. sstr[c] = '\0';
  8837. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8838. }
  8839. //****************transactionId********************/
  8840. c=0;
  8841. loc = strstr(payload, "transactionId");
  8842. memset(sstr ,0, sizeof(sstr) );
  8843. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8844. {
  8845. sstr[c] = loc[strlen("transactionId")+2+c];
  8846. c++;
  8847. }
  8848. sstr[c] = '\0';
  8849. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8850. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8851. TransactionId[gun_index] = transactionIdInt;
  8852. DEBUG_INFO("gun_index: %d\n", gun_index);
  8853. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8854. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8855. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8856. #ifdef SystemLogMessage
  8857. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8858. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8859. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8860. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8861. #endif
  8862. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8863. {
  8864. //add Charging Record
  8865. SettingChargingRecord(gun_index, transactionIdInt);
  8866. }
  8867. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8868. }
  8869. void handleStatusNotificationResponse(char *payload, int gun_index)
  8870. {
  8871. mtrace();
  8872. printf("handleStatusNotificationResponse\n");
  8873. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8874. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8875. }
  8876. void handleStopTransactionnResponse(char *payload, int gun_index)
  8877. {
  8878. mtrace();
  8879. char sstr[30]={ 0 };
  8880. int c = 0;
  8881. char *loc;
  8882. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8883. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8884. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8885. loc = strstr(payload, "idTagInfo");
  8886. //***********************idTagInfo************************/
  8887. if(loc != NULL)
  8888. {
  8889. //***********************expiryDate************************/
  8890. loc = strstr(payload, "expiryDate");
  8891. if(loc != NULL)
  8892. {
  8893. memset(sstr ,0, sizeof(sstr) );
  8894. c = 0;
  8895. while (loc[3+strlen("expiryDate")+c] != '\"')
  8896. {
  8897. sstr[c] = loc[3+strlen("expiryDate")+c];
  8898. c++;
  8899. }
  8900. sstr[c] = '\0';
  8901. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8902. }
  8903. //***********************parentIdTag************************/
  8904. loc = strstr(payload, "parentIdTag");
  8905. if(loc != NULL)
  8906. {
  8907. memset(sstr ,0, sizeof(sstr) );
  8908. c = 0;
  8909. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8910. {
  8911. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8912. c++;
  8913. }
  8914. sstr[c] = '\0';
  8915. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8916. }
  8917. //***********************status************************/
  8918. loc = strstr(payload, "status");
  8919. memset(sstr ,0, sizeof(sstr) );
  8920. c = 0;
  8921. while (loc[3+strlen("status")+c] != '\"')
  8922. {
  8923. sstr[c] = loc[3+strlen("status")+c];
  8924. c++;
  8925. }
  8926. sstr[c] = '\0';
  8927. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8928. }
  8929. #ifdef SystemLogMessage
  8930. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8931. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8932. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8933. #endif
  8934. }
  8935. //==========================================
  8936. // Handle Error routine
  8937. //==========================================
  8938. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8939. {
  8940. mtrace();
  8941. #ifdef SystemLogMessage
  8942. DEBUG_INFO("errorCode: %s\n", errorCode);
  8943. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8944. DEBUG_INFO("errorDetails: %s\n", payload);
  8945. #endif
  8946. }
  8947. //===============================================
  8948. // Common routine
  8949. //===============================================
  8950. int initialConfigurationTable(void)
  8951. {
  8952. FILE *fp;
  8953. FILE *outfile;
  8954. char str[200]={0};
  8955. char sstr[100]={0};
  8956. int c = 0;
  8957. char *loc;
  8958. printf("initialConfigurationTable \n");
  8959. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8960. if((access("../Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  8961. {
  8962. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  8963. if(outfile == NULL) {
  8964. DEBUG_INFO("Error opening file");
  8965. return FALSE;
  8966. }
  8967. //outfile = fopen ("../Storage/OCPP/OCPPConfiguration", "a");
  8968. /*Core Profile*/
  8969. //AllowOfflineTxForUnknownId
  8970. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8971. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8974. //DEBUG_INFO("data=%s\n",data);
  8975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  8976. //AuthorizationCacheEnabled
  8977. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  8981. //AuthorizeRemoteTxRequests
  8982. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  8983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  8984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  8985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  8986. //BlinkRepeat
  8987. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  8988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  8989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  8990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  8991. //ClockAlignedDataInterval
  8992. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  8993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  8994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  8995. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  8996. //ConnectionTimeOut
  8997. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  8999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9001. //GetConfigurationMaxKeys
  9002. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9005. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9006. // HeartbeatInterval
  9007. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9009. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9011. // LightIntensity
  9012. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9016. // LocalAuthorizeOffline
  9017. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9021. // LocalPreAuthorize
  9022. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9025. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9026. // MaxEnergyOnInvalidId
  9027. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9030. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9031. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9032. // MeterValuesAlignedData
  9033. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9036. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9037. // MeterValuesAlignedDataMaxLength
  9038. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9039. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9041. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9042. // MeterValuesSampledData
  9043. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9046. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9047. // MeterValuesSampledDataMaxLength
  9048. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9051. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9052. // MeterValueSampleInterval
  9053. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9057. // MinimumStatusDuration
  9058. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9061. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9062. // NumberOfConnectors
  9063. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9065. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9066. {
  9067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9068. }
  9069. else
  9070. {
  9071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9072. }
  9073. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9074. // ResetRetries
  9075. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9079. // ConnectorPhaseRotation
  9080. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9081. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9083. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9084. // ConnectorPhaseRotationMaxLength
  9085. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9086. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9087. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9088. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9089. // StopTransactionOnEVSideDisconnect
  9090. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9091. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9092. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9093. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9094. // StopTransactionOnInvalidId
  9095. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9099. // StopTxnAlignedData
  9100. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9104. // StopTxnAlignedDataMaxLength
  9105. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9109. // StopTxnSampledData
  9110. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Energy.Active.Import.Register");
  9114. // StopTxnSampledDataMaxLength
  9115. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", "0");
  9119. // SupportedFeatureProfiles
  9120. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "0");
  9124. // SupportedFeatureProfilesMaxLength
  9125. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9129. // TransactionMessageAttempts
  9130. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9133. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9134. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9135. // TransactionMessageRetryInterval
  9136. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9138. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9139. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9141. // UnlockConnectorOnEVSideDisconnect
  9142. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9145. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9146. // WebSocketPingInterval
  9147. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9148. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9150. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9151. //* Local Auth List Management Profile*/
  9152. #if 0
  9153. //For OCTT Test Case
  9154. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9157. #endif
  9158. #if 1
  9159. //LocalAuthListEnabled
  9160. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9164. #endif
  9165. //LocalAuthListMaxLength
  9166. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9170. //SendLocalListMaxLength
  9171. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9175. //ReserveConnectorZeroSupported
  9176. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9180. //* Smart Charging Profile */
  9181. //ChargeProfileMaxStackLevel
  9182. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9184. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9186. // ChargingScheduleAllowedChargingRateUnit
  9187. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9189. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9190. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9191. // ChargingScheduleMaxPeriods
  9192. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9196. // ConnectorSwitch3to1PhaseSupported
  9197. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9201. // MaxChargingProfilesInstalled
  9202. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9206. fclose(outfile);
  9207. }
  9208. else
  9209. {
  9210. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9211. char keystr[60]={0};
  9212. char readonlystr[10]={0};
  9213. char valuestr[100]={0};
  9214. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9215. if(fp == NULL) {
  9216. DEBUG_INFO("Error opening file");
  9217. return FALSE;
  9218. }
  9219. while( fgets (str, sizeof(str), fp)!=NULL )
  9220. {
  9221. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9222. //*************************key*********************************/
  9223. loc = strstr(str, "key");
  9224. c = 0;
  9225. memset(sstr ,0, sizeof(sstr) );
  9226. while (loc[strlen("key")+3+c] != '\"')
  9227. {
  9228. sstr[c] = loc[strlen("key")+3+c];
  9229. c++;
  9230. }
  9231. sstr[c] = '\0';
  9232. strcpy(keystr,sstr);
  9233. //*************************readonly*********************************/
  9234. loc = strstr(str, "readonly");
  9235. c = 0;
  9236. memset(sstr ,0, sizeof(sstr) );
  9237. while (loc[strlen("readonly")+2+c] != ',')
  9238. {
  9239. sstr[c] = loc[strlen("readonly")+2+c];
  9240. c++;
  9241. }
  9242. sstr[c] = '\0';
  9243. strcpy(readonlystr,sstr);
  9244. //*************************value*********************************/
  9245. loc = strstr(str, "value");
  9246. c = 0;
  9247. memset(sstr ,0, sizeof(sstr) );
  9248. while (loc[strlen("value")+3+c] != '\"')
  9249. {
  9250. sstr[c] = loc[strlen("value")+3+c];
  9251. c++;
  9252. }
  9253. sstr[c] = '\0';
  9254. strcpy(valuestr,sstr);
  9255. // DEBUG_INFO("keystr=%s\n",keystr);
  9256. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9257. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9258. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9259. {
  9260. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9261. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9263. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9264. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9265. }
  9266. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9267. {
  9268. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9269. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9271. }
  9272. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9273. {
  9274. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9275. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9276. }
  9277. if(strcmp(keystr, "BlinkRepeat") == 0)
  9278. {
  9279. //Charger.BlinkRepeat = Integer.parseInt(value);
  9280. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9282. }
  9283. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9284. {
  9285. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9286. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9287. }
  9288. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9289. {
  9290. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9292. }
  9293. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9294. {
  9295. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9297. }
  9298. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9299. {
  9300. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9302. HeartBeatWaitTime = atoi(valuestr);
  9303. }
  9304. if(strcmp(keystr, "LightIntensity") == 0)
  9305. {
  9306. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9308. }
  9309. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9310. {
  9311. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9313. }
  9314. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9315. {
  9316. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9318. }
  9319. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9320. {
  9321. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9323. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9324. }
  9325. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9326. {
  9327. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9328. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9329. }
  9330. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9331. {
  9332. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9334. }
  9335. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9336. {
  9337. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9338. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9339. }
  9340. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9341. {
  9342. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9344. }
  9345. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9346. {
  9347. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9349. }
  9350. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9351. {
  9352. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9353. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9354. }
  9355. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9356. {
  9357. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9359. }
  9360. if(strcmp(keystr, "ResetRetries") == 0)
  9361. {
  9362. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9363. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9364. }
  9365. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9366. {
  9367. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9369. }
  9370. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9371. {
  9372. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9373. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9374. }
  9375. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9376. {
  9377. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9379. }
  9380. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9381. {
  9382. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9383. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9384. }
  9385. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9386. {
  9387. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9388. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9389. }
  9390. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9391. {
  9392. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9394. }
  9395. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9396. {
  9397. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9399. }
  9400. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9401. {
  9402. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9404. }
  9405. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9406. {
  9407. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9409. }
  9410. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9411. {
  9412. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9413. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9414. }
  9415. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9416. {
  9417. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9418. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9419. TransactionMessageAttemptsValue = atoi(valuestr);
  9420. }
  9421. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9422. {
  9423. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9425. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9426. }
  9427. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9428. {
  9429. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9431. }
  9432. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9433. {
  9434. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9436. }
  9437. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9438. {
  9439. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9441. }
  9442. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9443. {
  9444. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9446. }
  9447. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9448. {
  9449. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9451. }
  9452. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9453. {
  9454. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9456. }
  9457. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9458. {
  9459. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9460. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9461. }
  9462. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9463. {
  9464. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9466. }
  9467. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9468. {
  9469. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9470. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9471. }
  9472. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9473. {
  9474. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9475. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9476. }
  9477. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9478. {
  9479. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9480. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9481. }
  9482. }
  9483. fclose(fp);
  9484. }
  9485. return 0;
  9486. }
  9487. void StoreConfigurationTable(void)
  9488. {
  9489. FILE *outfile;
  9490. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9491. if(outfile == NULL)
  9492. {
  9493. DEBUG_INFO("Error opening file");
  9494. return ;
  9495. }
  9496. /*Core Profile*/
  9497. //AllowOfflineTxForUnknownId
  9498. /*
  9499. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9500. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9501. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9502. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9503. */
  9504. //DEBUG_INFO("data=%s\n",data);
  9505. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9506. //AuthorizationCacheEnabled
  9507. /*
  9508. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9509. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9511. */
  9512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9513. //AuthorizeRemoteTxRequests
  9514. /*
  9515. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9517. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9518. */
  9519. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9520. //BlinkRepeat
  9521. /*
  9522. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9523. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9524. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9525. */
  9526. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9527. //ClockAlignedDataInterval
  9528. /*
  9529. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9532. */
  9533. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9534. //ConnectionTimeOut
  9535. /*
  9536. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9537. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9538. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9539. */
  9540. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9541. //GetConfigurationMaxKeys
  9542. /*
  9543. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9544. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9546. */
  9547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9548. // HeartbeatInterval
  9549. /*
  9550. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9552. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9553. */
  9554. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9555. // LightIntensity
  9556. /*
  9557. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9558. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9559. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9560. */
  9561. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9562. // LocalAuthorizeOffline
  9563. /*
  9564. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9567. */
  9568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9569. // LocalPreAuthorize
  9570. /*
  9571. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9573. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9574. */
  9575. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9576. // MaxEnergyOnInvalidId
  9577. /*
  9578. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9579. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9580. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9581. */
  9582. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9584. // MeterValuesAlignedData
  9585. /*
  9586. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9589. */
  9590. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9591. // MeterValuesAlignedDataMaxLength
  9592. /*
  9593. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9594. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9596. */
  9597. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9598. // MeterValuesSampledData
  9599. /*
  9600. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9601. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9603. */
  9604. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9605. // MeterValuesSampledDataMaxLength
  9606. /*
  9607. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9608. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9610. */
  9611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9612. // MeterValueSampleInterval
  9613. /*
  9614. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9617. */
  9618. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9619. // MinimumStatusDuration
  9620. /*
  9621. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9622. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9624. */
  9625. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9626. // NumberOfConnectors
  9627. /*
  9628. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9630. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9631. {
  9632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9633. }
  9634. else
  9635. {
  9636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9637. }
  9638. */
  9639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9640. // ResetRetries
  9641. /*
  9642. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9645. */
  9646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9647. // ConnectorPhaseRotation
  9648. /*
  9649. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9652. */
  9653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9654. // ConnectorPhaseRotationMaxLength
  9655. /*
  9656. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9659. */
  9660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9661. // StopTransactionOnEVSideDisconnect
  9662. /*
  9663. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9666. */
  9667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9668. // StopTransactionOnInvalidId
  9669. /*
  9670. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9673. */
  9674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9675. // StopTxnAlignedData
  9676. /*
  9677. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9680. */
  9681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9682. // StopTxnAlignedDataMaxLength
  9683. /*
  9684. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9687. */
  9688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9689. // StopTxnSampledData
  9690. /*
  9691. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9694. */
  9695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9696. // StopTxnSampledDataMaxLength
  9697. /*
  9698. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9701. */
  9702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9703. // SupportedFeatureProfiles
  9704. /*
  9705. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9708. */
  9709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9710. // SupportedFeatureProfilesMaxLength
  9711. /*
  9712. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9715. */
  9716. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9717. // TransactionMessageAttempts
  9718. /*
  9719. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9722. */
  9723. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9724. // TransactionMessageRetryInterval
  9725. /*
  9726. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9729. */
  9730. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9731. // UnlockConnectorOnEVSideDisconnect
  9732. /*
  9733. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9736. */
  9737. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9738. // WebSocketPingInterval
  9739. /*
  9740. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9743. */
  9744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9745. //* Local Auth List Management Profile*/
  9746. //LocalAuthListEnabled
  9747. /*
  9748. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9751. */
  9752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9753. //LocalAuthListMaxLength
  9754. /*
  9755. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9758. */
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9760. //SendLocalListMaxLength
  9761. /*
  9762. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9765. */
  9766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9767. //ReserveConnectorZeroSupported
  9768. /*
  9769. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9772. */
  9773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9774. //* Smart Charging Profile */
  9775. //ChargeProfileMaxStackLevel
  9776. /*
  9777. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9780. */
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9782. // ChargingScheduleAllowedChargingRateUnit
  9783. /*
  9784. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9786. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9787. */
  9788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9789. // ChargingScheduleMaxPeriods
  9790. /*
  9791. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9794. */
  9795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9796. // ConnectorSwitch3to1PhaseSupported
  9797. /*
  9798. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9801. */
  9802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9803. // MaxChargingProfilesInstalled
  9804. /*
  9805. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9808. */
  9809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9810. fclose(outfile);
  9811. }
  9812. void getKeyValue(char *keyReq)
  9813. {
  9814. int isEmpty = FALSE;
  9815. int isKnowKey = FALSE;
  9816. //int unKnowIndex = 0;
  9817. DEBUG_INFO("getKeyValue \n");
  9818. DEBUG_INFO("keyReq=%s \n",keyReq);
  9819. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9820. isEmpty = TRUE;
  9821. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9822. {
  9823. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9824. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9827. {
  9828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9829. }
  9830. else
  9831. {
  9832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9833. }
  9834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9835. isKnowKey = TRUE;
  9836. }
  9837. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9838. {
  9839. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9842. {
  9843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9844. }
  9845. else
  9846. {
  9847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9848. }
  9849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9850. isKnowKey = TRUE;
  9851. }
  9852. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9853. {
  9854. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9857. {
  9858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9859. }
  9860. else
  9861. {
  9862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9863. }
  9864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9865. isKnowKey = TRUE;
  9866. }
  9867. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9868. {
  9869. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9872. {
  9873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9874. }
  9875. else
  9876. {
  9877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9878. }
  9879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9880. isKnowKey = TRUE;
  9881. }
  9882. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9883. {
  9884. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9886. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9887. {
  9888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9889. }
  9890. else
  9891. {
  9892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9893. }
  9894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9895. isKnowKey = TRUE;
  9896. }
  9897. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9898. {
  9899. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9901. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9902. {
  9903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9904. }
  9905. else
  9906. {
  9907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9908. }
  9909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9910. isKnowKey = TRUE;
  9911. }
  9912. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9913. {
  9914. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9916. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9917. {
  9918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9919. }
  9920. else
  9921. {
  9922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9923. }
  9924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9925. isKnowKey = TRUE;
  9926. }
  9927. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9928. {
  9929. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9932. {
  9933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9934. }
  9935. else
  9936. {
  9937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9938. }
  9939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9940. isKnowKey = TRUE;
  9941. }
  9942. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9943. {
  9944. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9946. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9947. {
  9948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9949. }
  9950. else
  9951. {
  9952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9953. }
  9954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9955. isKnowKey = TRUE;
  9956. }
  9957. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9958. {
  9959. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9961. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9962. {
  9963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9964. }
  9965. else
  9966. {
  9967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9968. }
  9969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9970. isKnowKey = TRUE;
  9971. }
  9972. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9973. {
  9974. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9976. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9977. {
  9978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9979. }
  9980. else
  9981. {
  9982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  9983. }
  9984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  9985. isKnowKey = TRUE;
  9986. }
  9987. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  9988. {
  9989. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  9990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  9991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  9992. {
  9993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  9994. }
  9995. else
  9996. {
  9997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  9998. }
  9999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10000. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10001. isKnowKey = TRUE;
  10002. }
  10003. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10004. {
  10005. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10007. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10008. {
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10010. }
  10011. else
  10012. {
  10013. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10014. }
  10015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10016. isKnowKey = TRUE;
  10017. }
  10018. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10019. {
  10020. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10023. {
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10025. }
  10026. else
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10029. }
  10030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10031. isKnowKey = TRUE;
  10032. }
  10033. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10034. {
  10035. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10037. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10038. {
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10040. }
  10041. else
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10044. }
  10045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10046. isKnowKey = TRUE;
  10047. }
  10048. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10049. {
  10050. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10052. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10053. {
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10055. }
  10056. else
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10059. }
  10060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10061. isKnowKey = TRUE;
  10062. }
  10063. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10064. {
  10065. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10068. {
  10069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10070. }
  10071. else
  10072. {
  10073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10074. }
  10075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10076. isKnowKey = TRUE;
  10077. }
  10078. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10079. {
  10080. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10082. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10083. {
  10084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10085. }
  10086. else
  10087. {
  10088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10089. }
  10090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10091. isKnowKey = TRUE;
  10092. }
  10093. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10094. {
  10095. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10097. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10098. {
  10099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10100. }
  10101. else
  10102. {
  10103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10104. }
  10105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10106. isKnowKey = TRUE;
  10107. }
  10108. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10109. {
  10110. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10112. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10113. {
  10114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10115. }
  10116. else
  10117. {
  10118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10119. }
  10120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10121. isKnowKey = TRUE;
  10122. }
  10123. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10124. {
  10125. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10128. {
  10129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10130. }
  10131. else
  10132. {
  10133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10134. }
  10135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10136. isKnowKey = TRUE;
  10137. }
  10138. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10139. {
  10140. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10143. {
  10144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10145. }
  10146. else
  10147. {
  10148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10149. }
  10150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10151. isKnowKey = TRUE;
  10152. }
  10153. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10154. {
  10155. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10157. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10158. {
  10159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10160. }
  10161. else
  10162. {
  10163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10164. }
  10165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10166. isKnowKey = TRUE;
  10167. }
  10168. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10169. {
  10170. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10173. {
  10174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10175. }
  10176. else
  10177. {
  10178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10179. }
  10180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10181. isKnowKey = TRUE;
  10182. }
  10183. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10184. {
  10185. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10187. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10188. {
  10189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10190. }
  10191. else
  10192. {
  10193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10194. }
  10195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10196. isKnowKey = TRUE;
  10197. }
  10198. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10199. {
  10200. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10202. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10203. {
  10204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10205. }
  10206. else
  10207. {
  10208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10209. }
  10210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10211. isKnowKey = TRUE;
  10212. }
  10213. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10214. {
  10215. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10217. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10218. {
  10219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10220. }
  10221. else
  10222. {
  10223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10224. }
  10225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10226. isKnowKey = TRUE;
  10227. }
  10228. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10229. {
  10230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10233. {
  10234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10235. }
  10236. else
  10237. {
  10238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10239. }
  10240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10241. isKnowKey = TRUE;
  10242. }
  10243. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10244. {
  10245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10248. {
  10249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10250. }
  10251. else
  10252. {
  10253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10254. }
  10255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10256. isKnowKey = TRUE;
  10257. }
  10258. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10259. {
  10260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10263. {
  10264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10265. }
  10266. else
  10267. {
  10268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10269. }
  10270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10271. isKnowKey = TRUE;
  10272. }
  10273. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10274. {
  10275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10278. {
  10279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10280. }
  10281. else
  10282. {
  10283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10284. }
  10285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10286. isKnowKey = TRUE;
  10287. }
  10288. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10289. {
  10290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10293. {
  10294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10295. }
  10296. else
  10297. {
  10298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10299. }
  10300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10301. isKnowKey = TRUE;
  10302. }
  10303. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10304. {
  10305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10308. {
  10309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10310. }
  10311. else
  10312. {
  10313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10314. }
  10315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10316. isKnowKey = TRUE;
  10317. }
  10318. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10319. {
  10320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10323. {
  10324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10325. }
  10326. else
  10327. {
  10328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10329. }
  10330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10331. isKnowKey = TRUE;
  10332. }
  10333. #if 0
  10334. //For OCTT Test Case
  10335. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10336. {
  10337. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10339. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10340. {
  10341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10342. }
  10343. else
  10344. {
  10345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10346. }
  10347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10348. isKnowKey = TRUE;
  10349. }
  10350. #endif
  10351. #if 1
  10352. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10353. {
  10354. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10355. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10356. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10357. {
  10358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10359. }
  10360. else
  10361. {
  10362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10363. }
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10365. isKnowKey = TRUE;
  10366. }
  10367. #endif
  10368. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10369. {
  10370. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10372. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10373. {
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10375. }
  10376. else
  10377. {
  10378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10379. }
  10380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10381. isKnowKey = TRUE;
  10382. }
  10383. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10384. {
  10385. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10387. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10390. }
  10391. else
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10394. }
  10395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10396. isKnowKey = TRUE;
  10397. }
  10398. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10399. {
  10400. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10402. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10405. }
  10406. else
  10407. {
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10409. }
  10410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10411. isKnowKey = TRUE;
  10412. }
  10413. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10414. {
  10415. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10417. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10420. }
  10421. else
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10424. }
  10425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10426. isKnowKey = TRUE;
  10427. }
  10428. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10429. {
  10430. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10432. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10435. }
  10436. else
  10437. {
  10438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10439. }
  10440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10441. isKnowKey = TRUE;
  10442. }
  10443. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10444. {
  10445. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10447. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10448. {
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10450. }
  10451. else
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10454. }
  10455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10456. isKnowKey = TRUE;
  10457. }
  10458. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10459. {
  10460. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10462. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10465. }
  10466. else
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10469. }
  10470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10471. isKnowKey = TRUE;
  10472. }
  10473. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10474. {
  10475. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10477. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10480. }
  10481. else
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10484. }
  10485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10486. isKnowKey = TRUE;
  10487. }
  10488. //=========================================================
  10489. if(!isEmpty && !isKnowKey)
  10490. {
  10491. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10492. strcpy(unknownkey[UnknownKeynum], keyReq);
  10493. UnknownKeynum = UnknownKeynum + 1;
  10494. }
  10495. }
  10496. void processUnkownKey(void)
  10497. {
  10498. DEBUG_INFO("processUnkownKey\n");
  10499. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10500. for(int index=0; index < UnknownKeynum; index++)
  10501. {
  10502. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10503. {
  10504. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10505. }
  10506. }
  10507. }
  10508. int setKeyValue(char *key, char *value)
  10509. {
  10510. int isSuccess = NotSupported;
  10511. int check_ascii=0;
  10512. char str[10]={0};
  10513. #ifdef Debug
  10514. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10515. #endif
  10516. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10517. {
  10518. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10520. {
  10521. strcpy(str, (const char*)value);
  10522. for(int i = 0; str[i]; i++){
  10523. str[i] = tolower(str[i]);
  10524. }
  10525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10526. isSuccess = ConfigurationStatus_Accepted;
  10527. }
  10528. else
  10529. {
  10530. isSuccess = ConfigurationStatus_Rejected;
  10531. }
  10532. }
  10533. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10534. {
  10535. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10536. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10537. {
  10538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10539. isSuccess = ConfigurationStatus_Accepted;
  10540. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10541. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10542. }
  10543. else
  10544. {
  10545. isSuccess = ConfigurationStatus_Rejected;
  10546. }
  10547. }
  10548. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10549. {
  10550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10551. {
  10552. strcpy(str, (const char*)value);
  10553. for(int i = 0; str[i]; i++)
  10554. {
  10555. str[i] = tolower(str[i]);
  10556. }
  10557. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10559. isSuccess = ConfigurationStatus_Accepted;
  10560. }
  10561. else
  10562. {
  10563. isSuccess = ConfigurationStatus_Rejected;
  10564. }
  10565. }
  10566. if(strcmp(key, "BlinkRepeat") == 0)
  10567. {
  10568. //Charger.BlinkRepeat = Integer.parseInt(value);
  10569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10570. {
  10571. check_ascii = value[0];
  10572. if( (check_ascii < 48) || (check_ascii > 57) )
  10573. {
  10574. isSuccess = ConfigurationStatus_Rejected;
  10575. }
  10576. else
  10577. {
  10578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10579. isSuccess = ConfigurationStatus_Accepted;
  10580. }
  10581. }
  10582. else
  10583. {
  10584. isSuccess = ConfigurationStatus_Rejected;
  10585. }
  10586. }
  10587. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10588. {
  10589. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10590. {
  10591. check_ascii = value[0];
  10592. if( (check_ascii < 48) || (check_ascii > 57) )
  10593. {
  10594. isSuccess = ConfigurationStatus_Rejected;
  10595. }
  10596. else
  10597. {
  10598. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10600. isSuccess = ConfigurationStatus_Accepted;
  10601. }
  10602. }
  10603. else
  10604. {
  10605. isSuccess = ConfigurationStatus_Rejected;
  10606. }
  10607. }
  10608. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10609. {
  10610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10611. {
  10612. check_ascii = value[0];
  10613. if( (check_ascii < 48) || (check_ascii > 57) )
  10614. {
  10615. isSuccess = ConfigurationStatus_Rejected;
  10616. }
  10617. else
  10618. {
  10619. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10620. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10621. isSuccess = ConfigurationStatus_Accepted;
  10622. }
  10623. }
  10624. else
  10625. {
  10626. isSuccess = ConfigurationStatus_Rejected;
  10627. }
  10628. }
  10629. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10630. {
  10631. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10632. {
  10633. check_ascii = value[0];
  10634. if( (check_ascii < 48) || (check_ascii > 57) )
  10635. {
  10636. isSuccess = ConfigurationStatus_Rejected;
  10637. }
  10638. else
  10639. {
  10640. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10642. isSuccess = ConfigurationStatus_Accepted;
  10643. }
  10644. }
  10645. else
  10646. {
  10647. isSuccess = ConfigurationStatus_Rejected;
  10648. }
  10649. }
  10650. if(strcmp(key, "HeartbeatInterval") == 0)
  10651. {
  10652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10653. {
  10654. check_ascii = value[0];
  10655. if( (check_ascii < 48) || (check_ascii > 57) )
  10656. {
  10657. isSuccess = ConfigurationStatus_Rejected;
  10658. }
  10659. else
  10660. {
  10661. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10662. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10663. HeartBeatWaitTime = atoi(value);
  10664. isSuccess = ConfigurationStatus_Accepted;
  10665. }
  10666. }
  10667. else
  10668. {
  10669. isSuccess = ConfigurationStatus_Rejected;
  10670. }
  10671. }
  10672. if(strcmp(key, "LightIntensity") == 0)
  10673. {
  10674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10675. {
  10676. check_ascii = value[0];
  10677. if( (check_ascii < 48) || (check_ascii > 57) )
  10678. {
  10679. isSuccess = ConfigurationStatus_Rejected;
  10680. }
  10681. else
  10682. {
  10683. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10684. isSuccess = ConfigurationStatus_Accepted;
  10685. }
  10686. }
  10687. else
  10688. {
  10689. isSuccess = ConfigurationStatus_Rejected;
  10690. }
  10691. }
  10692. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10693. {
  10694. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10695. {
  10696. strcpy(str, (const char*)value);
  10697. for(int i = 0; str[i]; i++)
  10698. {
  10699. str[i] = tolower(str[i]);
  10700. }
  10701. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10702. isSuccess = ConfigurationStatus_Accepted;
  10703. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10704. }
  10705. else
  10706. {
  10707. isSuccess = ConfigurationStatus_Rejected;
  10708. }
  10709. }
  10710. if(strcmp(key, "LocalPreAuthorize") == 0)
  10711. {
  10712. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10713. {
  10714. strcpy(str, (const char*)value);
  10715. for(int i = 0; str[i]; i++)
  10716. {
  10717. str[i] = tolower(str[i]);
  10718. }
  10719. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10720. isSuccess = ConfigurationStatus_Accepted;
  10721. }
  10722. else
  10723. {
  10724. isSuccess = ConfigurationStatus_Rejected;
  10725. }
  10726. }
  10727. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10728. {
  10729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10730. {
  10731. check_ascii = value[0];
  10732. if( (check_ascii < 48) || (check_ascii > 57) )
  10733. {
  10734. isSuccess = ConfigurationStatus_Rejected;
  10735. }
  10736. else
  10737. {
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10739. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10740. isSuccess = ConfigurationStatus_Accepted;
  10741. }
  10742. }
  10743. else
  10744. {
  10745. isSuccess = ConfigurationStatus_Rejected;
  10746. }
  10747. }
  10748. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10749. {
  10750. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10751. {
  10752. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10753. isSuccess = ConfigurationStatus_Accepted;
  10754. }
  10755. else
  10756. {
  10757. isSuccess = ConfigurationStatus_Rejected;
  10758. }
  10759. }
  10760. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10761. {
  10762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10763. {
  10764. check_ascii = value[0];
  10765. if( (check_ascii < 48) || (check_ascii > 57) )
  10766. {
  10767. isSuccess = ConfigurationStatus_Rejected;
  10768. }
  10769. else
  10770. {
  10771. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10772. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10773. isSuccess = ConfigurationStatus_Accepted;
  10774. }
  10775. }
  10776. else
  10777. {
  10778. isSuccess = ConfigurationStatus_Rejected;
  10779. }
  10780. }
  10781. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10782. {
  10783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10784. {
  10785. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10786. isSuccess = ConfigurationStatus_Accepted;
  10787. }
  10788. else
  10789. {
  10790. isSuccess = ConfigurationStatus_Rejected;
  10791. }
  10792. }
  10793. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10794. {
  10795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10796. {
  10797. check_ascii = value[0];
  10798. if( (check_ascii < 48) || (check_ascii > 57) )
  10799. {
  10800. isSuccess = ConfigurationStatus_Rejected;
  10801. }
  10802. else
  10803. {
  10804. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10806. isSuccess = ConfigurationStatus_Accepted;
  10807. }
  10808. }
  10809. else
  10810. {
  10811. isSuccess = ConfigurationStatus_Rejected;
  10812. }
  10813. }
  10814. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10815. {
  10816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10817. {
  10818. check_ascii = value[0];
  10819. if( (check_ascii < 48) || (check_ascii > 57) )
  10820. {
  10821. isSuccess = ConfigurationStatus_Rejected;
  10822. }
  10823. else
  10824. {
  10825. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10827. isSuccess = ConfigurationStatus_Accepted;
  10828. }
  10829. }
  10830. else
  10831. {
  10832. isSuccess = ConfigurationStatus_Rejected;
  10833. }
  10834. }
  10835. if(strcmp(key, "MinimumStatusDuration") == 0)
  10836. {
  10837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10838. {
  10839. check_ascii = value[0];
  10840. if( (check_ascii < 48) || (check_ascii > 57) )
  10841. {
  10842. isSuccess = ConfigurationStatus_Rejected;
  10843. }
  10844. else
  10845. {
  10846. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10848. isSuccess = ConfigurationStatus_Accepted;
  10849. }
  10850. }
  10851. else
  10852. {
  10853. isSuccess = ConfigurationStatus_Rejected;
  10854. }
  10855. }
  10856. if(strcmp(key, "NumberOfConnectors") == 0)
  10857. {
  10858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10859. {
  10860. check_ascii = value[0];
  10861. if( (check_ascii < 48) || (check_ascii > 57) )
  10862. {
  10863. isSuccess = ConfigurationStatus_Rejected;
  10864. }
  10865. else
  10866. {
  10867. //Charger.ResetRetries = Integer.parseInt(value);
  10868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10869. isSuccess = ConfigurationStatus_Accepted;
  10870. }
  10871. }
  10872. else
  10873. {
  10874. isSuccess = ConfigurationStatus_Rejected;
  10875. }
  10876. }
  10877. if(strcmp(key, "ResetRetries") == 0)
  10878. {
  10879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10880. {
  10881. check_ascii = value[0];
  10882. if( (check_ascii < 48) || (check_ascii > 57) )
  10883. {
  10884. isSuccess = ConfigurationStatus_Rejected;
  10885. }
  10886. else
  10887. {
  10888. //Charger.ResetRetries = Integer.parseInt(value);
  10889. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10890. isSuccess = ConfigurationStatus_Accepted;
  10891. }
  10892. }
  10893. else
  10894. {
  10895. isSuccess = ConfigurationStatus_Rejected;
  10896. }
  10897. }
  10898. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10899. {
  10900. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10901. {
  10902. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10903. isSuccess = ConfigurationStatus_Accepted;
  10904. }
  10905. else
  10906. {
  10907. isSuccess = ConfigurationStatus_Rejected;
  10908. }
  10909. }
  10910. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10911. {
  10912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10913. {
  10914. check_ascii = value[0];
  10915. if( (check_ascii < 48) || (check_ascii > 57) )
  10916. {
  10917. isSuccess = ConfigurationStatus_Rejected;
  10918. }
  10919. else
  10920. {
  10921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10922. isSuccess = ConfigurationStatus_Accepted;
  10923. }
  10924. }
  10925. else
  10926. {
  10927. isSuccess = ConfigurationStatus_Rejected;
  10928. }
  10929. }
  10930. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10931. {
  10932. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10933. {
  10934. strcpy(str, (const char*)value);
  10935. for(int i = 0; str[i]; i++)
  10936. {
  10937. str[i] = tolower(str[i]);
  10938. }
  10939. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10941. isSuccess = ConfigurationStatus_Accepted;
  10942. }
  10943. else
  10944. {
  10945. isSuccess = ConfigurationStatus_Rejected;
  10946. }
  10947. }
  10948. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10949. {
  10950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10951. {
  10952. strcpy(str, (const char*)value);
  10953. for(int i = 0; str[i]; i++)
  10954. {
  10955. str[i] = tolower(str[i]);
  10956. }
  10957. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10959. isSuccess = ConfigurationStatus_Accepted;
  10960. }
  10961. else
  10962. {
  10963. isSuccess = ConfigurationStatus_Rejected;
  10964. }
  10965. }
  10966. if(strcmp(key, "StopTxnAlignedData") == 0)
  10967. {
  10968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10969. {
  10970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10971. isSuccess = ConfigurationStatus_Accepted;
  10972. }
  10973. else
  10974. {
  10975. isSuccess = ConfigurationStatus_Rejected;
  10976. }
  10977. }
  10978. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  10979. {
  10980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10981. {
  10982. check_ascii = value[0];
  10983. if( (check_ascii < 48) || (check_ascii > 57) )
  10984. {
  10985. isSuccess = ConfigurationStatus_Rejected;
  10986. }
  10987. else
  10988. {
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  10990. isSuccess = ConfigurationStatus_Accepted;
  10991. }
  10992. }
  10993. else
  10994. {
  10995. isSuccess = ConfigurationStatus_Rejected;
  10996. }
  10997. }
  10998. if(strcmp(key, "StopTxnSampledData") == 0)
  10999. {
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11001. {
  11002. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11003. isSuccess = ConfigurationStatus_Accepted;
  11004. }
  11005. else
  11006. {
  11007. isSuccess = ConfigurationStatus_Rejected;
  11008. }
  11009. }
  11010. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11011. {
  11012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11013. {
  11014. check_ascii = value[0];
  11015. if( (check_ascii < 48) || (check_ascii > 57) )
  11016. {
  11017. isSuccess = ConfigurationStatus_Rejected;
  11018. }
  11019. else
  11020. {
  11021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11022. isSuccess = ConfigurationStatus_Accepted;
  11023. }
  11024. }
  11025. else
  11026. {
  11027. isSuccess = ConfigurationStatus_Rejected;
  11028. }
  11029. }
  11030. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11031. {
  11032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11033. {
  11034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11035. isSuccess = ConfigurationStatus_Accepted;
  11036. }
  11037. else
  11038. {
  11039. isSuccess = ConfigurationStatus_Rejected;
  11040. }
  11041. }
  11042. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11043. {
  11044. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11045. {
  11046. check_ascii = value[0];
  11047. if( (check_ascii < 48) || (check_ascii > 57) )
  11048. {
  11049. isSuccess = ConfigurationStatus_Rejected;
  11050. }
  11051. else
  11052. {
  11053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11054. isSuccess = ConfigurationStatus_Accepted;
  11055. }
  11056. }
  11057. else
  11058. {
  11059. isSuccess = ConfigurationStatus_Rejected;
  11060. }
  11061. }
  11062. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11063. {
  11064. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11065. {
  11066. check_ascii = value[0];
  11067. if( (check_ascii < 48) || (check_ascii > 57) )
  11068. {
  11069. isSuccess = ConfigurationStatus_Rejected;
  11070. }
  11071. else
  11072. {
  11073. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11074. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11075. TransactionMessageAttemptsValue = atoi(value);
  11076. isSuccess = ConfigurationStatus_Accepted;
  11077. }
  11078. }
  11079. else
  11080. {
  11081. isSuccess = ConfigurationStatus_Rejected;
  11082. }
  11083. }
  11084. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11085. {
  11086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11087. {
  11088. check_ascii = value[0];
  11089. if( (check_ascii < 48) || (check_ascii > 57) )
  11090. {
  11091. isSuccess = ConfigurationStatus_Rejected;
  11092. }
  11093. else
  11094. {
  11095. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11097. TransactionMessageRetryIntervalValue = atoi(value);
  11098. isSuccess = ConfigurationStatus_Accepted;
  11099. }
  11100. }
  11101. else
  11102. {
  11103. isSuccess = ConfigurationStatus_Rejected;
  11104. }
  11105. }
  11106. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11107. {
  11108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11109. {
  11110. strcpy(str, (const char*)value);
  11111. for(int i = 0; str[i]; i++)
  11112. {
  11113. str[i] = tolower(str[i]);
  11114. }
  11115. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11117. isSuccess = ConfigurationStatus_Accepted;
  11118. }
  11119. else
  11120. {
  11121. isSuccess = ConfigurationStatus_Rejected;
  11122. }
  11123. }
  11124. if(strcmp(key, "WebSocketPingInterval") == 0)
  11125. {
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11127. {
  11128. check_ascii = value[0];
  11129. if( (check_ascii < 48) || (check_ascii > 57) )
  11130. {
  11131. isSuccess = ConfigurationStatus_Rejected;
  11132. }
  11133. else
  11134. {
  11135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11136. isSuccess = ConfigurationStatus_Accepted;
  11137. }
  11138. }
  11139. else
  11140. {
  11141. isSuccess = ConfigurationStatus_Rejected;
  11142. }
  11143. }
  11144. #if 0
  11145. //For OCPP Test Case
  11146. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11147. {
  11148. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11149. {
  11150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11151. isSuccess = ConfigurationStatus_Accepted;
  11152. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11153. }
  11154. else
  11155. {
  11156. isSuccess = ConfigurationStatus_Rejected;
  11157. }
  11158. }
  11159. #endif
  11160. #if 1
  11161. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11162. {
  11163. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11164. {
  11165. strcpy(str, (const char*)value);
  11166. for(int i = 0; str[i]; i++)
  11167. {
  11168. str[i] = tolower(str[i]);
  11169. }
  11170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11171. isSuccess = ConfigurationStatus_Accepted;
  11172. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11173. }
  11174. else
  11175. {
  11176. isSuccess = ConfigurationStatus_Rejected;
  11177. }
  11178. }
  11179. #endif
  11180. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11181. {
  11182. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11183. {
  11184. check_ascii = value[0];
  11185. if( (check_ascii < 48) || (check_ascii > 57) )
  11186. {
  11187. isSuccess = ConfigurationStatus_Rejected;
  11188. }
  11189. else
  11190. {
  11191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11192. isSuccess = ConfigurationStatus_Accepted;
  11193. }
  11194. }
  11195. else
  11196. {
  11197. isSuccess = ConfigurationStatus_Rejected;
  11198. }
  11199. }
  11200. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11201. {
  11202. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11203. {
  11204. check_ascii = value[0];
  11205. if( (check_ascii < 48) || (check_ascii > 57) )
  11206. {
  11207. isSuccess = ConfigurationStatus_Rejected;
  11208. }
  11209. else
  11210. {
  11211. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11212. isSuccess = ConfigurationStatus_Accepted;
  11213. }
  11214. }
  11215. else
  11216. {
  11217. isSuccess = ConfigurationStatus_Rejected;
  11218. }
  11219. }
  11220. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11221. {
  11222. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11223. {
  11224. strcpy(str, (const char*)value);
  11225. for(int i = 0; str[i]; i++)
  11226. {
  11227. str[i] = tolower(str[i]);
  11228. }
  11229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11230. isSuccess = ConfigurationStatus_Accepted;
  11231. }
  11232. else
  11233. {
  11234. isSuccess = ConfigurationStatus_Rejected;
  11235. }
  11236. }
  11237. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11238. {
  11239. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11240. {
  11241. check_ascii = value[0];
  11242. if( (check_ascii < 48) || (check_ascii > 57) )
  11243. {
  11244. isSuccess = ConfigurationStatus_Rejected;
  11245. }
  11246. else
  11247. {
  11248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11249. isSuccess = ConfigurationStatus_Accepted;
  11250. }
  11251. }
  11252. else
  11253. {
  11254. isSuccess = ConfigurationStatus_Rejected;
  11255. }
  11256. }
  11257. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11258. {
  11259. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11260. {
  11261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11262. isSuccess = ConfigurationStatus_Accepted;
  11263. }
  11264. else
  11265. {
  11266. isSuccess = ConfigurationStatus_Rejected;
  11267. }
  11268. }
  11269. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11270. {
  11271. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11272. {
  11273. check_ascii = value[0];
  11274. if( (check_ascii < 48) || (check_ascii > 57) )
  11275. {
  11276. isSuccess = ConfigurationStatus_Rejected;
  11277. }
  11278. else
  11279. {
  11280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11281. isSuccess = ConfigurationStatus_Accepted;
  11282. }
  11283. }
  11284. else
  11285. {
  11286. isSuccess = ConfigurationStatus_Rejected;
  11287. }
  11288. }
  11289. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11290. {
  11291. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11292. {
  11293. strcpy(str, (const char*)value);
  11294. for(int i = 0; str[i]; i++)
  11295. {
  11296. str[i] = tolower(str[i]);
  11297. }
  11298. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11299. isSuccess = ConfigurationStatus_Accepted;
  11300. }
  11301. else
  11302. {
  11303. isSuccess = ConfigurationStatus_Rejected;
  11304. }
  11305. }
  11306. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11307. {
  11308. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11309. {
  11310. check_ascii = value[0];
  11311. if( (check_ascii < 48) || (check_ascii > 57) )
  11312. {
  11313. isSuccess = ConfigurationStatus_Rejected;
  11314. }
  11315. else
  11316. {
  11317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11318. isSuccess = ConfigurationStatus_Accepted;
  11319. }
  11320. }
  11321. else
  11322. {
  11323. isSuccess = ConfigurationStatus_Rejected;
  11324. }
  11325. }
  11326. return isSuccess;
  11327. }
  11328. int updateSetting(char *key, char *value)
  11329. {
  11330. mtrace();
  11331. int isSuccess = FALSE;
  11332. char string[1000]={0}, buffer[1000]={0};
  11333. char strtemp[50]={0};
  11334. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11335. int pos, c = 0;
  11336. char *loc;
  11337. int pos1=0;
  11338. FILE *f = fopen("/var/www/settings1", "r");
  11339. if(f == NULL)
  11340. {
  11341. #ifdef Debug
  11342. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11343. #endif
  11344. return isSuccess;
  11345. }
  11346. fseek(f, 0, SEEK_END);
  11347. long fsize = ftell(f);
  11348. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11349. fread(string, 1, fsize, f);
  11350. fclose(f);
  11351. string[fsize] = 0;
  11352. loc = strstr(string, key);
  11353. if(loc != NULL)
  11354. {
  11355. DEBUG_INFO("key exist!\n");
  11356. pos = loc - string-1;
  11357. f = fopen("/var/www/settings1", "w");
  11358. strncpy(buffer, string, pos);
  11359. fprintf(f, "%s", buffer);
  11360. memset(sstr ,0, sizeof(sstr) );
  11361. c = 0;
  11362. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11363. {
  11364. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11365. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11366. c++;
  11367. }
  11368. sstr[c] = '\0';
  11369. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11370. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11371. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11372. memset(buffer ,0, sizeof(buffer) );
  11373. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11374. //printf("buffer=%s",buffer);
  11375. fprintf(f, "%s", buffer);
  11376. fclose(f);
  11377. }
  11378. else
  11379. {
  11380. printf("key not exist!\n");
  11381. f = fopen("/var/www/settings1", "w+");
  11382. fputs(string, f);
  11383. fseek(f, -1, SEEK_CUR);
  11384. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11385. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11386. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11387. fclose(f);
  11388. }
  11389. isSuccess = TRUE;
  11390. return isSuccess;
  11391. }
  11392. int TransactionMessageAttemptsGet(void)
  11393. {
  11394. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11395. }
  11396. int FirstHeartBeatResponse(void)
  11397. {
  11398. return FirstHeartBeat;
  11399. }
  11400. int TransactionMessageRetryIntervalGet(void)
  11401. {
  11402. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11403. }
  11404. #define SA struct sockaddr
  11405. #define MAXBUF 1024
  11406. //static int m_socket_data;
  11407. //static int sockfd;
  11408. int ReadHttpStatus(int sock){
  11409. //char c;
  11410. char buff[1024]="",*ptr=buff+1;
  11411. int bytes_received, status;
  11412. DEBUG_INFO("Begin Response ..\n");
  11413. while((bytes_received = recv(sock, ptr, 1, 0))){
  11414. if(bytes_received==-1){
  11415. perror("ReadHttpStatus");
  11416. exit(1);
  11417. }
  11418. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11419. ptr++;
  11420. }
  11421. *ptr=0;
  11422. ptr=buff+1;
  11423. sscanf(ptr,"%*s %d ", &status);
  11424. DEBUG_INFO("%s\n",ptr);
  11425. DEBUG_INFO("status=%d\n",status);
  11426. DEBUG_INFO("End Response ..\n");
  11427. return (bytes_received>0)?status:0;
  11428. }
  11429. //the only filed that it parsed is 'Content-Length'
  11430. int ParseHeader(int sock){
  11431. //char c;
  11432. char buff[1024]="",*ptr=buff+4;
  11433. int bytes_received;
  11434. DEBUG_INFO("Begin HEADER ..\n");
  11435. while((bytes_received = recv(sock, ptr, 1, 0))){
  11436. if(bytes_received==-1){
  11437. perror("Parse Header");
  11438. exit(1);
  11439. }
  11440. if(
  11441. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11442. (ptr[-1]=='\r') && (*ptr=='\n' )
  11443. ) break;
  11444. ptr++;
  11445. }
  11446. *ptr=0;
  11447. ptr=buff+4;
  11448. //printf("%s",ptr);
  11449. if(bytes_received){
  11450. ptr=strstr(ptr,"Content-Length:");
  11451. if(ptr){
  11452. sscanf(ptr,"%*s %d",&bytes_received);
  11453. }else
  11454. bytes_received=-1; //unknown size
  11455. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11456. }
  11457. DEBUG_INFO("End HEADER ..\n");
  11458. return bytes_received ;
  11459. }
  11460. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11461. {
  11462. char rmFileCmd[100]={0};
  11463. char FilePath[100]={0};
  11464. char ftpbuf[200];
  11465. int systemresult;
  11466. //DEBUG_INFO("filename=%s\n",filename);
  11467. //DEBUG_INFO("url=%s\n",url);
  11468. sprintf(FilePath,"../mnt/%s",filename);
  11469. if((access(FilePath,F_OK))!=-1)
  11470. {
  11471. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11472. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11473. system(rmFileCmd);
  11474. }
  11475. memset(ftpbuf, 0, sizeof(ftpbuf));
  11476. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11477. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11478. systemresult = system(ftpbuf);
  11479. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11480. if(systemresult != 0)
  11481. {
  11482. DEBUG_INFO("http DownLoad error!\n");
  11483. return FALSE;
  11484. }
  11485. return TRUE;
  11486. }
  11487. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11488. {
  11489. char rmFileCmd[100]={0};
  11490. char FilePath[100]={0};
  11491. char ftpbuf[200];
  11492. int systemresult;
  11493. //char temp[100];
  11494. #if 0
  11495. struct hostent* server;
  11496. char *IPbuffer;
  11497. server = gethostbyname(location);
  11498. // To convert an Internet network
  11499. // address into ASCII string
  11500. IPbuffer = inet_ntoa(*((struct in_addr*)
  11501. server->h_addr_list[0]));
  11502. #endif
  11503. sprintf(FilePath,"../mnt/%s",filename);
  11504. if((access(FilePath,F_OK))!=-1)
  11505. {
  11506. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11507. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11508. system(rmFileCmd);
  11509. }
  11510. memset(ftpbuf, 0, sizeof(ftpbuf));
  11511. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11512. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11513. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11514. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11515. systemresult = system(ftpbuf);
  11516. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11517. if(systemresult != 0)
  11518. {
  11519. printf("wget error!\n");
  11520. return FALSE;
  11521. }
  11522. return TRUE;
  11523. }
  11524. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11525. {
  11526. char rmFileCmd[100]={0};
  11527. char FilePath[100]={0};
  11528. char ftpbuf[200];
  11529. int systemresult;
  11530. DEBUG_INFO("filename=%s\n",filename);
  11531. DEBUG_INFO("url=%s\n",url);
  11532. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11533. if((access(FilePath,F_OK))!=-1)
  11534. {
  11535. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11536. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11537. system(rmFileCmd);
  11538. }
  11539. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11540. if(fp == NULL)
  11541. {
  11542. DEBUG_INFO("log is NULL\n");
  11543. return 0;
  11544. }
  11545. else
  11546. {
  11547. fprintf(fp, "%s\n", url);
  11548. fprintf(fp, "%s\n", filename);
  11549. fclose(fp);
  11550. }
  11551. memset(ftpbuf, 0, sizeof(ftpbuf));
  11552. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11553. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11554. systemresult = system(ftpbuf);
  11555. DEBUG_INFO("systemresult=%d\n",systemresult);
  11556. if(systemresult != 0)
  11557. {
  11558. DEBUG_INFO("http DownLoad error!\n");
  11559. return FALSE;
  11560. }
  11561. return TRUE;
  11562. }
  11563. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11564. {
  11565. struct hostent* server;
  11566. char *IPbuffer;
  11567. char ftpbuf[200];
  11568. int systemresult;
  11569. // To retrieve host information
  11570. server = gethostbyname(location);
  11571. // To convert an Internet network
  11572. // address into ASCII string
  11573. IPbuffer = inet_ntoa(*((struct in_addr*)
  11574. server->h_addr_list[0]));
  11575. memset(ftpbuf, 0, sizeof(ftpbuf));
  11576. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11577. /* format : ftpput -u username -p passwd IP target source*/
  11578. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11579. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11580. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11581. systemresult = system(ftpbuf);
  11582. DEBUG_INFO("systemresult=%d\n",systemresult);
  11583. if(systemresult != 0)
  11584. {
  11585. DEBUG_INFO("ftpput error!\n");
  11586. return FALSE;
  11587. }
  11588. return TRUE;
  11589. }
  11590. int SettingChargingRecord(int target, int transactionId)
  11591. {
  11592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11593. {
  11594. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11595. {
  11596. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11597. {
  11598. addBuff(target, transactionId, 0);
  11599. return TRUE;
  11600. }
  11601. }
  11602. for (int index = 0; index < CCS_QUANTITY; index++)
  11603. {
  11604. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11605. {
  11606. addBuff(target, transactionId, 0);
  11607. return TRUE;
  11608. }
  11609. }
  11610. for (int index = 0; index < GB_QUANTITY; index++)
  11611. {
  11612. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11613. {
  11614. addBuff(target, transactionId, 0);
  11615. return TRUE;
  11616. }
  11617. }
  11618. }
  11619. else
  11620. {
  11621. for (int index = 0; index < AC_QUANTITY; index++)
  11622. {
  11623. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11624. {
  11625. addBuff(target, transactionId, 0);
  11626. return TRUE;
  11627. }
  11628. }
  11629. }
  11630. return FALSE;
  11631. }
  11632. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11633. {
  11634. int isSuccess = FALSE;
  11635. //char *query = NULL;
  11636. sqlite3_stmt *stmt;
  11637. int rc; // return code
  11638. char str[20];
  11639. sprintf(str,"%d",user_id);
  11640. 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 */
  11641. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11642. rc = sqlite3_step(stmt); /* 3 */
  11643. if (rc != SQLITE_DONE) {
  11644. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11645. goto out;
  11646. }
  11647. sqlite3_finalize(stmt);
  11648. // free(query);
  11649. out:
  11650. //----------------------
  11651. // close SQLite database
  11652. //----------------------
  11653. sqlite3_close(db);
  11654. printf("database closed.\n");
  11655. return isSuccess;
  11656. }
  11657. /**
  11658. * Place the contents of the specified file into a memory buffer
  11659. *
  11660. * @param[in] filename The path and name of the file to read
  11661. * @param[out] filebuffer A pointer to the contents in memory
  11662. * @return status 0 success, 1 on failure
  11663. */
  11664. int get_file_contents(const char* filename, char** outbuffer) {
  11665. FILE* file = NULL;
  11666. long filesize;
  11667. const int blocksize = 1;
  11668. size_t readsize;
  11669. char* filebuffer;
  11670. // Open the file
  11671. file = fopen(filename, "r");
  11672. if (NULL == file)
  11673. {
  11674. printf("'%s' not opened\n", filename);
  11675. exit(EXIT_FAILURE);
  11676. }
  11677. // Determine the file size
  11678. fseek(file, 0, SEEK_END);
  11679. filesize = ftell(file);
  11680. rewind (file);
  11681. // Allocate memory for the file contents
  11682. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11683. *outbuffer = filebuffer;
  11684. if (filebuffer == NULL)
  11685. {
  11686. fputs ("malloc out-of-memory", stderr);
  11687. exit(EXIT_FAILURE);
  11688. }
  11689. // Read in the file
  11690. readsize = fread(filebuffer, blocksize, filesize, file);
  11691. if (readsize != filesize)
  11692. {
  11693. fputs ("didn't read file completely",stderr);
  11694. exit(EXIT_FAILURE);
  11695. }
  11696. // Clean exit
  11697. fclose(file);
  11698. return EXIT_SUCCESS;
  11699. }
  11700. static int selectSqlCount = 0;
  11701. static int callback(void *data, int argc, char **argv, char **azColName){
  11702. int i;
  11703. printf("%s: ", (const char*)data);
  11704. selectSqlCount = argc;
  11705. for(i = 0; i<argc; i++){
  11706. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11707. }
  11708. printf("\n");
  11709. return 0;
  11710. }
  11711. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11712. //int i;
  11713. //printf("%s:\n", (const char*)data);
  11714. localversion = argv[5] ? atoi(argv[5]) : 0;
  11715. printf("localversion=%d\n", localversion);
  11716. return 0;
  11717. }
  11718. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11719. //int i;
  11720. //printf("%s:\n", (const char*)data);
  11721. //idTag
  11722. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11723. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11724. //parentIdTag
  11725. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11726. //expir_date
  11727. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11728. //status
  11729. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11730. //version
  11731. idTagQuery.listVersionInt = atoi(argv[5]);
  11732. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11733. return 0;
  11734. }
  11735. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11736. int i;
  11737. //printf("%s:\n", (const char*)data);
  11738. #if 1
  11739. for(i=0; i<argc; i++){
  11740. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11741. }
  11742. //printf("");
  11743. #endif
  11744. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11745. // printf("localversion=%d\n", localversion);
  11746. return 0;
  11747. }
  11748. /** sqlite3_exec的回调。
  11749. *
  11750. * 向控制台打印查询的结果。
  11751. *
  11752. * @param in data 传递给回调函数的数据。
  11753. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11754. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11755. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11756. * @return 状态码。
  11757. */
  11758. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11759. {
  11760. for (int i = 0; i < n_columns; i++)
  11761. {
  11762. DEBUG_INFO("%s/t", col_values[i]);
  11763. }
  11764. DEBUG_INFO("/n");
  11765. return 0;
  11766. }
  11767. void OCPP_getListVerion()
  11768. {
  11769. int rc = 0;
  11770. // const char* data = "Callback function called";
  11771. char sql[100];
  11772. char zErrMsg[100];
  11773. memset(sql, 0, 100);
  11774. memset(zErrMsg, 0, 100);
  11775. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11776. /* Execute SQL statement */
  11777. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11778. DEBUG_INFO("rc=%d\n",rc);
  11779. if( rc != SQLITE_OK ){
  11780. DEBUG_INFO("SQL error: %s", zErrMsg);
  11781. //sqlite3_free(zErrMsg);
  11782. }else{
  11783. DEBUG_INFO("Operation done successfully");
  11784. }
  11785. }
  11786. void OCPP_getIdTag(char *idTag)
  11787. {
  11788. int rc = 0;
  11789. // const char* data = "Callback function called";
  11790. char sql[100];
  11791. char zErrMsg[100];
  11792. memset(sql, 0, 100);
  11793. memset(zErrMsg, 0, 100);
  11794. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11795. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11796. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11797. /* Execute SQL statement */
  11798. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11799. if( rc != SQLITE_OK ){
  11800. DEBUG_INFO("SQL error: %s", zErrMsg);
  11801. //sqlite3_free(zErrMsg);
  11802. }else{
  11803. printf("Operation done successfully");
  11804. }
  11805. //return ver;
  11806. }
  11807. void OCPP_get_TableAuthlocalAllData(void)
  11808. {
  11809. int rc = 0;
  11810. // const char* data = "Callback function called";
  11811. char sql[100];
  11812. char zErrMsg[100];
  11813. memset(sql, 0, 100);
  11814. memset(zErrMsg, 0, 100);
  11815. sprintf(sql,"select * from ocpp_auth_local ");
  11816. /* Execute SQL statement */
  11817. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11818. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11819. if( rc != SQLITE_OK ){
  11820. DEBUG_INFO("SQL error: %s", zErrMsg);
  11821. //sqlite3_free(zErrMsg);
  11822. }else{
  11823. DEBUG_INFO("Operation done successfully");
  11824. }
  11825. //return ver;
  11826. }
  11827. int OCPP_cleanLocalList()
  11828. {
  11829. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11830. char *errMsg = 0;
  11831. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11832. if (SQLITE_OK != rc)
  11833. {
  11834. DEBUG_INFO("%s\n",errMsg);
  11835. return FALSE;
  11836. }
  11837. else
  11838. {
  11839. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11840. }
  11841. return TRUE;
  11842. }
  11843. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11844. {
  11845. int isSuccess = FALSE;
  11846. int ret = 0;
  11847. //const char* data = "Callback function called";
  11848. char sql[200];
  11849. char zErrMsg[100];
  11850. memset(sql, 0, 200);
  11851. memset(zErrMsg, 0, 100);
  11852. 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);
  11853. //* Execute SQL statement */
  11854. //zErrMsg = 0;
  11855. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11856. if( ret != SQLITE_OK ){
  11857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11858. // free(zErrMsg);
  11859. // free(sql);
  11860. return isSuccess;
  11861. }
  11862. DEBUG_INFO("successfully Insert records created\n");
  11863. isSuccess = TRUE;
  11864. return isSuccess;
  11865. }
  11866. void OCPP_deleteIdTag(char *idTag)
  11867. {
  11868. //int ver = 0;
  11869. //int isSuccess = FALSE;
  11870. int rc = 0;
  11871. char sql[100];
  11872. char zErrMsg[100];
  11873. memset(sql, 0, 100);
  11874. memset(zErrMsg, 0, 100);
  11875. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11876. //* Execute SQL statement */
  11877. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11878. if( rc != SQLITE_OK ){
  11879. DEBUG_INFO("SQL error: %s", zErrMsg);
  11880. //sqlite3_free(zErrMsg);
  11881. }else{
  11882. DEBUG_INFO("Operation done successfully");
  11883. }
  11884. }
  11885. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11886. {
  11887. int isSuccess = FALSE;
  11888. int ret = 0;
  11889. const char* data = "Callback function called";
  11890. char sql[200];
  11891. char zErrMsg[100];
  11892. memset(sql, 0, 200);
  11893. memset(zErrMsg, 0, 100);
  11894. //* selectFromTable */
  11895. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11896. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11897. //* Execute SQL statement */
  11898. selectSqlCount = 0;
  11899. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11900. if( ret != SQLITE_OK ){
  11901. printf("Error SQL: %s\n", zErrMsg);
  11902. }
  11903. printf("successfully select operation done\n");
  11904. memset(sql, 0, 200);
  11905. memset(zErrMsg, 0, 100);
  11906. if(selectSqlCount == 0)
  11907. {
  11908. //Insert
  11909. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11910. 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);
  11911. DEBUG_INFO("sql:%s\n", sql);
  11912. //* Execute SQL statement */
  11913. //zErrMsg = 0;
  11914. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11915. if( ret != SQLITE_OK ){
  11916. printf("SQL error: %s\n", zErrMsg);
  11917. return isSuccess;
  11918. }
  11919. DEBUG_INFO("successfully Insert records created\n");
  11920. isSuccess = TRUE;
  11921. }
  11922. else
  11923. {
  11924. //Update
  11925. //* Create merged SQL statement */
  11926. 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);
  11927. /* Execute SQL statement */
  11928. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11929. if( ret != SQLITE_OK ){
  11930. printf("SQL error: %s\n", zErrMsg);
  11931. //sqlite3_free(zErrMsg);
  11932. //sqlite3_free(sql);
  11933. return isSuccess;
  11934. }
  11935. DEBUG_INFO("Successfully operation done \n");
  11936. isSuccess = TRUE;
  11937. }
  11938. return isSuccess;
  11939. }
  11940. int GetOcppServerURL()
  11941. {
  11942. int result = FALSE;
  11943. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11944. memset(OcppHost, 0, sizeof(OcppHost));
  11945. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11946. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11947. {
  11948. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11949. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11950. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11951. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11952. result = TRUE;
  11953. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11954. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11955. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11956. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11957. goto End;
  11958. }
  11959. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11960. {
  11961. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11962. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11963. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11964. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11965. result = TRUE;
  11966. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11967. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11968. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11969. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11970. goto End;
  11971. }
  11972. else
  11973. {
  11974. strcpy(OcppHost,"");
  11975. }
  11976. End:
  11977. return result;
  11978. }
  11979. int GetOcppPath()
  11980. {
  11981. int result = FALSE;
  11982. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  11983. {
  11984. if(OcppTempPath == NULL)
  11985. {
  11986. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11987. }
  11988. else
  11989. {
  11990. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  11991. }
  11992. result = TRUE;
  11993. goto End;
  11994. }
  11995. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  11996. {
  11997. if(OcppTempPath == NULL)
  11998. {
  11999. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12000. }
  12001. else
  12002. {
  12003. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12004. }
  12005. result = TRUE;
  12006. goto End;
  12007. }
  12008. else
  12009. {
  12010. strcpy(OcppPath,"");
  12011. }
  12012. End:
  12013. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12014. return result;
  12015. }
  12016. int GetOcppPort()
  12017. {
  12018. return OcppPort;
  12019. }
  12020. int GetOcppConnStatus(void)
  12021. {
  12022. return ShmOCPP16Data->OcppConnStatus;
  12023. }
  12024. void SetOcppConnStatus(uint8_t status)
  12025. {
  12026. ShmOCPP16Data->OcppConnStatus = status;
  12027. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12028. if(status == FALSE)
  12029. {
  12030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12031. {
  12032. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12033. }
  12034. else
  12035. {
  12036. SystemInitial = AC_QUANTITY;
  12037. }
  12038. }
  12039. }
  12040. int GetHeartBeatWithNOResponse(void)
  12041. {
  12042. return HeartBeatWithNOResponse;
  12043. }
  12044. void SetHeartBeatWithNOResponse(void)
  12045. {
  12046. HeartBeatWithNOResponse = 0;
  12047. }
  12048. int GetTransactionId(int gunindex)
  12049. {
  12050. return TransactionId[gunindex];
  12051. }
  12052. void SetTransactionIdZero(int gunindex)
  12053. {
  12054. TransactionId[gunindex] = 0;
  12055. }
  12056. int InternetDisconnect(void)
  12057. {
  12058. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12059. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12060. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12061. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12062. }
  12063. void GetChargingProfileRequest(int gunindex)
  12064. {
  12065. mtrace();
  12066. //int connectorIdInt, durationInt;
  12067. //char chargingRateUnitStr[4]={0};
  12068. int tempdurationInt = 0;
  12069. int tempchargingProfileId = 0;
  12070. int tempstackLevel = 0;
  12071. int temptransactionId = 0;
  12072. float tempminChargingRateFloat = 0.0;
  12073. char tempchargingProfilePurposeStr[24]={0};
  12074. char tempchargingProfileKindStr[12]={0};
  12075. char temprecurrencyKindStr[8]={0};
  12076. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12077. char tempvalidToStr[28]={0};
  12078. int tempStartPeriodInt = 0;
  12079. float tempLimitInt = 0.0;//0.1;
  12080. int tempNumberPhasesInt=0;
  12081. char fname[200];
  12082. //char comfirmstr[20];
  12083. float MinChargingRate =0.0;
  12084. double diff_t;
  12085. struct tm tp;
  12086. FILE *fptr1;//, *fptr2;
  12087. int c = 0;
  12088. char * pch;
  12089. char *loc;
  12090. char sstr[200]={ 0 };
  12091. int n_chargingProfile = 0;
  12092. int n_SchedulePeriods = 0;
  12093. char SchedulePeriodList[10][200]={0};
  12094. char sLineWord[800]={0};
  12095. char word[1000]={0};
  12096. int confirmPeriods = 0;
  12097. struct StructProfile ChargePointMaxProfile;
  12098. struct StructProfile TxDefaultProfile;
  12099. struct StructProfile TxProfile;
  12100. struct StructProfile TxDefaultProfiletemp[2]={0};
  12101. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12102. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12103. struct StructChargingProfile TxProfile_TEMP={0};
  12104. int TxDefaultProfileFileIsNull=FALSE;
  12105. int ChargePointMaxProfileIsNull=FALSE;
  12106. int TxProfileIsNull=FALSE;
  12107. // int CompositeSceduleIndex = 0;
  12108. char ChargePointMaxProfileScheduleStr[30]={0};
  12109. char TxDefaultProfileScheduleStr[30]={0};
  12110. char TxProfileScheduleStr[30]={0};
  12111. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12112. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12113. memset(&TxProfile,0,sizeof(struct StructProfile));
  12114. DEBUG_INFO("GetChargingProfileRequest\n");
  12115. //*****************************ChargePointMaxProfile******************************************/
  12116. strcpy(fname, ChargePointMaxProfile_JSON);
  12117. ChargePointMaxProfileIsNull=TRUE;
  12118. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12119. {
  12120. fptr1 = fopen(fname, "r");
  12121. int c;
  12122. c = fgetc(fptr1);
  12123. //DEBUG_INFO("c:%d\n",c);
  12124. rewind(fptr1);
  12125. if(c == EOF)
  12126. {
  12127. DEBUG_INFO("\n End of file reached.");
  12128. ChargePointMaxProfileIsNull=TRUE;
  12129. fclose(fptr1);
  12130. }
  12131. else
  12132. {
  12133. ChargePointMaxProfileIsNull=FALSE;
  12134. while(fscanf(fptr1, "%s", word) != EOF)
  12135. {
  12136. if(strcmp(word, "chargingProfileId") == 0)
  12137. {
  12138. n_chargingProfile = n_chargingProfile + 1;
  12139. }
  12140. }
  12141. rewind(fptr1);
  12142. //search Charging Profile Element
  12143. int i = 0;
  12144. int j = 0;
  12145. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12146. //***********chargingProfileId**************/
  12147. c = 0;
  12148. loc = strstr(sLineWord, "chargingProfileId");
  12149. //DEBUG_INFO("loc=%s\n",loc);
  12150. memset(sstr ,0, sizeof(sstr) );
  12151. if(loc != NULL)
  12152. {
  12153. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12154. {
  12155. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12156. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12157. c++;
  12158. }
  12159. sstr[c] = '\0';
  12160. tempchargingProfileId = atoi(sstr);
  12161. }
  12162. else
  12163. {
  12164. tempchargingProfileId = 0;
  12165. }
  12166. //***********stackLevel**************/
  12167. c = 0;
  12168. loc = strstr(sLineWord, "stackLevel");
  12169. //DEBUG_INFO("loc=%s\n",loc);
  12170. memset(sstr ,0, sizeof(sstr) );
  12171. if(loc != NULL)
  12172. {
  12173. while (loc[2+strlen("stackLevel")+c] != '\"')
  12174. {
  12175. sstr[c] = loc[2+strlen("stackLevel")+c];
  12176. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12177. c++;
  12178. }
  12179. sstr[c] = '\0';
  12180. tempstackLevel = atoi(sstr);
  12181. }
  12182. else
  12183. {
  12184. tempstackLevel = 0;
  12185. }
  12186. //***********chargingProfilePurpose **************/
  12187. c = 0;
  12188. loc = strstr(sLineWord, "chargingProfilePurpose");
  12189. //DEBUG_INFO("loc=%s\n",loc);
  12190. memset(sstr ,0, sizeof(sstr) );
  12191. if(loc != NULL)
  12192. {
  12193. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12194. {
  12195. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12196. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12197. c++;
  12198. }
  12199. sstr[c] = '\0';
  12200. strcpy(tempchargingProfilePurposeStr,sstr);
  12201. }
  12202. else
  12203. {
  12204. strcpy(tempchargingProfilePurposeStr,"");
  12205. }
  12206. //***********chargingProfileKind **************/
  12207. c = 0;
  12208. loc = strstr(sLineWord, "chargingProfileKind");
  12209. //DEBUG_INFO("loc=%s\n",loc);
  12210. memset(sstr ,0, sizeof(sstr) );
  12211. if(loc != NULL)
  12212. {
  12213. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12214. {
  12215. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12216. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12217. c++;
  12218. }
  12219. sstr[c] = '\0';
  12220. strcpy(tempchargingProfileKindStr,sstr);
  12221. }
  12222. else
  12223. {
  12224. strcpy(tempchargingProfileKindStr,"");
  12225. }
  12226. //***********recurrencyKind **************/
  12227. c = 0;
  12228. loc = strstr(sLineWord, "recurrencyKind");
  12229. //DEBUG_INFO("loc=%s\n",loc);
  12230. memset(sstr ,0, sizeof(sstr) );
  12231. if(loc != NULL)
  12232. {
  12233. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12234. {
  12235. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12236. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12237. c++;
  12238. }
  12239. sstr[c] = '\0';
  12240. strcpy(temprecurrencyKindStr,sstr);
  12241. }
  12242. else
  12243. {
  12244. strcpy(temprecurrencyKindStr,"");
  12245. }
  12246. //***********validFrom**************/
  12247. c = 0;
  12248. loc = strstr(sLineWord, "validFrom");
  12249. //DEBUG_INFO("loc=%s\n",loc);
  12250. memset(sstr ,0, sizeof(sstr) );
  12251. if(loc != NULL)
  12252. {
  12253. while (loc[3+strlen("validFrom")+c] != '\"')
  12254. {
  12255. sstr[c] = loc[3+strlen("validFrom")+c];
  12256. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12257. c++;
  12258. }
  12259. sstr[c] = '\0';
  12260. strcpy(tempvalidFromStr,sstr);
  12261. }
  12262. else
  12263. {
  12264. strcpy(tempvalidFromStr,"");
  12265. }
  12266. //***********validTo **************/
  12267. c = 0;
  12268. loc = strstr(sLineWord, "validTo");
  12269. //DEBUG_INFO("loc=%s\n",loc);
  12270. memset(sstr ,0, sizeof(sstr) );
  12271. if(loc != NULL)
  12272. {
  12273. while (loc[3+strlen("validTo")+c] != '\"')
  12274. {
  12275. sstr[c] = loc[3+strlen("validTo")+c];
  12276. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12277. c++;
  12278. }
  12279. sstr[c] = '\0';
  12280. strcpy(tempvalidToStr,sstr);
  12281. }
  12282. else
  12283. {
  12284. strcpy(tempvalidToStr,"");
  12285. }
  12286. //***********validFrom**************/
  12287. c = 0;
  12288. loc = strstr(sLineWord, "validFrom");
  12289. if(loc != NULL)
  12290. {
  12291. memset(sstr ,0, sizeof(sstr) );
  12292. while (loc[3+strlen("validFrom")+c] != '\"')
  12293. {
  12294. sstr[c] = loc[3+strlen("validFrom")+c];
  12295. c++;
  12296. }
  12297. sstr[c] = '\0';
  12298. strcpy(tempvalidFromStr,sstr);
  12299. }
  12300. else
  12301. {
  12302. strcpy(tempvalidFromStr,"");
  12303. }
  12304. //***********duration**************/
  12305. c = 0;
  12306. loc = strstr(sLineWord, "duration");
  12307. if(loc != NULL)
  12308. {
  12309. memset(sstr ,0, sizeof(sstr) );
  12310. while (loc[2+strlen("duration")+c] != ',')
  12311. {
  12312. sstr[c] = loc[2+strlen("duration")+c];
  12313. c++;
  12314. }
  12315. sstr[c] = '\0';
  12316. tempdurationInt = atoi(sstr);
  12317. }
  12318. else
  12319. {
  12320. tempdurationInt = 0;
  12321. }
  12322. //**********startSchedule**********/
  12323. c = 0;
  12324. loc = strstr(sLineWord, "startSchedule");
  12325. memset(sstr ,0, sizeof(sstr) );
  12326. while (loc[3+strlen("startSchedule")+c] != '\"')
  12327. {
  12328. sstr[c] = loc[3+strlen("startSchedule")+c];
  12329. c++;
  12330. }
  12331. sstr[c] = '\0';
  12332. strcpy(tempstartScheduleStr, sstr);
  12333. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12334. //**********chargingRateUnit**********/
  12335. c = 0;
  12336. loc = strstr(sLineWord, "chargingRateUnit");
  12337. memset(sstr ,0, sizeof(sstr) );
  12338. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12339. {
  12340. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12341. c++;
  12342. }
  12343. sstr[c] = '\0';
  12344. strcpy(tempchargingRateUnitStr, sstr);
  12345. //**********minChargingRate*******/
  12346. c = 0;
  12347. loc = strstr(sLineWord, "minChargingRate");
  12348. if(loc != NULL)
  12349. {
  12350. memset(sstr ,0, sizeof(sstr) );
  12351. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12352. {
  12353. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12354. c++;
  12355. }
  12356. sstr[c] = '\0';
  12357. tempminChargingRateFloat = atof(sstr);
  12358. }
  12359. else
  12360. {
  12361. tempminChargingRateFloat = 0.0;
  12362. }
  12363. //
  12364. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12365. tp.tm_isdst = -1;
  12366. time_t utc = mktime(&tp);
  12367. time_t t = time(NULL);
  12368. diff_t = difftime(t, utc);
  12369. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12370. //parsing strings to words
  12371. i = 0;
  12372. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12373. loc = loc+3+strlen("chargingSchedulePeriod");
  12374. pch = strtok(loc ,"{");
  12375. while (pch != NULL)
  12376. {
  12377. strcpy(SchedulePeriodList[i], pch);
  12378. pch = strtok (NULL, "{");
  12379. i = i + 1;
  12380. }
  12381. n_SchedulePeriods = i;
  12382. for(int i=0;i<n_SchedulePeriods;i++)
  12383. {
  12384. //*************startPeriod****************/
  12385. c = 0;
  12386. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12387. memset(sstr ,0, sizeof(sstr) );
  12388. while (loc[strlen("startPeriod")+2+c] != ',')
  12389. {
  12390. sstr[c] = loc[strlen("startPeriod")+2+c];
  12391. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12392. c++;
  12393. }
  12394. sstr[c] = '\0';
  12395. tempStartPeriodInt = atoi(sstr);
  12396. //*************limit****************/
  12397. c = 0;
  12398. loc = strstr(SchedulePeriodList[i], "limit");
  12399. memset(sstr ,0, sizeof(sstr) );
  12400. while (loc[strlen("limit")+2+c] != ',')
  12401. {
  12402. sstr[c] = loc[strlen("limit")+2+c];
  12403. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12404. c++;
  12405. }
  12406. sstr[c] = '\0';
  12407. tempLimitInt = atof(sstr);
  12408. //*************numberPhases****************/
  12409. c = 0;
  12410. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12411. memset(sstr ,0, sizeof(sstr) );
  12412. while (loc[strlen("numberPhases")+2+c] != '}')
  12413. {
  12414. sstr[c] = loc[strlen("numberPhases")+2+c];
  12415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12416. c++;
  12417. }
  12418. sstr[c] = '\0';
  12419. tempNumberPhasesInt = atoi(sstr);
  12420. if(j == 0)
  12421. {
  12422. ChargePointMaxProfile.Duration = tempdurationInt;
  12423. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12424. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12425. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12426. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12427. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12428. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12429. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12430. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12431. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12432. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12433. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12434. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12435. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12436. }
  12437. }
  12438. if(MinChargingRate < tempminChargingRateFloat)
  12439. {
  12440. MinChargingRate = tempminChargingRateFloat;
  12441. }
  12442. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12443. if(confirmPeriods < n_SchedulePeriods)
  12444. {
  12445. confirmPeriods = n_SchedulePeriods;
  12446. }
  12447. j = j + 1;
  12448. }
  12449. fclose(fptr1);
  12450. }
  12451. }// the end of access file ChargePointMaxProfile
  12452. //****************************TxDefaultProfile************************************************/
  12453. switch(gunindex + 1)
  12454. {
  12455. case 0:
  12456. break;
  12457. case 1:
  12458. strcpy(fname, TxDefaultProfile_1_JSON );
  12459. break;
  12460. case 2:
  12461. strcpy(fname, TxDefaultProfile_2_JSON );
  12462. break;
  12463. default:
  12464. strcpy(fname, TxDefaultProfile_1_JSON );
  12465. break;
  12466. }
  12467. TxDefaultProfileFileIsNull=TRUE;
  12468. if((access(fname,F_OK))!=-1)
  12469. {
  12470. fptr1 = fopen(fname, "r");
  12471. c = 0;
  12472. c = fgetc(fptr1);
  12473. //DEBUG_INFO("c:%d\n",c);
  12474. rewind(fptr1);
  12475. if(c == EOF)
  12476. {
  12477. DEBUG_INFO("\n End of file reached.");
  12478. TxDefaultProfileFileIsNull=TRUE;
  12479. fclose(fptr1);
  12480. }
  12481. else
  12482. {
  12483. TxDefaultProfileFileIsNull=FALSE;
  12484. while(fscanf(fptr1, "%s", word) != EOF)
  12485. {
  12486. if(strcmp(word, "chargingProfileId") == 0)
  12487. {
  12488. n_chargingProfile = n_chargingProfile + 1;
  12489. }
  12490. }
  12491. rewind(fptr1);
  12492. //search Charging Profile Element
  12493. int i = 0;
  12494. int j = 0;
  12495. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12496. #if 0
  12497. /***********connectorId****************/
  12498. c = 0;
  12499. loc = strstr(sLineWord, "connectorId");
  12500. memset(sstr ,0, sizeof(sstr) );
  12501. while (loc[strlen("connectorId")+2+c] != ',')
  12502. {
  12503. sstr[c] = loc[strlen("connectorId")+2+c];
  12504. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12505. c++;
  12506. }
  12507. sstr[c] = '\0';
  12508. tempconnectorIdInt = atoi(sstr);
  12509. #endif
  12510. //***********chargingProfileId**************/
  12511. c = 0;
  12512. loc = strstr(sLineWord, "chargingProfileId");
  12513. //DEBUG_INFO("loc=%s\n",loc);
  12514. memset(sstr ,0, sizeof(sstr) );
  12515. if(loc != NULL)
  12516. {
  12517. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12518. {
  12519. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12521. c++;
  12522. }
  12523. sstr[c] = '\0';
  12524. tempchargingProfileId = atoi(sstr);
  12525. }
  12526. else
  12527. {
  12528. tempchargingProfileId = 0;
  12529. }
  12530. //***********stackLevel**************/
  12531. c = 0;
  12532. loc = strstr(sLineWord, "stackLevel");
  12533. //DEBUG_INFO("loc=%s\n",loc);
  12534. memset(sstr ,0, sizeof(sstr) );
  12535. if(loc != NULL)
  12536. {
  12537. while (loc[2+strlen("stackLevel")+c] != '\"')
  12538. {
  12539. sstr[c] = loc[2+strlen("stackLevel")+c];
  12540. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12541. c++;
  12542. }
  12543. sstr[c] = '\0';
  12544. tempstackLevel = atoi(sstr);
  12545. }
  12546. else
  12547. {
  12548. tempstackLevel = 0;
  12549. }
  12550. //***********chargingProfilePurpose **************/
  12551. c = 0;
  12552. loc = strstr(sLineWord, "chargingProfilePurpose");
  12553. //DEBUG_INFO("loc=%s\n",loc);
  12554. memset(sstr ,0, sizeof(sstr) );
  12555. if(loc != NULL)
  12556. {
  12557. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12558. {
  12559. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12560. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12561. c++;
  12562. }
  12563. sstr[c] = '\0';
  12564. strcpy(tempchargingProfilePurposeStr,sstr);
  12565. }
  12566. else
  12567. {
  12568. strcpy(tempchargingProfilePurposeStr,"");
  12569. }
  12570. //***********chargingProfileKind **************/
  12571. c = 0;
  12572. loc = strstr(sLineWord, "chargingProfileKind");
  12573. //DEBUG_INFO("loc=%s\n",loc);
  12574. memset(sstr ,0, sizeof(sstr) );
  12575. if(loc != NULL)
  12576. {
  12577. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12578. {
  12579. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12580. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12581. c++;
  12582. }
  12583. sstr[c] = '\0';
  12584. strcpy(tempchargingProfileKindStr,sstr);
  12585. }
  12586. else
  12587. {
  12588. strcpy(tempchargingProfileKindStr,"");
  12589. }
  12590. //***********recurrencyKind **************/
  12591. c = 0;
  12592. loc = strstr(sLineWord, "recurrencyKind");
  12593. //DEBUG_INFO("loc=%s\n",loc);
  12594. memset(sstr ,0, sizeof(sstr) );
  12595. if(loc != NULL)
  12596. {
  12597. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12598. {
  12599. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12601. c++;
  12602. }
  12603. sstr[c] = '\0';
  12604. strcpy(temprecurrencyKindStr,sstr);
  12605. }
  12606. else
  12607. {
  12608. strcpy(temprecurrencyKindStr,"");
  12609. }
  12610. //***********validFrom**************/
  12611. c = 0;
  12612. loc = strstr(sLineWord, "validFrom");
  12613. if(loc != NULL)
  12614. {
  12615. memset(sstr ,0, sizeof(sstr) );
  12616. while (loc[3+strlen("validFrom")+c] != '\"')
  12617. {
  12618. sstr[c] = loc[3+strlen("validFrom")+c];
  12619. c++;
  12620. }
  12621. sstr[c] = '\0';
  12622. strcpy(tempvalidFromStr,sstr);
  12623. }
  12624. else
  12625. {
  12626. strcpy(tempvalidFromStr,"");
  12627. }
  12628. //***********validFrom**************/
  12629. c = 0;
  12630. loc = strstr(sLineWord, "duration");
  12631. if(loc != NULL)
  12632. {
  12633. memset(sstr ,0, sizeof(sstr) );
  12634. while (loc[2+strlen("duration")+c] != ',')
  12635. {
  12636. sstr[c] = loc[2+strlen("duration")+c];
  12637. c++;
  12638. }
  12639. sstr[c] = '\0';
  12640. tempdurationInt = atoi(sstr);
  12641. }
  12642. else
  12643. {
  12644. tempdurationInt = 0;
  12645. }
  12646. //**********startSchedule**********/
  12647. c = 0;
  12648. loc = strstr(sLineWord, "startSchedule");
  12649. memset(sstr ,0, sizeof(sstr) );
  12650. while (loc[3+strlen("startSchedule")+c] != '\"')
  12651. {
  12652. sstr[c] = loc[3+strlen("startSchedule")+c];
  12653. c++;
  12654. }
  12655. sstr[c] = '\0';
  12656. strcpy(tempstartScheduleStr, sstr);
  12657. strcpy(TxDefaultProfileScheduleStr, sstr);
  12658. //**********chargingRateUnit**********/
  12659. c = 0;
  12660. loc = strstr(sLineWord, "chargingRateUnit");
  12661. memset(sstr ,0, sizeof(sstr) );
  12662. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12663. {
  12664. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12665. c++;
  12666. }
  12667. sstr[c] = '\0';
  12668. strcpy(tempchargingRateUnitStr, sstr);
  12669. //**********minChargingRate*******/
  12670. c = 0;
  12671. loc = strstr(sLineWord, "minChargingRate");
  12672. if(loc != NULL)
  12673. {
  12674. memset(sstr ,0, sizeof(sstr) );
  12675. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12676. {
  12677. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12678. c++;
  12679. }
  12680. sstr[c] = '\0';
  12681. tempminChargingRateFloat = atof(sstr);
  12682. }
  12683. else
  12684. {
  12685. tempminChargingRateFloat = 0.0;
  12686. }
  12687. //
  12688. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12689. tp.tm_isdst = -1;
  12690. time_t utc = mktime(&tp);
  12691. time_t t = time(NULL);
  12692. diff_t = difftime(t, utc);
  12693. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12694. //parsing strings to words
  12695. i = 0;
  12696. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12697. loc = loc+3+strlen("chargingSchedulePeriod");
  12698. pch = strtok(loc ,"{");
  12699. while (pch != NULL)
  12700. {
  12701. strcpy(SchedulePeriodList[i], pch);
  12702. pch = strtok (NULL, "{");
  12703. i = i + 1;
  12704. }
  12705. n_SchedulePeriods = i;
  12706. for(int i=0;i<n_SchedulePeriods;i++)
  12707. {
  12708. //*************startPeriod****************/
  12709. c = 0;
  12710. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12711. memset(sstr ,0, sizeof(sstr) );
  12712. while (loc[strlen("startPeriod")+2+c] != ',')
  12713. {
  12714. sstr[c] = loc[strlen("startPeriod")+2+c];
  12715. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12716. c++;
  12717. }
  12718. sstr[c] = '\0';
  12719. tempStartPeriodInt = atoi(sstr);
  12720. //*************limit****************/
  12721. c = 0;
  12722. loc = strstr(SchedulePeriodList[i], "limit");
  12723. memset(sstr ,0, sizeof(sstr) );
  12724. while (loc[strlen("limit")+2+c] != ',')
  12725. {
  12726. sstr[c] = loc[strlen("limit")+2+c];
  12727. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12728. c++;
  12729. }
  12730. sstr[c] = '\0';
  12731. tempLimitInt = atof(sstr);
  12732. //*************numberPhases****************/
  12733. c = 0;
  12734. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12735. memset(sstr ,0, sizeof(sstr) );
  12736. while (loc[strlen("numberPhases")+2+c] != '}')
  12737. {
  12738. sstr[c] = loc[strlen("numberPhases")+2+c];
  12739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12740. c++;
  12741. }
  12742. sstr[c] = '\0';
  12743. tempNumberPhasesInt = atoi(sstr);
  12744. if(j == 0)
  12745. {
  12746. TxDefaultProfile.Duration = tempdurationInt;
  12747. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12748. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12749. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12750. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12751. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12752. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12753. TxDefaultProfile_TEMP.TransactionId = 0;
  12754. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12755. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12756. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12757. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12758. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12759. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12760. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12761. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12762. }
  12763. else
  12764. {
  12765. //other stack level charging Profile
  12766. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12767. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12768. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12769. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12770. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12771. }
  12772. }
  12773. if(MinChargingRate < tempminChargingRateFloat)
  12774. {
  12775. MinChargingRate = tempminChargingRateFloat;
  12776. }
  12777. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12778. if(confirmPeriods < n_SchedulePeriods)
  12779. confirmPeriods = n_SchedulePeriods;
  12780. j = j + 1;
  12781. }
  12782. fclose(fptr1);
  12783. //Stacking Charging Profiles
  12784. for(int l=0; l <(j-1) ;l++)
  12785. {
  12786. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12787. {
  12788. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12789. {
  12790. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12791. {
  12792. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12793. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12794. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12795. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12796. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12797. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12798. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12799. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12800. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12801. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12802. }
  12803. else
  12804. {
  12805. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12806. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12807. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12808. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12809. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12810. }
  12811. }
  12812. }
  12813. }
  12814. //end of Stacking Charging Profiles
  12815. }
  12816. }// the end of ACCESS TxDefaultProfile
  12817. //****************************TxProfile************************************************/
  12818. switch(gunindex + 1)
  12819. {
  12820. case 0:
  12821. break;
  12822. case 1:
  12823. strcpy(fname, TxProfile_1_JSON );
  12824. break;
  12825. case 2:
  12826. strcpy(fname, TxProfile_2_JSON );
  12827. break;
  12828. default:
  12829. strcpy(fname, TxProfile_1_JSON );
  12830. break;
  12831. }
  12832. TxProfileIsNull=TRUE;
  12833. if((access(fname,F_OK))!=-1)
  12834. {
  12835. fptr1 = fopen(fname, "r");
  12836. c = 0;
  12837. c = fgetc(fptr1);
  12838. //DEBUG_INFO("c:%d\n",c);
  12839. rewind(fptr1);
  12840. if(c == EOF)
  12841. {
  12842. DEBUG_INFO("\n End of file reached.");
  12843. TxProfileIsNull=TRUE;
  12844. fclose(fptr1);
  12845. }
  12846. else
  12847. {
  12848. TxProfileIsNull=FALSE;
  12849. while(fscanf(fptr1, "%s", word) != EOF)
  12850. {
  12851. if(strcmp(word, "chargingProfileId") == 0)
  12852. {
  12853. n_chargingProfile = n_chargingProfile + 1;
  12854. }
  12855. }
  12856. rewind(fptr1);
  12857. //search Charging Profile Element
  12858. int i= 0;
  12859. int j= 0;
  12860. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12861. #if 0
  12862. /***********connectorId****************/
  12863. c = 0;
  12864. loc = strstr(sLineWord, "connectorId");
  12865. memset(sstr ,0, sizeof(sstr) );
  12866. while (loc[strlen("connectorId")+2+c] != ',')
  12867. {
  12868. sstr[c] = loc[strlen("connectorId")+2+c];
  12869. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12870. c++;
  12871. }
  12872. sstr[c] = '\0';
  12873. tempconnectorIdInt = atoi(sstr);
  12874. #endif
  12875. //***********chargingProfileId**************/
  12876. c = 0;
  12877. loc = strstr(sLineWord, "chargingProfileId");
  12878. memset(sstr ,0, sizeof(sstr) );
  12879. if(loc != NULL)
  12880. {
  12881. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12882. {
  12883. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12885. c++;
  12886. }
  12887. sstr[c] = '\0';
  12888. tempchargingProfileId = atoi(sstr);
  12889. }
  12890. else
  12891. {
  12892. tempchargingProfileId = 0;
  12893. }
  12894. //***********transactionId **************/
  12895. c = 0;
  12896. loc = strstr(sLineWord, "transactionId");
  12897. //DEBUG_INFO("loc=%s\n",loc);
  12898. memset(sstr ,0, sizeof(sstr) );
  12899. if(loc != NULL)
  12900. {
  12901. while (loc[2+strlen("transactionId")+c] != '\"')
  12902. {
  12903. sstr[c] = loc[2+strlen("transactionId")+c];
  12904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12905. c++;
  12906. }
  12907. sstr[c] = '\0';
  12908. temptransactionId = atoi(sstr);
  12909. }
  12910. else
  12911. {
  12912. temptransactionId = 0;
  12913. }
  12914. //***********stackLevel**************/
  12915. c = 0;
  12916. loc = strstr(sLineWord, "stackLevel");
  12917. //DEBUG_INFO("loc=%s\n",loc);
  12918. memset(sstr ,0, sizeof(sstr) );
  12919. if(loc != NULL)
  12920. {
  12921. while (loc[2+strlen("stackLevel")+c] != '\"')
  12922. {
  12923. sstr[c] = loc[2+strlen("stackLevel")+c];
  12924. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12925. c++;
  12926. }
  12927. sstr[c] = '\0';
  12928. tempstackLevel = atoi(sstr);
  12929. }
  12930. else
  12931. {
  12932. tempstackLevel = 0;
  12933. }
  12934. //***********chargingProfilePurpose **************/
  12935. c = 0;
  12936. loc = strstr(sLineWord, "chargingProfilePurpose");
  12937. //DEBUG_INFO("loc=%s\n",loc);
  12938. memset(sstr ,0, sizeof(sstr) );
  12939. if(loc != NULL)
  12940. {
  12941. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12942. {
  12943. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12944. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12945. c++;
  12946. }
  12947. sstr[c] = '\0';
  12948. strcpy(tempchargingProfilePurposeStr,sstr);
  12949. }
  12950. else
  12951. {
  12952. strcpy(tempchargingProfilePurposeStr,"");
  12953. }
  12954. //***********chargingProfileKind **************/
  12955. c = 0;
  12956. loc = strstr(sLineWord, "chargingProfileKind");
  12957. //DEBUG_INFO("loc=%s\n",loc);
  12958. memset(sstr ,0, sizeof(sstr) );
  12959. if(loc != NULL)
  12960. {
  12961. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12962. {
  12963. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12964. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12965. c++;
  12966. }
  12967. sstr[c] = '\0';
  12968. strcpy(tempchargingProfileKindStr,sstr);
  12969. }
  12970. else
  12971. {
  12972. strcpy(tempchargingProfileKindStr,"");
  12973. }
  12974. //***********recurrencyKind **************/
  12975. c = 0;
  12976. loc = strstr(sLineWord, "recurrencyKind");
  12977. //DEBUG_INFO("loc=%s\n",loc);
  12978. memset(sstr ,0, sizeof(sstr) );
  12979. if(loc != NULL)
  12980. {
  12981. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12982. {
  12983. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12985. c++;
  12986. }
  12987. sstr[c] = '\0';
  12988. strcpy(temprecurrencyKindStr,sstr);
  12989. }
  12990. else
  12991. {
  12992. strcpy(temprecurrencyKindStr,"");
  12993. }
  12994. //***********validFrom**************/
  12995. c = 0;
  12996. loc = strstr(sLineWord, "validFrom");
  12997. if(loc != NULL)
  12998. {
  12999. memset(sstr ,0, sizeof(sstr) );
  13000. while (loc[3+strlen("validFrom")+c] != '\"')
  13001. {
  13002. sstr[c] = loc[3+strlen("validFrom")+c];
  13003. c++;
  13004. }
  13005. sstr[c] = '\0';
  13006. strcpy(tempvalidFromStr,sstr);
  13007. }
  13008. else
  13009. {
  13010. strcpy(tempvalidFromStr,"");
  13011. }
  13012. //***********duration**************/
  13013. c = 0;
  13014. loc = strstr(sLineWord, "duration");
  13015. //DEBUG_INFO("loc=%s\n",loc);
  13016. memset(sstr ,0, sizeof(sstr) );
  13017. if(loc != NULL)
  13018. {
  13019. while (loc[2+strlen("duration")+c] != '\"')
  13020. {
  13021. sstr[c] = loc[2+strlen("duration")+c];
  13022. c++;
  13023. }
  13024. sstr[c] = '\0';
  13025. tempdurationInt = atoi(sstr);
  13026. }
  13027. else
  13028. {
  13029. tempdurationInt = 0;
  13030. }
  13031. //**********startSchedule**********/
  13032. c = 0;
  13033. loc = strstr(sLineWord, "startSchedule");
  13034. memset(sstr ,0, sizeof(sstr) );
  13035. while (loc[3+strlen("startSchedule")+c] != '\"')
  13036. {
  13037. sstr[c] = loc[3+strlen("startSchedule")+c];
  13038. c++;
  13039. }
  13040. sstr[c] = '\0';
  13041. strcpy(tempstartScheduleStr, sstr);
  13042. strcpy(TxProfileScheduleStr, sstr);
  13043. //**********chargingRateUnit**********/
  13044. c = 0;
  13045. loc = strstr(sLineWord, "chargingRateUnit");
  13046. memset(sstr ,0, sizeof(sstr) );
  13047. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13048. {
  13049. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13050. c++;
  13051. }
  13052. sstr[c] = '\0';
  13053. strcpy(tempchargingRateUnitStr, sstr);
  13054. //**********minChargingRate*******/
  13055. c = 0;
  13056. loc = strstr(sLineWord, "minChargingRate");
  13057. if(loc != NULL)
  13058. {
  13059. memset(sstr ,0, sizeof(sstr) );
  13060. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13061. {
  13062. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13063. c++;
  13064. }
  13065. sstr[c] = '\0';
  13066. tempminChargingRateFloat = atof(sstr);
  13067. }
  13068. else
  13069. {
  13070. tempminChargingRateFloat = 0.0;
  13071. }
  13072. //
  13073. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13074. tp.tm_isdst = -1;
  13075. time_t utc = mktime(&tp);
  13076. time_t t = time(NULL);
  13077. diff_t = difftime(t, utc);
  13078. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13079. //parsing strings to words
  13080. i = 0;
  13081. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13082. loc = loc+3+strlen("chargingSchedulePeriod");
  13083. pch = strtok(loc ,"{");
  13084. while (pch != NULL)
  13085. {
  13086. strcpy(SchedulePeriodList[i], pch);
  13087. pch = strtok (NULL, "{");
  13088. i = i + 1;
  13089. }
  13090. n_SchedulePeriods = i;
  13091. for(int i=0;i<n_SchedulePeriods;i++)
  13092. {
  13093. //*************startPeriod****************/
  13094. c = 0;
  13095. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13096. memset(sstr ,0, sizeof(sstr) );
  13097. while (loc[strlen("startPeriod")+2+c] != ',')
  13098. {
  13099. sstr[c] = loc[strlen("startPeriod")+2+c];
  13100. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13101. c++;
  13102. }
  13103. sstr[c] = '\0';
  13104. tempStartPeriodInt = atoi(sstr);
  13105. //*************limit****************/
  13106. c = 0;
  13107. loc = strstr(SchedulePeriodList[i], "limit");
  13108. memset(sstr ,0, sizeof(sstr) );
  13109. while (loc[strlen("limit")+2+c] != ',')
  13110. {
  13111. sstr[c] = loc[strlen("limit")+2+c];
  13112. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13113. c++;
  13114. }
  13115. sstr[c] = '\0';
  13116. tempLimitInt = atof(sstr);
  13117. //*************numberPhases****************/
  13118. c = 0;
  13119. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13120. memset(sstr ,0, sizeof(sstr) );
  13121. while (loc[strlen("numberPhases")+2+c] != '}')
  13122. {
  13123. sstr[c] = loc[strlen("numberPhases")+2+c];
  13124. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13125. c++;
  13126. }
  13127. sstr[c] = '\0';
  13128. tempNumberPhasesInt = atoi(sstr);
  13129. //TxProfile.Duration = durationInt;
  13130. TxProfile.TotalPeriod = n_SchedulePeriods;
  13131. TxProfile.Period[i].Limit = tempLimitInt;
  13132. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13133. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13134. }
  13135. if(MinChargingRate < tempminChargingRateFloat)
  13136. {
  13137. MinChargingRate = tempminChargingRateFloat;
  13138. }
  13139. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13140. if(confirmPeriods < n_SchedulePeriods)
  13141. confirmPeriods = n_SchedulePeriods;
  13142. if(j == 0)
  13143. {
  13144. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13145. TxProfile_TEMP.StackLevel = tempstackLevel;
  13146. TxProfile_TEMP.TransactionId = 0;
  13147. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13148. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13149. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13150. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13151. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13152. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13153. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13154. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13155. }
  13156. }
  13157. fclose(fptr1);
  13158. }
  13159. }// the end of ACCESS TxProfile
  13160. //CompositeSchedule
  13161. int period=0;
  13162. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13163. {
  13164. //TxProfile
  13165. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13166. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13167. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13168. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13170. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13171. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13172. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13173. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13174. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13175. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13176. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13177. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13178. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13179. {
  13180. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13181. {
  13182. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13183. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13184. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13185. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13186. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13187. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13188. period = period + 1;
  13189. }
  13190. else
  13191. {
  13192. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13193. {
  13194. }
  13195. else
  13196. {
  13197. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13198. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13199. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13200. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13201. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13202. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13203. period = period + 1;
  13204. }
  13205. }
  13206. }
  13207. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13208. {
  13209. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13210. {
  13211. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13212. {
  13213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13214. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13215. }
  13216. else
  13217. {
  13218. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13219. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13220. }
  13221. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13222. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13223. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13224. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13225. period = period + 1;
  13226. }
  13227. }
  13228. }
  13229. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13230. {
  13231. //TxDefaultProfile
  13232. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13233. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13234. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13235. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13238. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13239. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13240. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13241. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13242. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13243. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13244. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13245. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13246. {
  13247. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13248. {
  13249. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13252. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13253. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13254. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13255. period = period + 1;
  13256. }
  13257. else
  13258. {
  13259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13261. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13262. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13263. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13264. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13265. period = period + 1;
  13266. }
  13267. }
  13268. }
  13269. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13270. {
  13271. //TxDefaultProfile
  13272. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13274. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13275. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13276. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13277. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13278. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13279. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13283. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13284. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13285. {
  13286. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13287. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13288. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13289. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13290. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13291. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13292. period = period + 1;
  13293. }
  13294. }
  13295. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13296. {
  13297. //ChargePointMaxProfile
  13298. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13299. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13300. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13301. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13302. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13303. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13304. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13305. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13306. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13307. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13308. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13309. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13310. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13311. {
  13312. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13313. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13314. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13315. period = period + 1;
  13316. }
  13317. }
  13318. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13319. {
  13320. //TxProfile
  13321. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13323. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13324. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13325. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13326. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13327. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13328. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13329. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13330. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13331. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13332. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13333. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13334. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13335. {
  13336. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13337. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13338. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13339. }
  13340. }
  13341. confirmPeriods = period;
  13342. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13343. 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,"
  13344. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13345. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13346. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13347. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13348. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13349. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13350. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13351. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13352. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13353. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13354. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13355. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13357. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13358. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13359. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13360. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13361. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13362. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13363. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13364. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13366. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13367. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13368. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13370. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13371. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13372. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13396. }
  13397. void LWS_Send(char * str)
  13398. {
  13399. //=====================================================
  13400. // Check InternetConn 0: disconnected, 1: connected
  13401. //====================================================
  13402. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13403. {
  13404. DEBUG_INFO("\n offline now !!!\n");
  13405. return;
  13406. }
  13407. pthread_mutex_lock(&lock);
  13408. memset(SendBuffer,0,SendBufLen);
  13409. sprintf((char *)SendBuffer, "%s", str);
  13410. pthread_mutex_unlock(&lock);
  13411. lws_callback_on_writable(wsi_client);
  13412. lws_service(context, 10000);//timeout_ms
  13413. }