MessageHandler.c 576 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844
  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 "define.h"
  24. #include "SystemLogMessage.h"
  25. //#include "config.h"
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdlib.h>
  29. /*for sendfile()*/
  30. #include <sys/sendfile.h>
  31. /*for O_RDONLY*/
  32. #include <fcntl.h>
  33. #include "sqlite3.h"
  34. #include <arpa/inet.h>
  35. //#define _GNU_SOURCE
  36. #include <time.h>
  37. #include "MessageHandler.h"
  38. #include <assert.h>
  39. #include <pthread.h>
  40. #include <mcheck.h>
  41. #define PASS 1
  42. #define FAIL -1
  43. #define FALSE 0
  44. #define TRUE 1 // Option 1
  45. //ChargePointMaxProfile
  46. #define ChargePointMaxProfile_JSON "../Storage/OCPP/ChargePointMaxProfile.json"
  47. //TxDefaultProfile
  48. #define TxDefaultProfile_0_JSON "../Storage/OCPP/TxDefaultProfile_0.json"
  49. #define TxDefaultProfile_1_JSON "../Storage/OCPP/TxDefaultProfile_1.json"
  50. #define TxDefaultProfile_2_JSON "../Storage/OCPP/TxDefaultProfile_2.json"
  51. //TxProfile
  52. #define TxProfile_1_JSON "../Storage/OCPP/TxProfile_1.json"
  53. #define TxProfile_2_JSON "../Storage/OCPP/TxProfile_2.json"
  54. #define ChargingProfile_0_JSON "../Storage/OCPP/chargingprofile_0.json"
  55. #define ChargingProfile_1_JSON "../Storage/OCPP/chargingprofile_1.json"
  56. #define ChargingProfile_2_JSON "../Storage/OCPP/chargingprofile_2.json"
  57. #define AuthorizationCache_JSON "../Storage/OCPP/AuthorizationCache.json"
  58. #define LocalAuthorizationList_JSON "../Storage/OCPP/LocalAuthorizationList.json"
  59. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  60. struct StatusCodeData *ShmStatusCodeData;
  61. struct PsuData *ShmPsuData ;
  62. struct OCPP16Data *ShmOCPP16Data;
  63. // define Macro
  64. #define SystemLogMessage
  65. // OCPP Message Type
  66. #define MESSAGE_TYPE_CALL 2
  67. #define MESSAGE_TYPE_CALLRESULT 3
  68. #define MESSAGE_TYPE_CALLERROR 4
  69. //
  70. #define server_cycle_Status 120
  71. #define MACROSTR(k) #k
  72. //ConfigurationMaxKeys
  73. #define GetConfigurationMaxKeysNUM 43
  74. //char guid[37];
  75. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  76. char queuedata[2600]={0};
  77. //===============================
  78. // Configuration: unknownkey
  79. //===============================
  80. static char unknownkey[10][20]={0};
  81. static int UnknownKeynum = 0;
  82. //===============================
  83. // Gun Total Numbers
  84. //===============================
  85. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  86. static int gunTotalNumber=0;
  87. //===============================
  88. // Local List Version
  89. //===============================
  90. static int localversion=0;
  91. static char idTagAuthorization[32]={0};
  92. //===============================
  93. // OCPP Path
  94. //===============================
  95. extern char OcppPath[160];
  96. extern char OcppProtocol[10];
  97. extern char OcppHost[50];
  98. extern char OcppTempPath[50];
  99. int OcppPort=0;
  100. //===============================
  101. // OCPP sign variable
  102. //===============================
  103. int server_sign = FALSE;
  104. int server_pending = FALSE;
  105. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  106. int BootNotificationInterval = 0;
  107. static int SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  108. //===============================
  109. // OCPP auth variable
  110. //===============================
  111. int authenrequest = FALSE;
  112. int authorizeRetryTimes = 0; //number of Retry times
  113. //===============================
  114. // OCPP StartTransaction transactionId variables
  115. //===============================
  116. static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  117. //===============================
  118. // OCPP other variables
  119. //===============================
  120. int isUpdateRequest = FALSE;
  121. static int HeartBeatWaitTime = 10;
  122. static int FirstHeartBeat = 0;
  123. static int FirmwareStatusNotificationStatus = 3; // Idle
  124. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  125. static char CurrentChargingProfileScheduleStr[30]={0};
  126. //========================================
  127. // OCPP status/previous related variables
  128. //========================================
  129. static int GunStatusInterval = 10;
  130. int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  131. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  132. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  133. static int GbPreviousSystemStatus[GB_QUANTITY];
  134. static int AcPreviousSystemStatus[AC_QUANTITY];
  135. int TransactionMessageAttemptsValue = 0;
  136. int TransactionMessageRetryIntervalValue = 0;
  137. static struct OCPPAuthLocalElemet
  138. {
  139. int listVersionInt;
  140. char idTagstr[20];
  141. char parentIdTag[20];
  142. char expiryDate[30];
  143. char idTagstatus[16];
  144. }idTagQuery;
  145. //=============================================
  146. // OCPP HeartBeat Response Not Receive Counts
  147. //============================================
  148. static int HeartBeatWithNOResponse = 0;
  149. static int HeartBeatCount = 0;
  150. extern struct lws *wsi_client;
  151. extern struct lws_context *context;
  152. #if 0
  153. extern unsigned char *SendBuffer;
  154. #endif
  155. extern unsigned char SendBuffer[4096];
  156. extern int SendBufLen;
  157. //extern map_t hashMap;
  158. //extern data_struct_t* mapItem; --- remove for temporally
  159. //extern data_struct_t mapItem[0];
  160. extern char *random_uuid( char buf[37] );
  161. extern void split(char **arr, char *str, const char *del);
  162. extern pthread_mutex_t mutex1;
  163. extern struct Charger_Info Charger;
  164. extern sqlite3 *db;
  165. int TransactionMessageAttemptsGet(void);
  166. int TransactionMessageRetryIntervalGet(void);
  167. int GetOcppConnStatus(void);
  168. void SetOcppConnStatus(uint8_t status);
  169. int updateSetting(char *key, char *value);
  170. int setKeyValue(char *key, char *value);
  171. void OCPP_get_TableAuthlocalAllData(void);
  172. void processUnkownKey(void);
  173. //static char *querysql = "SELECT * FROM ocpp_auth_local;";
  174. struct StructOCPPMeterValue
  175. {
  176. unsigned char TimeStamp[28];
  177. struct StructSampledValue SampledValue[10];
  178. };
  179. struct ClientTime
  180. {
  181. unsigned int Heartbeat;
  182. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  183. unsigned int StartTransaction;
  184. unsigned int StopTransaction;
  185. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  186. }clientTime;
  187. typedef union
  188. {
  189. //Operations Initiated by Central System
  190. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  191. struct
  192. {
  193. //CsMsgValue[0]
  194. unsigned char StatusNotificationReq :1; //bit 0,
  195. unsigned char StatusNotificationConf :1; //bit 0,
  196. unsigned char :6; //bit 2~7
  197. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  198. }CpinitiateMsg;
  199. CpinitiateMsg cpinitateMsg;
  200. //==========================================
  201. // Init all Enumeration & Mapping String
  202. //==========================================
  203. /*ChargePointErrorCode*/
  204. typedef enum {
  205. ConnectorLockFailure,
  206. EVCommunicationError,
  207. GroundFailure,
  208. HighTemperature,
  209. InternalError,
  210. LocalListConflict,
  211. NoError,
  212. OtherError,
  213. OverCurrentFailure,
  214. OverVoltage,
  215. PowerMeterFailure,
  216. PowerSwitchFailure,
  217. ReaderFailure,
  218. ResetFailure,
  219. UnderVoltage,
  220. WeakSignal
  221. } ChargePointErrorCode;
  222. #if 0
  223. static char *ChargePointErrorCodeStr[] = {
  224. MACROSTR(ConnectorLockFailure),
  225. MACROSTR(EVCommunicationError),
  226. MACROSTR(GroundFailure),
  227. MACROSTR(HighTemperature),
  228. MACROSTR(InternalError),
  229. MACROSTR(LocalListConflict),
  230. MACROSTR(NoError),
  231. MACROSTR(OtherError),
  232. MACROSTR(OverCurrentFailure),
  233. MACROSTR(OverVoltage),
  234. MACROSTR(PowerMeterFailure),
  235. MACROSTR(PowerSwitchFailure),
  236. MACROSTR(ReaderFailure),
  237. MACROSTR(ResetFailure),
  238. MACROSTR(UnderVoltage),
  239. MACROSTR(WeakSignal)
  240. };
  241. #endif
  242. /*ChargePointStatus*/
  243. typedef enum {
  244. Available =0,
  245. Preparing,
  246. Charging,
  247. SuspendedEVSE,
  248. SuspendedEV,
  249. Finishing,
  250. Reserved,
  251. Unavailable,
  252. Faulted
  253. } ChargePointStatus;
  254. static char * ChargePointStatusStr[] = {
  255. MACROSTR(Available),
  256. MACROSTR(Preparing),
  257. MACROSTR(Charging),
  258. MACROSTR(SuspendedEVSE),
  259. MACROSTR(SuspendedEV),
  260. MACROSTR(Finishing),
  261. MACROSTR(Reserved),
  262. MACROSTR(Unavailable),
  263. MACROSTR(Faulted)
  264. };
  265. /*AvailabilityType*/
  266. typedef enum {
  267. RegistrationStatus_Accepted,
  268. RegistrationStatus_Pending,
  269. RegistrationStatus_Rejected
  270. } RegistrationStatus;
  271. static char *RegistrationStatusStr[] = {
  272. MACROSTR(Accepted),
  273. MACROSTR(Pending),
  274. MACROSTR(Rejected)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. Inoperative,
  279. Operative
  280. } AvailabilityType;
  281. static char *AvailabilityTypeStr[] = {
  282. MACROSTR(Inoperative),
  283. MACROSTR(Operative)
  284. };
  285. /*AvailabilityStatus*/
  286. typedef enum {
  287. Accepted,
  288. Rejected,
  289. Scheduled
  290. } AvailabilityStatus;
  291. static char *AvailabilityStatusStr[] = {
  292. MACROSTR(Accepted),
  293. MACROSTR(Rejected),
  294. MACROSTR(Scheduled)
  295. };
  296. /*ConfigurationStatus*/
  297. typedef enum {
  298. ConfigurationStatus_Accepted,
  299. ConfigurationStatus_Rejected,
  300. RebootRequired,
  301. NotSupported
  302. } ConfigurationStatus;
  303. static char *ConfigurationStatusStr[] = {
  304. MACROSTR(Accepted),
  305. MACROSTR(Rejected),
  306. MACROSTR(RebootRequired),
  307. MACROSTR(NotSupported)
  308. };
  309. /*ClearCacheStatus*/
  310. typedef enum {
  311. ClearCacheStatus_Accepted,
  312. ClearCacheStatus_Rejected
  313. } ClearCacheStatus;
  314. static char *ClearCacheStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected)
  317. };
  318. /*ChargingProfilePurposeType*/
  319. typedef enum {
  320. ChargePointMaxProfile,
  321. TxDefaultProfile,
  322. TxProfile
  323. } ChargingProfilePurposeType;
  324. static char *ChargingProfilePurposeTypeStr[] = {
  325. MACROSTR(ChargePointMaxProfile),
  326. MACROSTR(TxDefaultProfile),
  327. MACROSTR(TxProfile)
  328. };
  329. /*ChargingProfileStatus*/
  330. typedef enum {
  331. ChargingProfileStatus_Accepted,
  332. ChargingProfileStatus_Rejected,
  333. ChargingProfileStatus_NotSupported
  334. } ChargingProfileStatus;
  335. static char *ChargingProfileStatusStr[] = {
  336. MACROSTR(Accepted),
  337. MACROSTR(Rejected),
  338. MACROSTR(NotSupported)
  339. };
  340. /*ClearChargingProfileStatus*/
  341. typedef enum {
  342. ClearChargingProfileStatus_Accepted,
  343. ClearChargingProfileStatus_Unknown
  344. } ClearChargingProfileStatus;
  345. static char *ClearChargingProfileStatusStr[] = {
  346. MACROSTR(Accepted),
  347. MACROSTR(Unknown)
  348. };
  349. /*GetCompositeScheduleStatus*/
  350. typedef enum {
  351. GetCompositeScheduleStatus_Accepted,
  352. GetCompositeScheduleStatus_Rejected
  353. } GetCompositeScheduleStatus;
  354. static char *GetCompositeScheduleStatusStr[] = {
  355. MACROSTR(Accepted),
  356. MACROSTR(Rejected)
  357. };
  358. /*ChargingRateUnitType*/
  359. typedef enum {
  360. ChargingRateUnitType_W,
  361. ChargingRateUnitType_A
  362. } ChargingRateUnitType;
  363. /*AuthorizationStatus*/
  364. typedef enum {
  365. AuthorizationStatus_Accepted ,
  366. AuthorizationStatus_Blocked ,
  367. AuthorizationStatus_Expired ,
  368. AuthorizationStatus_Invalid ,
  369. AuthorizationStatus_ConcurrentTx
  370. } AuthorizationStatus;
  371. /*UpdateType*/
  372. typedef enum {
  373. Differential ,
  374. Full
  375. } UpdateType;
  376. static char *UpdateTypeStr[] = {
  377. MACROSTR(Differential),
  378. MACROSTR(Full)
  379. };
  380. /*UpdateStatus*/
  381. typedef enum {
  382. UpdateStatus_Accepted ,
  383. UpdateStatus_Failed ,
  384. UpdateStatus_NotSupported ,
  385. UpdateStatus_VersionMismatch
  386. } UpdateStatus;
  387. static char *UpdateStatusStr[] = {
  388. MACROSTR(Accepted),
  389. MACROSTR(Failed),
  390. MACROSTR(NotSupported),
  391. MACROSTR(VersionMismatch)
  392. };
  393. /*RemoteStartStopStatus*/
  394. typedef enum {
  395. RemoteStartStopStatus_Accepted,
  396. RemoteStartStopStatus_Rejected
  397. } RemoteStartStopStatus;
  398. static char *RemoteStartStopStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Rejected)
  401. };
  402. /*ReservationStatus*/
  403. typedef enum {
  404. ReservationStatus_Accepted,
  405. ReservationStatus_Faulted,
  406. ReservationStatus_Occupied,
  407. ReservationStatus_Rejected,
  408. ReservationStatus_Unavailable
  409. } ReservationStatus;
  410. static char *ReservationStatusStr[] = {
  411. MACROSTR(Accepted),
  412. MACROSTR(Faulted),
  413. MACROSTR(Occupied),
  414. MACROSTR(Rejected),
  415. MACROSTR(Unavailable)
  416. };
  417. /*ResetType*/
  418. typedef enum {
  419. Hard,
  420. Soft
  421. } ResetType;
  422. static char *ResetTypeStr[] = {
  423. MACROSTR(Hard),
  424. MACROSTR(Soft)
  425. };
  426. /*ResetStatus*/
  427. typedef enum {
  428. ResetStatus_Accepted,
  429. ResetStatus_Rejected
  430. } ResetStatus;
  431. static char *ResetStatusStr[] = {
  432. MACROSTR(Accepted),
  433. MACROSTR(Rejected)
  434. };
  435. /*DiagnosticsStatus*/
  436. typedef enum {
  437. DiagnosticsStatus_Idle,
  438. DiagnosticsStatus_Uploaded,
  439. DiagnosticsStatus_UploadFailed,
  440. DiagnosticsStatus_Uploading
  441. } DiagnosticsStatus;
  442. static char * DiagnosticsStatusStr[] = {
  443. MACROSTR(Idle),
  444. MACROSTR(Uploaded),
  445. MACROSTR(UploadFailed),
  446. MACROSTR(Uploading)
  447. };
  448. /*FirmwareStatus*/
  449. typedef enum {
  450. FirmwareStatus_Downloaded,
  451. FirmwareStatus_DownloadFailed,
  452. FirmwareStatus_Downloading,
  453. FirmwareStatus_Idle,
  454. FirmwareStatus_InstallationFailed,
  455. FirmwareStatus_Installing,
  456. FirmwareStatus_Installed
  457. } FirmwareStatus;
  458. static char * FirmwareStatusStr[] = {
  459. MACROSTR(Downloaded),
  460. MACROSTR(DownloadFailed),
  461. MACROSTR(Downloading),
  462. MACROSTR(Idle),
  463. MACROSTR(InstallationFailed),
  464. MACROSTR(Installing),
  465. MACROSTR(Installed)
  466. };
  467. /*MessageTrigger*/
  468. typedef enum {
  469. BootNotification,
  470. DiagnosticsStatusNotification,
  471. FirmwareStatusNotification,
  472. Heartbeat,
  473. MeterValues,
  474. StatusNotification
  475. } MessageTrigger;
  476. static char * MessageTriggerStr[] = {
  477. MACROSTR(BootNotification),
  478. MACROSTR(DiagnosticsStatusNotification),
  479. MACROSTR(FirmwareStatusNotification),
  480. MACROSTR(Heartbeat),
  481. MACROSTR(MeterValues),
  482. MACROSTR(StatusNotification)
  483. };
  484. /*TriggerMessageStatus*/
  485. typedef enum {
  486. TriggerMessageStatus_Accepted ,
  487. TriggerMessageStatus_Rejected ,
  488. TriggerMessageStatus_NotImplemented
  489. } TriggerMessageStatus;
  490. static char * TriggerMessageStatusStr[] = {
  491. MACROSTR(Accepted),
  492. MACROSTR(Rejected),
  493. MACROSTR(NotImplemented)
  494. };
  495. /*UnlockStatus*/
  496. typedef enum {
  497. Unlocked,
  498. UnlockFailed,
  499. UnlockStatus_NotSupported
  500. } UnlockStatus;
  501. static char * UnlockStatusStr[] = {
  502. MACROSTR(Unlocked),
  503. MACROSTR(UnlockFailed),
  504. MACROSTR(NotSupported)
  505. };
  506. /*StopTransactionReason*/
  507. typedef enum {
  508. EmergencyStop,
  509. EVDisconnected,
  510. HardReset,
  511. Local,
  512. Other,
  513. PowerLoss,
  514. Reboot,
  515. Remote,
  516. SoftReset,
  517. UnlockCommand,
  518. DeAuthorized
  519. } StopTransactionReason;
  520. static char * StopTransactionReasonStr[] = {
  521. MACROSTR(EmergencyStop),
  522. MACROSTR(EVDisconnected),
  523. MACROSTR(HardReset),
  524. MACROSTR(Local),
  525. MACROSTR(Other),
  526. MACROSTR(PowerLoss),
  527. MACROSTR(Reboot),
  528. MACROSTR(Remote),
  529. MACROSTR(SoftReset),
  530. MACROSTR(UnlockCommand),
  531. MACROSTR(DeAuthorized)
  532. };
  533. /*CancelReservationStatus*/
  534. typedef enum {
  535. CancelReservationStatus_Accepted,
  536. CancelReservationStatus_Rejected
  537. } CancelReservationStatus;
  538. static char * CancelReservationStatusStr[] = {
  539. MACROSTR(Accepted),
  540. MACROSTR(Rejected)
  541. };
  542. /*ReadingContext*/
  543. typedef enum {
  544. ReadingContext_Interruption_Begin,
  545. ReadingContext_Interruption_End,
  546. ReadingContext_Other,
  547. ReadingContext_Sample_Clock,
  548. ReadingContext_Sample_Periodic ,
  549. ReadingContext_Transaction_Begin ,
  550. ReadingContext_Transaction_End,
  551. ReadingContext_Trigger
  552. } ReadingContext;
  553. static char * ReadingContextStr[] = {
  554. MACROSTR(Interruption.Begin),
  555. MACROSTR(Interruption.End),
  556. MACROSTR(Other),
  557. MACROSTR(Sample.Clock),
  558. MACROSTR(Sample.Periodic),
  559. MACROSTR(Transaction.Begin),
  560. MACROSTR(Transaction.End),
  561. MACROSTR(Trigger)
  562. };
  563. /*ValueFormat*/
  564. typedef enum {
  565. Raw,
  566. SignedData
  567. } ValueFormat;
  568. static char * ValueFormatStr[] = {
  569. MACROSTR(Raw),
  570. MACROSTR(SignedData)
  571. };
  572. /*Measurand*/
  573. typedef enum {
  574. Current_Export ,
  575. Current_Import,
  576. Current_Offered,
  577. Energy_Active_Export_Register,
  578. Energy_Active_Import_Register,
  579. Energy_Reactive_Export_Register,
  580. Energy_Reactive_Import_Register,
  581. Energy_Active_Export_Interval,
  582. Energy_Active_Import_Interval,
  583. Energy_Reactive_Export_Interval,
  584. Energy_Reactive_Import_Interval,
  585. Frequency,
  586. Power_Active_Export ,
  587. Power_Active_Import,
  588. Power_Factor,
  589. Power_Offered,
  590. Power_Reactive_Export,
  591. Power_Reactive_Import,
  592. RPM,
  593. SoC,
  594. Temperature ,
  595. Voltage
  596. } Measurand;
  597. static char * MeasurandStr[] = {
  598. MACROSTR(Current.Export),
  599. MACROSTR(Current.Import),
  600. MACROSTR(Current.Offered),
  601. MACROSTR(Energy.Active.Export.Register),
  602. MACROSTR(Energy.Active.Import.Register),
  603. MACROSTR(Energy.Reactive.Export.Register),
  604. MACROSTR(Energy.Reactive.Import.Register),
  605. MACROSTR(Energy.Active.Export.Interval),
  606. MACROSTR(Energy.Active.Import.Interval),
  607. MACROSTR(Energy.Reactive.Export.Interval),
  608. MACROSTR(Energy.Reactive.Import.Interval),
  609. MACROSTR(Frequency),
  610. MACROSTR(Power.Active.Export),
  611. MACROSTR(Power.Active.Import),
  612. MACROSTR(Power.Factor),
  613. MACROSTR(Power.Offered),
  614. MACROSTR(Power.Reactive.ExportMACROSTR),
  615. MACROSTR(Power.Reactive.Import),
  616. MACROSTR(RPM),
  617. MACROSTR(SoC),
  618. MACROSTR(Temperature),
  619. MACROSTR(Voltage)
  620. };
  621. /*Location*/
  622. typedef enum {
  623. Location_Body,
  624. Location_Cable,
  625. Location_EV,
  626. Location_Inlet ,
  627. Location_Outlet
  628. } Location;
  629. static char * LocationStr[] = {
  630. MACROSTR(Body),
  631. MACROSTR(Cable),
  632. MACROSTR(EV),
  633. MACROSTR(Inlet),
  634. MACROSTR(Outlet)
  635. };
  636. /*Phase*/
  637. typedef enum {
  638. L1,
  639. L2,
  640. L3,
  641. N,
  642. L1_N,
  643. L2_N,
  644. L3_N,
  645. L1_L2,
  646. L2_L3,
  647. L3_L1
  648. } Phase;
  649. static char * PhaseStr[] = {
  650. MACROSTR(L1),
  651. MACROSTR(L2),
  652. MACROSTR(L3),
  653. MACROSTR(N),
  654. MACROSTR(L1-N),
  655. MACROSTR(L2-N),
  656. MACROSTR(L3-N),
  657. MACROSTR(L1-L2),
  658. MACROSTR(L2-L3),
  659. MACROSTR(L3-L1)
  660. };
  661. /*UnitOfMeasure*/
  662. typedef enum {
  663. UnitOfMeasure_Wh,
  664. UnitOfMeasure_kWh ,
  665. UnitOfMeasure_varh ,
  666. UnitOfMeasure_kvarh ,
  667. UnitOfMeasure_W ,
  668. UnitOfMeasure_kW ,
  669. UnitOfMeasure_VA ,
  670. UnitOfMeasure_kVA ,
  671. UnitOfMeasure_var ,
  672. UnitOfMeasure_kvar ,
  673. UnitOfMeasure_A ,
  674. UnitOfMeasure_V ,
  675. UnitOfMeasure_Celsius ,
  676. UnitOfMeasure_Fahrenheit ,
  677. UnitOfMeasure_K ,
  678. UnitOfMeasure_Percent
  679. } UnitOfMeasure;
  680. static char * UnitOfMeasureStr[] = {
  681. MACROSTR(Wh),
  682. MACROSTR(kWh),
  683. MACROSTR(varh),
  684. MACROSTR(kvarh),
  685. MACROSTR(W),
  686. MACROSTR(kW),
  687. MACROSTR(VA),
  688. MACROSTR(kVA),
  689. MACROSTR(var),
  690. MACROSTR(kvar),
  691. MACROSTR(A),
  692. MACROSTR(V),
  693. MACROSTR(Celsius),
  694. MACROSTR(Fahrenheit),
  695. MACROSTR(K),
  696. MACROSTR(Percent)
  697. };
  698. #if 0
  699. /*Configuration enum*/
  700. enum CoreProfile {
  701. AllowOfflineTxForUnknownId=0,
  702. AuthorizationCacheEnabled,
  703. AuthorizeRemoteTxRequests,
  704. BlinkRepeat,
  705. ClockAlignedDataInterval,
  706. ConnectionTimeOut,
  707. GetConfigurationMaxKeys,
  708. HeartbeatInterval,
  709. LightIntensity,
  710. LocalAuthorizeOffline,
  711. LocalPreAuthorize,
  712. MaxEnergyOnInvalidId,
  713. MeterValuesAlignedData,
  714. MeterValuesAlignedDataMaxLength,
  715. MeterValuesSampledData,
  716. MeterValuesSampledDataMaxLength,
  717. MeterValueSampleInterval,
  718. MinimumStatusDuration,
  719. NumberOfConnectors,
  720. ResetRetries,
  721. ConnectorPhaseRotation,
  722. ConnectorPhaseRotationMaxLength,
  723. StopTransactionOnEVSideDisconnect,
  724. StopTransactionOnInvalidId,
  725. StopTxnAlignedData,
  726. StopTxnAlignedDataMaxLength,
  727. StopTxnSampledData,
  728. StopTxnSampledDataMaxLength,
  729. SupportedFeatureProfiles,
  730. SupportedFeatureProfilesMaxLength,
  731. TransactionMessageAttempts,
  732. TransactionMessageRetryInterval,
  733. UnlockConnectorOnEVSideDisconnect,
  734. WebSocketPingInterval,
  735. _CoreProfile_CNT
  736. };
  737. #endif
  738. enum LocalAuthListManagementProfile{
  739. LocalAuthListEnabled=0,
  740. LocalAuthListMaxLength,
  741. SendLocalListMaxLength,
  742. _LocalAuthListManagementProfile_CNT
  743. };
  744. enum ReservationProfile{
  745. ReserveConnectorZeroSupported
  746. };
  747. enum SmartChargingProfile{
  748. ChargeProfileMaxStackLevel,
  749. ChargingScheduleAllowedChargingRateUnit,
  750. ChargingScheduleMaxPeriods,
  751. ConnectorSwitch3to1PhaseSupported,
  752. MaxChargingProfilesInstalled
  753. };
  754. enum ChargerSystemStatus{
  755. ChargerSystemStatus_Booting,
  756. ChargerSystemStatus_Idle,
  757. ChargerSystemStatus_Authorizing,
  758. ChargerSystemStatus_Preparing,
  759. ChargerSystemStatus_Charging,
  760. ChargerSystemStatus_Terminating,
  761. ChargerSystemStatus_Alarm,
  762. ChargerSystemStatus_Fault
  763. };
  764. enum GetConfigurationKey {
  765. GetConfiguration_AllowOfflineTxForUnknownId=0,
  766. GetConfiguration_AuthorizationCacheEnabled,
  767. GetConfiguration_AuthorizeRemoteTxRequests,
  768. GetConfiguration_BlinkRepeat,
  769. GetConfiguration_ClockAlignedDataInterval,
  770. GetConfiguration_ConnectionTimeOut,
  771. GetConfiguration_GetConfigurationMaxKeys,
  772. GetConfiguration_HeartbeatInterval,
  773. GetConfiguration_LightIntensity,
  774. GetConfiguration_LocalAuthorizeOffline,
  775. GetConfiguration_LocalPreAuthorize,
  776. GetConfiguration_MaxEnergyOnInvalidId,
  777. GetConfiguration_MeterValuesAlignedData,
  778. GetConfiguration_MeterValuesAlignedDataMaxLength,
  779. GetConfiguration_MeterValuesSampledData,
  780. GetConfiguration_MeterValuesSampledDataMaxLength,
  781. GetConfiguration_MeterValueSampleInterval,
  782. GetConfiguration_MinimumStatusDuration,
  783. GetConfiguration_NumberOfConnectors,
  784. GetConfiguration_ResetRetries,
  785. GetConfiguration_ConnectorPhaseRotation,
  786. GetConfiguration_ConnectorPhaseRotationMaxLength,
  787. GetConfiguration_StopTransactionOnEVSideDisconnect,
  788. GetConfiguration_StopTransactionOnInvalidId,
  789. GetConfiguration_StopTxnAlignedData,
  790. GetConfiguration_StopTxnAlignedDataMaxLength,
  791. GetConfiguration_StopTxnSampledData,
  792. GetConfiguration_StopTxnSampledDataMaxLength,
  793. GetConfiguration_SupportedFeatureProfiles,
  794. GetConfiguration_SupportedFeatureProfilesMaxLength,
  795. GetConfiguration_TransactionMessageAttempts,
  796. GetConfiguration_TransactionMessageRetryInterval,
  797. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  798. GetConfiguration_WebSocketPingInterval,
  799. GetConfiguration_LocalAuthListEnabled,
  800. GetConfiguration_LocalAuthListMaxLength,
  801. GetConfiguration_SendLocalListMaxLength,
  802. GetConfiguration_ReserveConnectorZeroSupported,
  803. GetConfiguration_ChargeProfileMaxStackLevel,
  804. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  805. GetConfiguration_ChargingScheduleMaxPeriods,
  806. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  807. GetConfiguration_MaxChargingProfilesInstalled,
  808. };
  809. //GetConfiguration Array
  810. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  811. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  812. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  813. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  814. //==========================================
  815. // Init all share memory
  816. //==========================================
  817. int InitShareMemory()
  818. {
  819. int result = PASS;
  820. int MeterSMId;
  821. //printf("1\n");
  822. //creat ShmSysConfigAndInfo
  823. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  824. {
  825. #ifdef SystemLogMessage
  826. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  827. #endif
  828. result = FAIL;
  829. }
  830. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  831. {
  832. #ifdef SystemLogMessage
  833. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  834. #endif
  835. result = FAIL;
  836. }
  837. else
  838. {}
  839. //printf("2\n");
  840. //creat ShmStatusCodeData
  841. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  842. {
  843. #ifdef SystemLogMessage
  844. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  845. #endif
  846. result = FAIL;
  847. }
  848. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  849. {
  850. #ifdef SystemLogMessage
  851. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  852. #endif
  853. result = FAIL;
  854. }
  855. else
  856. {}
  857. //printf("3\n");
  858. //creat ShmPsuData
  859. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  860. {
  861. #ifdef SystemLogMessage
  862. DEBUG_ERROR("shmget ShmPsuData NG\n");
  863. #endif
  864. result = FAIL;
  865. }
  866. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  867. {
  868. #ifdef SystemLogMessage
  869. DEBUG_ERROR("shmat ShmPsuData NG\n");
  870. #endif
  871. result = FAIL;
  872. }
  873. else
  874. {}
  875. //creat ShmOCPP16Data
  876. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  877. {
  878. #ifdef SystemLogMessage
  879. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  880. #endif
  881. result = FAIL;
  882. }
  883. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  884. {
  885. #ifdef SystemLogMessage
  886. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  887. #endif
  888. result = FAIL;
  889. }
  890. else
  891. {}
  892. /****************************** For Initial Settings************************************************/
  893. gunTotalNumber = (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY;
  894. //memset(ShmOCPP16Data->StatusNotification,0,sizeof(struct StructStatusNotification)*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY));
  895. for(int gun_index=0; gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/; gun_index++ )
  896. {
  897. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  898. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  899. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  900. }
  901. // Charger PRE_SYS_MODE
  902. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  903. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  904. clientTime.Heartbeat=time((time_t*)NULL);
  905. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ;gun_index++)
  906. {
  907. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  908. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  909. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError");
  910. }
  911. //HeartBeatWaitTime = 10;
  912. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  913. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  914. // allocate Configuration memory address
  915. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  916. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  917. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  918. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  920. {
  921. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  922. DEBUG_INFO("DC ...\n");
  923. }
  924. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  925. {
  926. SystemInitial = AC_QUANTITY;
  927. DEBUG_INFO("AC ...\n");
  928. }
  929. //Status Setting
  930. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  931. {
  932. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  933. }
  934. for (int index = 0; index < CCS_QUANTITY; index++)
  935. {
  936. CcsPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  937. }
  938. for (int index = 0; index < GB_QUANTITY; index++)
  939. {
  940. GbPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  941. }
  942. for (int index = 0; index < AC_QUANTITY; index++)
  943. {
  944. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  945. }
  946. //memset(unknownkey, 0, 10);
  947. return result;
  948. }
  949. int ProcessShareMemory()
  950. {
  951. if(InitShareMemory() == FAIL)
  952. {
  953. #ifdef SystemLogMessage
  954. DEBUG_ERROR("InitShareMemory NG\n");
  955. #endif
  956. if(ShmStatusCodeData!=NULL)
  957. {
  958. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  959. }
  960. sleep(5);
  961. return FAIL;
  962. }
  963. return PASS;
  964. }
  965. //---------------------------------------------
  966. // new:
  967. // enum SYSTEM_STATUS
  968. // {
  969. // SYS_MODE_BOOTING = 0,
  970. // SYS_MODE_IDLE = 1,
  971. // SYS_MODE_AUTHORIZING = 2,
  972. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  973. // SYS_MODE_REASSIGN = 4,
  974. // SYS_MODE_PREPARING = 5,
  975. // SYS_MODE_PREPARE_FOR_EV = 6,
  976. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  977. // SYS_MODE_CHARGING = 8,
  978. // SYS_MODE_TERMINATING = 9,
  979. // SYS_MODE_COMPLETE = 10,
  980. // SYS_MODE_ALARM = 11,
  981. // SYS_MODE_FAULT = 12,
  982. // SYS_MODE_RESERVATION = 13,
  983. // SYS_MODE_BOOKING = 14,
  984. // SYS_MODE_MAINTAIN = 15,
  985. // SYS_MODE_DEBUG = 16,
  986. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  987. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  988. // SYS_MODE_UPDATE = 19
  989. // };
  990. //
  991. //
  992. //-----------------------------------------
  993. void CheckSystemValue(void)
  994. {
  995. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  996. int IdleModeCnt = 0;
  997. char filenmae[100]={0};
  998. char str[100]={0};
  999. //===============================
  1000. // send Heartbeat
  1001. //===============================
  1002. //printf("server_sign=%d\n",server_sign);
  1003. //printf("HeartBeatWaitTime=%d\n",HeartBeatWaitTime);
  1004. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime)/*((time((time_t*)NULL)-clientTime.Heartbeat)>= ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval)*/)
  1005. {
  1006. printf("Heartbeat !!!\n");
  1007. //parameter for test
  1008. sendHeartbeatRequest(0);
  1009. //==============================================
  1010. // Reset Waiting Time
  1011. //==============================================
  1012. clientTime.Heartbeat=time((time_t*)NULL);
  1013. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1014. }
  1015. //==============================================
  1016. // Update firmware request
  1017. //==============================================
  1018. if(isUpdateRequest == TRUE )
  1019. {
  1020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1021. {
  1022. for(int gun_index=0;gun_index < (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY) ;gun_index++)
  1023. {
  1024. //check SystemStatus
  1025. /*************************DC*******************************/
  1026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1027. {
  1028. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1029. {
  1030. IdleModeCnt = IdleModeCnt + 1;
  1031. }
  1032. }
  1033. for (int index = 0; index < CCS_QUANTITY; index++)
  1034. {
  1035. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1036. {
  1037. IdleModeCnt = IdleModeCnt + 1;
  1038. }
  1039. }
  1040. for (int index = 0; index < GB_QUANTITY; index++)
  1041. {
  1042. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == 1)) //S_IDLE
  1043. {
  1044. IdleModeCnt = IdleModeCnt + 1;
  1045. }
  1046. }
  1047. }
  1048. if(IdleModeCnt == (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY ))
  1049. {
  1050. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1051. isUpdateRequest = FALSE;
  1052. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1053. }
  1054. }
  1055. else
  1056. {
  1057. /*************************AC*******************************/
  1058. for (int index = 0; index < AC_QUANTITY; index++)
  1059. {
  1060. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == 1) //S_IDLE
  1061. {
  1062. IdleModeCnt = IdleModeCnt + 1;
  1063. }
  1064. }
  1065. if(IdleModeCnt == AC_QUANTITY)
  1066. {
  1067. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Installing]);
  1068. isUpdateRequest = FALSE;
  1069. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1; // trigger firmware upgrade
  1070. }
  1071. }
  1072. }
  1073. //DEBUG_INFO("\n gunTotalNumber=%d\n",gunTotalNumber);
  1074. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1075. {
  1076. //===============================
  1077. // CSU Trigger Reset Conf
  1078. //===============================
  1079. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1080. {
  1081. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1082. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1083. {
  1084. server_sign = FALSE;
  1085. }
  1086. }
  1087. //===============================
  1088. // CSU Trigger Authorize Request
  1089. //===============================
  1090. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3)/*authenrequest == FALSE*/)
  1091. {
  1092. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE") == 0)// [If AuthorizeRemoteTxRequests = true
  1093. {
  1094. sendAuthorizeRequest(0);
  1095. authorizeRetryTimes = authorizeRetryTimes + 1;
  1096. // authenrequest = TRUE
  1097. if(authorizeRetryTimes < 3)
  1098. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1099. }
  1100. }
  1101. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1102. {
  1103. authorizeRetryTimes = 0;
  1104. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1105. server_sign = FALSE;
  1106. }
  1107. //===============================
  1108. // CSU Trigger Smart Charging Profilw
  1109. //===============================
  1110. if((server_sign == TRUE) && (ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1))
  1111. {
  1112. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1113. GetChargingProfileRequest(gun_index);
  1114. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1115. }
  1116. //==============================================
  1117. // Charger start transaction
  1118. //==============================================
  1119. if((server_sign == TRUE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1120. {
  1121. sendStartTransactionRequest(gun_index);
  1122. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1123. clientTime.StartTransaction = time((time_t*)NULL);
  1124. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1125. }
  1126. //==============================================
  1127. // Charger stop transaction
  1128. //==============================================
  1129. if((server_sign == TRUE) && ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1130. {
  1131. sendStopTransactionRequest(gun_index);
  1132. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1133. clientTime.StopTransaction = time((time_t*)NULL);
  1134. }
  1135. //DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.AcChargingData[0].SystemStatus);
  1136. //==============================================
  1137. // Charger status report
  1138. //==============================================
  1139. /* Check Mode Change */
  1140. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1141. {
  1142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1143. {
  1144. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1145. {
  1146. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1147. {
  1148. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1149. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1150. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1151. statusModeChage[gun_index] = TRUE;
  1152. }
  1153. }
  1154. }
  1155. for (int index = 0; index < CCS_QUANTITY; index++)
  1156. {
  1157. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1158. {
  1159. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1160. {
  1161. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1162. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1163. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1164. statusModeChage[gun_index] = TRUE;
  1165. }
  1166. }
  1167. }
  1168. for (int index = 0; index < GB_QUANTITY; index++)
  1169. {
  1170. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)/*&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '4')*/)
  1171. {
  1172. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1173. {
  1174. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1175. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1176. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1177. statusModeChage[gun_index] = TRUE;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. else //AC
  1183. {
  1184. for (int index = 0; index < AC_QUANTITY; index++)
  1185. {
  1186. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1187. {
  1188. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1189. {
  1190. PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1191. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1192. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1193. statusModeChage[gun_index] = TRUE;
  1194. }
  1195. }
  1196. }// END OF FOR
  1197. }// END OF ELSE
  1198. if(((SystemInitial != 0)&& (server_sign == TRUE))||
  1199. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1200. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1201. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1202. {
  1203. if(SystemInitial != 0)
  1204. SystemInitial = SystemInitial -1;
  1205. //GunStatusInterval= GunStatusInterval* gun_index;
  1206. sendStatusNotificationRequest(gun_index);
  1207. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1208. //cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  1209. statusModeChage[gun_index] = FALSE;
  1210. //sleep(30); // sleep for 30 seconds
  1211. }
  1212. //==============================================
  1213. // Meter report
  1214. //==============================================
  1215. if((server_sign == TRUE) && ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1216. {
  1217. //check Transaction active
  1218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1219. {
  1220. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1221. {
  1222. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1223. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1224. {
  1225. meterValueSend[gun_index] =1;
  1226. }
  1227. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1228. {
  1229. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1230. if((access(filenmae,F_OK))!=-1)
  1231. {
  1232. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1233. sprintf(str,"rm -f %s",filenmae);
  1234. system(str);
  1235. }
  1236. }
  1237. }// End for CHAdeMO
  1238. for (int index = 0; index < CCS_QUANTITY; index++)
  1239. {
  1240. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1241. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1242. {
  1243. meterValueSend[gun_index] =1;
  1244. }
  1245. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1246. {
  1247. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1248. if((access(filenmae,F_OK))!=-1)
  1249. {
  1250. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1251. sprintf(str,"rm -f %s",filenmae);
  1252. system(str);
  1253. }
  1254. }
  1255. } // End for CCS
  1256. for (int index = 0; index < GB_QUANTITY; index++)
  1257. {
  1258. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1259. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1260. {
  1261. meterValueSend[gun_index] =1;
  1262. }
  1263. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1264. {
  1265. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1266. if((access(filenmae,F_OK))!=-1)
  1267. {
  1268. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1269. sprintf(str,"rm -f %s",filenmae);
  1270. system(str);
  1271. }
  1272. }
  1273. }// End for GB
  1274. }
  1275. else
  1276. {
  1277. for (int index = 0; index < AC_QUANTITY; index++)
  1278. {
  1279. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1280. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1281. {
  1282. meterValueSend[gun_index] =1;
  1283. }
  1284. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1285. {
  1286. sprintf(filenmae,"../Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1287. if((access(filenmae,F_OK))!=-1)
  1288. {
  1289. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1290. sprintf(str,"rm -f %s",filenmae);
  1291. system(str);
  1292. }
  1293. }
  1294. }//End for AC
  1295. }//END OF ELSE
  1296. // sleep(1);
  1297. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1298. if(meterValueSend[gun_index] == 1)
  1299. sendMeterValuesRequest(gun_index);
  1300. }
  1301. //==============================================
  1302. // Check Connector reserved
  1303. //==============================================
  1304. //===============================
  1305. // Check if Reserve is expired
  1306. //===============================
  1307. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1308. {
  1309. double diff_t;
  1310. struct tm tp;
  1311. // current time
  1312. time_t t = time(NULL);
  1313. // sprintf((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%s", "2018-09-20T02:56:54.973Z");
  1314. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1315. tp.tm_isdst = -1;
  1316. time_t utc = mktime(&tp);
  1317. diff_t = difftime(utc, t);
  1318. //DEBUG_INFO("diff_t=%f\n",diff_t);
  1319. if(diff_t <= 0)
  1320. {
  1321. DEBUG_INFO("reserve expired !!! \n");
  1322. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1323. //ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationReq = 1;
  1324. }
  1325. }//END OF Check if Reserve is expired
  1326. //==========================================
  1327. // csu trigger FirmwareStatusNotificationReq
  1328. //==========================================
  1329. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1330. {
  1331. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1332. }
  1333. //==========================================
  1334. // csu trigger CancelReservationConf
  1335. //==========================================
  1336. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1337. {
  1338. //sendCancelReservationConfirmation(uuid, comfirmstr);
  1339. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1340. }
  1341. //==========================================
  1342. // csu trigger ChangeAvailabilityConf
  1343. //==========================================
  1344. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1345. {
  1346. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1347. }
  1348. //==========================================
  1349. // csu trigger UnlockConnectorConf
  1350. //==========================================
  1351. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1352. {
  1353. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1354. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1355. }
  1356. //==========================================
  1357. // csu trigger ReserveNowConf
  1358. //==========================================
  1359. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1360. {
  1361. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1362. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1363. }
  1364. //==========================================
  1365. // csu trigger DataTransferReq
  1366. //==========================================
  1367. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1368. {
  1369. sendDataTransferRequest(gun_index);
  1370. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1371. }
  1372. }
  1373. }
  1374. //==========================================
  1375. // send request routine
  1376. //==========================================
  1377. int sendAuthorizeRequest(int gun_index)
  1378. {
  1379. mtrace();
  1380. int result = FAIL;
  1381. char message[100]={0};
  1382. char guid[37];
  1383. char tempdata[65]={0};
  1384. DEBUG_INFO("sendAuthorizeRequest \n");
  1385. //Local Authorize
  1386. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus ==0))
  1387. {
  1388. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1389. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1390. {
  1391. DEBUG_INFO("Local Authorization Fail !!!!\n");
  1392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1395. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1397. authorizeRetryTimes = 0;
  1398. return result;
  1399. }
  1400. else
  1401. {
  1402. DEBUG_INFO("Local Authorization Pass !!!!\n");
  1403. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1404. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1405. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1406. result = PASS;
  1407. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1408. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1409. authorizeRetryTimes = 0;
  1410. return result;
  1411. }
  1412. }
  1413. //initailize struct Authorize
  1414. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1415. //get data from shared memory
  1416. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1417. random_uuid(guid);
  1418. sprintf(message,"[ %d, \"%s\", \"Authorize\", { \"idTag\": \"%s\" } ]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1419. LWS_Send(message);
  1420. sprintf(tempdata, "Authorize,%d", gun_index);
  1421. if(hashmap_operation(0, guid, tempdata) == 1)
  1422. {
  1423. result = PASS;
  1424. DEBUG_ERROR("Authorize mapItem pass\n");
  1425. }
  1426. //#ifdef SystemLogMessage
  1427. //DEBUG_INFO(">>>>>Authorize request\n");
  1428. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1429. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1430. //#endif
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. return result;
  1433. }
  1434. int sendBootNotificationRequest(void)
  1435. {
  1436. mtrace();
  1437. int result = FAIL;
  1438. char message[500]={0}, payload[700]={0};
  1439. char guid[37]={0};
  1440. char tempdata[65]={0};
  1441. int IsGunCharging = FALSE;
  1442. //check Transaction active
  1443. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1444. {
  1445. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1446. {
  1447. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1448. {
  1449. IsGunCharging = TRUE;
  1450. }
  1451. }
  1452. for (int index = 0; index < CCS_QUANTITY; index++)
  1453. {
  1454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1455. {
  1456. IsGunCharging = TRUE;
  1457. }
  1458. }
  1459. for (int index = 0; index < GB_QUANTITY; index++)
  1460. {
  1461. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1462. {
  1463. IsGunCharging = TRUE;
  1464. }
  1465. }
  1466. }
  1467. else
  1468. {
  1469. for (int index = 0; index < AC_QUANTITY; index++)
  1470. {
  1471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1472. {
  1473. IsGunCharging = TRUE;
  1474. }
  1475. }
  1476. }
  1477. if(IsGunCharging == TRUE)
  1478. {
  1479. server_sign = TRUE;
  1480. return result;
  1481. }
  1482. // Fill BootNotification fields
  1483. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1484. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1485. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1486. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1487. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1488. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1489. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1490. sprintf(payload, "{ \"chargeBoxSerialNumber\": \"%s\", \"chargePointModel\": \"%s\", \"chargePointSerialNumber\": \"%s\", \"chargePointVendor\": \"%s\", \"firmwareVersion\": \"%s\", \"iccid\": \"%s\", \"imsi\": \"%s\", \"meterSerialNumber\": \"%s\", \"meterType\": \"%s\"} ",
  1491. ShmOCPP16Data->ChargeBoxId
  1492. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1493. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1494. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1495. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1496. ,ShmOCPP16Data->BootNotification.CpIccid
  1497. ,ShmOCPP16Data->BootNotification.CpImsi
  1498. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1499. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1500. random_uuid(guid);
  1501. sprintf(message,"[ %d, \"%s\", \"%s\", %s ]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1502. LWS_Send(message);
  1503. sprintf(tempdata, "BootNotification,0");
  1504. 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*/)
  1505. {
  1506. result = PASS;
  1507. }
  1508. memset(queuedata, 0, sizeof(queuedata));
  1509. strcpy(queuedata,message);
  1510. HeartBeatCount = 0;
  1511. //#ifdef SystemLogMessage
  1512. //DEBUG_INFO(">>>>>BootNotification request\n");
  1513. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1514. //#endif
  1515. return result;
  1516. }
  1517. int sendDataTransferRequest(int gun_index)
  1518. {
  1519. mtrace();
  1520. char message[1000]={0};
  1521. char guid[37]={0};
  1522. char tempdata[65]={0};
  1523. int result = FAIL;
  1524. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1525. random_uuid(guid);
  1526. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1527. MESSAGE_TYPE_CALL,
  1528. guid,
  1529. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1530. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1531. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1532. LWS_Send(message);
  1533. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1534. 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*/)
  1535. {
  1536. result = PASS;
  1537. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1538. }
  1539. //#ifdef SystemLogMessage
  1540. //DEBUG_INFO(">>>>>DataTransfer request\n");
  1541. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1542. //#endif
  1543. return result;
  1544. }
  1545. int sendDiagnosticsStatusNotificationRequest(char *status)
  1546. {
  1547. mtrace();
  1548. int result = FAIL;
  1549. char message[110]={0};
  1550. char guid[37]={0};
  1551. char tempdata[65]={0};
  1552. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1553. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1554. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1555. random_uuid(guid);
  1556. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1557. LWS_Send(message);
  1558. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1559. if(hashmap_operation(0, guid, tempdata) == 1)
  1560. {
  1561. result = PASS;
  1562. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1563. }
  1564. //#ifdef SystemLogMessage
  1565. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1566. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1567. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1568. //#endif
  1569. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1570. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1571. //record status
  1572. if(strcmp(status,"Idle")==0)
  1573. {
  1574. DiagnosticsStatusNotificationStatus = 0;
  1575. }
  1576. else if(strcmp(status,"Uploaded")==0)
  1577. {
  1578. DiagnosticsStatusNotificationStatus = 1;
  1579. }
  1580. else if(strcmp(status,"UploadFailed")==0)
  1581. {
  1582. DiagnosticsStatusNotificationStatus = 2;
  1583. }
  1584. else if(strcmp(status,"Uploading")==0)
  1585. {
  1586. DiagnosticsStatusNotificationStatus = 3;
  1587. }
  1588. return result;
  1589. }
  1590. int sendFirmwareStatusNotificationRequest(char *status)
  1591. {
  1592. mtrace();
  1593. int result = FAIL;
  1594. char message[110]={0};
  1595. char guid[37]={0};
  1596. char tempdata[65]={0};
  1597. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1598. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1599. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1600. random_uuid(guid);
  1601. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1602. LWS_Send(message);
  1603. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1604. 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*/)
  1605. {
  1606. result = PASS;
  1607. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1608. }
  1609. //#ifdef SystemLogMessage
  1610. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1611. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1612. //#endif
  1613. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1615. //record status
  1616. if(strcmp(status,"Downloaded")==0)
  1617. {
  1618. FirmwareStatusNotificationStatus = 0;
  1619. }
  1620. else if(strcmp(status,"DownloadFailed")==0)
  1621. {
  1622. FirmwareStatusNotificationStatus = 1;
  1623. }
  1624. else if(strcmp(status,"Downloading")==0)
  1625. {
  1626. FirmwareStatusNotificationStatus = 2;
  1627. }
  1628. else if(strcmp(status,"Idle")==0)
  1629. {
  1630. FirmwareStatusNotificationStatus = 3;
  1631. }
  1632. else if(strcmp(status,"InstallationFailed")==0)
  1633. {
  1634. FirmwareStatusNotificationStatus = 4;
  1635. }
  1636. else if(strcmp(status,"Installing")==0)
  1637. {
  1638. FirmwareStatusNotificationStatus = 5;
  1639. }
  1640. else if(strcmp(status,"Installed")==0)
  1641. {
  1642. FirmwareStatusNotificationStatus = 6;
  1643. }
  1644. return result;
  1645. }
  1646. int sendHeartbeatRequest(int gun_index)
  1647. {
  1648. mtrace();
  1649. int result = FAIL;
  1650. char message[80]={0};
  1651. char guid[37]={0};
  1652. char tempdata[65]={0};
  1653. random_uuid(guid);
  1654. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1655. , MESSAGE_TYPE_CALL
  1656. , guid );
  1657. LWS_Send(message);
  1658. sprintf(tempdata, "Heartbeat,%d", 0);
  1659. 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*/)
  1660. {
  1661. result = PASS;
  1662. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1663. }
  1664. return result;
  1665. }
  1666. int sendStartTransactionRequest(int gun_index)
  1667. {
  1668. mtrace();
  1669. int result = FAIL;
  1670. char message[250]={0};
  1671. char guid[37]={0};
  1672. struct timeval tmnow;
  1673. struct tm *tm;
  1674. char buf[28];//, usec_buf[6];
  1675. char tempdata[65]={0};
  1676. DEBUG_INFO("sendStartTransactionRequest...");
  1677. gettimeofday(&tmnow, NULL);
  1678. time_t t;
  1679. t = time(NULL);
  1680. /*UTC time and date*/
  1681. tm = gmtime(&t);
  1682. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1683. #if 0 // remove temporally
  1684. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1685. strcat(buf,".");
  1686. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1687. strcat(buf,usec_buf);
  1688. #endif
  1689. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1690. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1691. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1692. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1693. {
  1694. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1695. {
  1696. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1697. {
  1698. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1699. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1700. }
  1701. }
  1702. for (int index = 0; index < CCS_QUANTITY; index++)
  1703. {
  1704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1705. {
  1706. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1707. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1708. }
  1709. }
  1710. for (int index = 0; index < GB_QUANTITY; index++)
  1711. {
  1712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1713. {
  1714. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1715. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1716. }
  1717. }
  1718. }
  1719. else
  1720. {
  1721. for (int index = 0; index < AC_QUANTITY; index++)
  1722. {
  1723. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1724. {
  1725. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  1726. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1727. }
  1728. }
  1729. }//END OF ELSE
  1730. random_uuid(guid);
  1731. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1732. , MESSAGE_TYPE_CALL
  1733. , guid
  1734. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1735. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1736. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1737. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1738. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1739. LWS_Send(message);
  1740. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1741. 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*/)
  1742. {
  1743. result = PASS;
  1744. }
  1745. strcpy(queuedata, message);
  1746. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1747. //#ifdef SystemLogMessage
  1748. //DEBUG_INFO(">>>>>StartTransaction request\n");
  1749. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1750. //#endif
  1751. return result;
  1752. }
  1753. int sendStatusNotificationRequest(int gun_index)
  1754. {
  1755. mtrace();
  1756. int result = FAIL;
  1757. char message[600]={0};
  1758. char guid[37];
  1759. int currentStatus = 0;
  1760. struct timeval tmnow;
  1761. struct tm *tm;
  1762. char buf[28];//, usec_buf[6];
  1763. char tempdata[65]={0};
  1764. gettimeofday(&tmnow, NULL);
  1765. time_t t;
  1766. t = time(NULL);
  1767. /*UTC time and date*/
  1768. tm = gmtime(&t);
  1769. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1770. #if 0 // remove temporally
  1771. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1772. strcat(buf,".");
  1773. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1774. strcat(buf,usec_buf);
  1775. #endif
  1776. printf("%s",buf);
  1777. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1778. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1779. // it's option
  1780. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1781. /*
  1782. enum _SYSTEM_STATUS
  1783. {
  1784. S_BOOTING = 0,
  1785. S_IDLE, = 1
  1786. S_AUTHORIZING, =2
  1787. S_REASSIGN_CHECK, =3
  1788. S_REASSIGN, =4
  1789. S_PRECHARGE, =5
  1790. S_PREPARING_FOR_EV, =6
  1791. S_PREPARING_FOR_EVSE, =7
  1792. S_CHARGING, =8
  1793. S_TERMINATING, =9
  1794. S_COMPLETE, =10
  1795. S_ALARM, =11
  1796. S_FAULT =12
  1797. }
  1798. */
  1799. //check Transaction active
  1800. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1801. {
  1802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1803. {
  1804. //printf("gun_index=%d\n",gun_index);
  1805. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1806. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1807. {
  1808. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1809. currentStatus = 0; //OCPP Status
  1810. }
  1811. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1812. {
  1813. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1814. currentStatus = 1; //OCPP Status
  1815. }
  1816. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1817. {
  1818. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1819. currentStatus = 2; //OCPP Status
  1820. }
  1821. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1822. {
  1823. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1824. currentStatus = 5; //OCPP Status
  1825. }
  1826. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1827. {
  1828. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1829. currentStatus = 4; //OCPP Status
  1830. }
  1831. 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
  1832. {
  1833. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1834. currentStatus = 7; //OCPP Status: Unavailable
  1835. }
  1836. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1837. {
  1838. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1839. currentStatus = 8; //OCPP Status: Faulted
  1840. }
  1841. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1842. {
  1843. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1844. currentStatus = 6; //OCPP Status: Reserved
  1845. }
  1846. }//end of for CHAdeMO_QUANTITY
  1847. for (int index = 0; index < CCS_QUANTITY; index++)
  1848. {
  1849. //printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.CcsChargingData[0].SystemStatus);
  1850. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1851. {
  1852. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1853. currentStatus = 0; //OCPP Status
  1854. }
  1855. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1856. {
  1857. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1858. currentStatus = 1; //OCPP Status
  1859. }
  1860. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1861. {
  1862. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1863. currentStatus = 2; //OCPP Status
  1864. }
  1865. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1866. {
  1867. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1868. currentStatus = 5; //OCPP Status
  1869. }
  1870. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1871. {
  1872. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1873. currentStatus = 4; //OCPP Status
  1874. }
  1875. 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
  1876. {
  1877. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[Unavailable]);
  1878. currentStatus = 7; //OCPP Status : Unavailable
  1879. }
  1880. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1881. {
  1882. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1883. currentStatus = 8; //OCPP Status
  1884. }
  1885. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1886. {
  1887. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1888. currentStatus = 6; //OCPP Status
  1889. }
  1890. }
  1891. for (int index = 0; index < GB_QUANTITY; index++)
  1892. {
  1893. //printf("ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.GbChargingData[0].SystemStatus);
  1894. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1895. {
  1896. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1897. currentStatus = 0; //OCPP Status
  1898. }
  1899. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) &&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1900. {
  1901. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1902. currentStatus = 1; //OCPP Status
  1903. }
  1904. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1905. {
  1906. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1907. currentStatus = 2; //OCPP Status
  1908. }
  1909. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1910. {
  1911. // strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1912. currentStatus = 5; //OCPP Status
  1913. }
  1914. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1915. {
  1916. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1917. currentStatus = 4; //OCPP Status
  1918. }
  1919. 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
  1920. {
  1921. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1922. currentStatus = 7; //OCPP Status: Unavailable
  1923. }
  1924. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1925. {
  1926. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1927. currentStatus = 8; //OCPP Status: Faulted
  1928. }
  1929. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1930. {
  1931. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1932. currentStatus = 6; //OCPP Status: Faulted
  1933. }
  1934. }
  1935. }
  1936. else
  1937. {
  1938. for (int index = 0; index < AC_QUANTITY; index++)
  1939. {
  1940. //printf("gun_index=%d\n",gun_index);
  1941. //printf("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus=%d\n",ShmSysConfigAndInfo->SysInfo.ChademoChargingData[0].SystemStatus);
  1942. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) //S_IDLE
  1943. {
  1944. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Available");
  1945. currentStatus = 0; //OCPP Status
  1946. }
  1947. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //S_PRECHARGE
  1948. {
  1949. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Preparing");
  1950. currentStatus = 1; //OCPP Status
  1951. }
  1952. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)) //S_CHARGING
  1953. {
  1954. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging");
  1955. currentStatus = 2; //OCPP Status
  1956. }
  1957. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) //S_COMPLETE
  1958. {
  1959. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, "Finishing");
  1960. currentStatus = 5; //OCPP Status
  1961. }
  1962. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ---> SuspendedEV
  1963. {
  1964. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1965. currentStatus = 4; //OCPP Status
  1966. }
  1967. 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
  1968. {
  1969. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1970. currentStatus = 7; //OCPP Status: Unavailable
  1971. }
  1972. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT ---> Faulted
  1973. {
  1974. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1975. currentStatus = 8; //OCPP Status: Faulted
  1976. }
  1977. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // ---> Reserved
  1978. {
  1979. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[SuspendedEV]);
  1980. currentStatus = 6; //OCPP Status: Reserved
  1981. }
  1982. }//end of for AC_QUANTITY
  1983. }//END OF ELSE
  1984. //it's option
  1985. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  1986. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  1987. //strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode, "000000");
  1988. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  1989. random_uuid(guid);
  1990. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  1991. , MESSAGE_TYPE_CALL
  1992. , guid
  1993. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  1994. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  1995. , ShmOCPP16Data->StatusNotification[gun_index].Info
  1996. , ShmOCPP16Data->StatusNotification[gun_index].Status
  1997. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  1998. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  1999. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2000. LWS_Send(message);
  2001. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2002. 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*/)
  2003. {
  2004. //DEBUG_ERROR("statusNotification mapitem pass");
  2005. result = PASS;
  2006. }
  2007. //#ifdef SystemLogMessage
  2008. //DEBUG_INFO(">>>>>StatusNotification request\n");
  2009. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2010. //#endif
  2011. return result;
  2012. }
  2013. int sendStopTransactionRequest(int gun_index)
  2014. {
  2015. mtrace();
  2016. int result = FAIL;
  2017. //char message[1500]={0};
  2018. char guid[37]={0};
  2019. char tempdata[65]={0};
  2020. //int idx_sample=0;
  2021. DEBUG_ERROR("sendStopTransactionRequest \n");
  2022. memset(queuedata, 0, sizeof(queuedata));
  2023. //ENERGY_ACTIVE_IMPORT_REGISTER
  2024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2025. {
  2026. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2027. {
  2028. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2029. {
  2030. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2031. //Check Status
  2032. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2033. {
  2034. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2035. }
  2036. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2037. }
  2038. }// END OF CHAdeMO_QUANTITY
  2039. for (int index = 0; index < CCS_QUANTITY; index++)
  2040. {
  2041. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2042. {
  2043. //for test
  2044. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2045. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2046. //Check Status
  2047. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2048. {
  2049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2050. }
  2051. else
  2052. {
  2053. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2054. }
  2055. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2056. }
  2057. }// END OF CCS_QUANTITY
  2058. for (int index = 0; index < GB_QUANTITY; index++)
  2059. {
  2060. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2061. {
  2062. // for test
  2063. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy = 100.0;
  2064. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2065. //Check Status
  2066. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2067. {
  2068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2069. }
  2070. else
  2071. {
  2072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[Local]); //
  2073. }
  2074. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2075. }
  2076. }// END OF GB_QUANTITY
  2077. }
  2078. else
  2079. {
  2080. for (int index = 0; index < AC_QUANTITY; index++)
  2081. {
  2082. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2083. {
  2084. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  2085. //Check Status
  2086. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) // S_ALARM (Temporally for SuspendedEV )
  2087. {
  2088. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].StopReason, StopTransactionReasonStr[EVDisconnected]); //
  2089. }
  2090. //sprintf(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idx_transaction].SampledValue[idx_sample].Value, "%s" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2091. }
  2092. }// END OF AC_QUANTITY
  2093. }//END OF ELSE
  2094. //Stop Transaction Time
  2095. struct timeval tmnow;
  2096. struct tm *tm;
  2097. char buf[28];//, usec_buf[6];
  2098. gettimeofday(&tmnow, NULL);
  2099. time_t t;
  2100. t = time(NULL);
  2101. /*UTC time and date*/
  2102. tm = gmtime(&t);
  2103. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2104. //strcpy(ShmOCPP16Data->StopTransaction[gun_index].Timestamp,"2019-05-04T18:15:33Z");
  2105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2106. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2107. random_uuid(guid);
  2108. /***********************************transactionData******************************************************/
  2109. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2110. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData = (struct StructMeterValue *)malloc(sizeof(struct StructMeterValue));
  2111. //ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue = (struct StructSampledValue *)malloc(sizeof(struct StructSampledValue)*10);
  2112. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2113. //=================================
  2114. // Transaction_Begin
  2115. //=================================
  2116. // Energy.Active.Export.Interval
  2117. //idx_sample=0;
  2118. 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
  2119. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2120. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2121. 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*/]);
  2122. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2123. {
  2124. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2125. }
  2126. else
  2127. {
  2128. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2129. }
  2130. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2131. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2132. //=================================
  2133. // Transaction_End
  2134. //=================================
  2135. //Current.Export
  2136. //idx_sample=1;
  2137. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2138. {
  2139. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2140. {
  2141. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2142. {
  2143. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2144. }
  2145. }
  2146. for (int index = 0; index < CCS_QUANTITY; index++)
  2147. {
  2148. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2149. {
  2150. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2151. }
  2152. }
  2153. for (int index = 0; index < GB_QUANTITY; index++)
  2154. {
  2155. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2156. {
  2157. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2158. }
  2159. }
  2160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2161. }
  2162. else
  2163. {
  2164. for (int index = 0; index < AC_QUANTITY; index++)
  2165. {
  2166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2167. {
  2168. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2169. }
  2170. }
  2171. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2172. }// END FOR AC ELSE
  2173. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2175. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Export]);
  2176. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2177. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2179. //Energy.Active.Export.Interval
  2180. //idx_sample=2;
  2181. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2182. {
  2183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2184. {
  2185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2186. {
  2187. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2188. }
  2189. }
  2190. for (int index = 0; index < CCS_QUANTITY; index++)
  2191. {
  2192. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2193. {
  2194. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2195. }
  2196. }
  2197. for (int index = 0; index < GB_QUANTITY; index++)
  2198. {
  2199. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2200. {
  2201. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2202. }
  2203. }
  2204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2205. }
  2206. else
  2207. {
  2208. for (int index = 0; index < AC_QUANTITY; index++)
  2209. {
  2210. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2211. {
  2212. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*1000 );// PresentChargedEnergy is 0~6553.5 kWh
  2213. }
  2214. }
  2215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2216. }// END FOR AC ELSE
  2217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2218. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2219. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2220. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_Wh/*UnitOfMeasure_kWh*/]);
  2223. //Power.Active.Export
  2224. //idx_sample=3;
  2225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2226. {
  2227. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2228. {
  2229. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2230. {
  2231. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2232. }
  2233. }
  2234. for (int index = 0; index < CCS_QUANTITY; index++)
  2235. {
  2236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2237. {
  2238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2239. }
  2240. }
  2241. for (int index = 0; index < GB_QUANTITY; index++)
  2242. {
  2243. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2244. {
  2245. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2246. }
  2247. }
  2248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2249. }
  2250. else
  2251. {
  2252. for (int index = 0; index < AC_QUANTITY; index++)
  2253. {
  2254. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2255. {
  2256. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2257. }
  2258. }
  2259. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2260. }// END FOR AC ELSE
  2261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2263. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Export/*Energy_Reactive_Export_Register*/]);
  2264. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2265. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2267. //Voltage
  2268. //idx_sample=4;
  2269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2270. {
  2271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2272. {
  2273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2274. {
  2275. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2276. }
  2277. }
  2278. for (int index = 0; index < CCS_QUANTITY; index++)
  2279. {
  2280. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2281. {
  2282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2283. }
  2284. }
  2285. for (int index = 0; index < GB_QUANTITY; index++)
  2286. {
  2287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2288. {
  2289. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2290. }
  2291. }
  2292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2293. }
  2294. else
  2295. {
  2296. for (int index = 0; index < AC_QUANTITY; index++)
  2297. {
  2298. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2299. {
  2300. 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
  2301. }
  2302. }
  2303. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2304. }// END FOR AC ELSE
  2305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2306. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2308. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2310. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2311. //SoC
  2312. //idx_sample=5;
  2313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2314. {
  2315. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2316. {
  2317. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2318. {
  2319. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2320. }
  2321. }
  2322. for (int index = 0; index < CCS_QUANTITY; index++)
  2323. {
  2324. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2325. {
  2326. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2327. }
  2328. }
  2329. for (int index = 0; index < GB_QUANTITY; index++)
  2330. {
  2331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2332. {
  2333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2334. }
  2335. }
  2336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2339. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2342. } // END FOR DC CASE
  2343. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2344. {
  2345. 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\" } ] } ] } ]"
  2346. ,MESSAGE_TYPE_CALL
  2347. ,guid
  2348. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2349. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2350. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2351. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2352. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2353. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2354. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2355. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2356. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2357. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2358. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2359. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2360. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2361. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2362. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2363. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2364. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2365. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2366. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2367. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2368. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2369. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2370. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2371. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2372. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2373. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2374. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2375. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2376. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2377. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2378. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2379. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2380. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2381. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2382. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2383. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2384. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2385. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2386. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2387. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2388. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2389. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2391. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2392. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2396. );
  2397. }
  2398. else
  2399. {
  2400. 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\" } ] } ] } ]"
  2401. ,MESSAGE_TYPE_CALL
  2402. ,guid
  2403. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2404. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2405. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2407. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2408. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2435. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2436. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2437. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2438. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2439. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2440. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2441. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2442. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2443. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2444. );
  2445. }
  2446. LWS_Send(queuedata);
  2447. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2448. if(hashmap_operation(0, guid, tempdata) == 1)
  2449. {
  2450. result = PASS;
  2451. DEBUG_INFO("StopTransaction mapitem pass\n");
  2452. }
  2453. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2454. //for test
  2455. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2456. return result;
  2457. }
  2458. int sendMeterValuesRequest(int gun_index)
  2459. {
  2460. mtrace();
  2461. int result = FAIL;
  2462. // char message[1500]={0};
  2463. char guid[37]={0};
  2464. //int idx_sample=0;
  2465. //int length = 0;
  2466. char tempdata[65]={0};
  2467. DEBUG_ERROR("sendMeterValuesRequest ...\n");
  2468. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2469. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2470. {
  2471. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2472. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2473. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2474. return result;
  2475. }
  2476. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2477. {
  2478. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2479. }
  2480. memset(queuedata, 0, sizeof(queuedata));
  2481. //set value
  2482. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2483. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2484. random_uuid(guid);
  2485. //UTC Date time
  2486. struct timeval tmnow;
  2487. struct tm *tm;
  2488. char buf[28];//, usec_buf[6];
  2489. gettimeofday(&tmnow, NULL);
  2490. time_t t;
  2491. t = time(NULL);
  2492. /*UTC time and date*/
  2493. tm = gmtime(&t);
  2494. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2495. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2496. //idx_sample=0;
  2497. //********************************(1)Current.Export************************************************/
  2498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2499. {
  2500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2501. {
  2502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2503. {
  2504. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2505. }
  2506. }
  2507. for (int index = 0; index < CCS_QUANTITY; index++)
  2508. {
  2509. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2510. {
  2511. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2512. }
  2513. }
  2514. for (int index = 0; index < GB_QUANTITY; index++)
  2515. {
  2516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2517. {
  2518. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2519. }
  2520. }
  2521. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2522. }
  2523. else
  2524. {
  2525. for (int index = 0; index < AC_QUANTITY; index++)
  2526. {
  2527. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2528. {
  2529. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2530. }
  2531. }
  2532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2533. }// END FOR AC ELSE
  2534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Export]);
  2537. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2538. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2540. //idx_sample=1;
  2541. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2543. {
  2544. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2545. {
  2546. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2547. {
  2548. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2549. }
  2550. }
  2551. for (int index = 0; index < CCS_QUANTITY; index++)
  2552. {
  2553. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2555. {
  2556. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2558. }
  2559. }
  2560. for (int index = 0; index < GB_QUANTITY; index++)
  2561. {
  2562. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2563. {
  2564. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2565. }
  2566. }
  2567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2568. }
  2569. else
  2570. {
  2571. for (int index = 0; index < AC_QUANTITY; index++)
  2572. {
  2573. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2574. {
  2575. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2576. }
  2577. }
  2578. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2579. }//END FOR AC ELSE
  2580. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2581. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2582. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Export_Interval]);
  2583. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2584. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2586. //idx_sample=2;
  2587. //********************************(4)Power.Active.Export************************************************/
  2588. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2589. {
  2590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2591. {
  2592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2593. {
  2594. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2595. }
  2596. }
  2597. for (int index = 0; index < CCS_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  2602. }
  2603. }
  2604. for (int index = 0; index < GB_QUANTITY; index++)
  2605. {
  2606. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2607. {
  2608. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  2609. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  2610. }
  2611. }
  2612. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2613. }
  2614. else
  2615. {
  2616. for (int index = 0; index < AC_QUANTITY; index++)
  2617. {
  2618. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2619. {
  2620. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  2621. }
  2622. }
  2623. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2624. }// END FOR AC ELSE
  2625. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2626. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  2627. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Export]);
  2628. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  2629. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  2630. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  2631. //idx_sample=3;
  2632. //***********************************************(5)VOLTAGE******************************************************/
  2633. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2634. {
  2635. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2636. {
  2637. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2638. {
  2639. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  2640. }
  2641. }
  2642. for (int index = 0; index < CCS_QUANTITY; index++)
  2643. {
  2644. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2645. {
  2646. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  2647. }
  2648. }
  2649. for (int index = 0; index < GB_QUANTITY; index++)
  2650. {
  2651. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2652. {
  2653. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  2654. }
  2655. }
  2656. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  2657. }
  2658. else
  2659. {
  2660. for (int index = 0; index < AC_QUANTITY; index++)
  2661. {
  2662. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2663. {
  2664. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  2665. }
  2666. }
  2667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2668. }//END FOR AC ELSE
  2669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2670. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  2671. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  2672. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  2673. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  2674. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2675. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2676. {
  2677. //idx_sample=4;
  2678. //sampledValue = NULL;
  2679. //***********************************************(6)SOC******************************************************/
  2680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2683. {
  2684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  2685. }
  2686. }
  2687. for (int index = 0; index < CCS_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2690. {
  2691. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  2692. }
  2693. }
  2694. for (int index = 0; index < GB_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2697. {
  2698. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  2699. }
  2700. }
  2701. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  2703. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  2704. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  2705. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  2706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  2707. }
  2708. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2709. {
  2710. 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\"}]}]}]"
  2711. ,MESSAGE_TYPE_CALL
  2712. ,guid
  2713. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2714. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2715. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2722. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2723. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2724. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2725. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2726. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2727. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2728. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2729. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2730. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2731. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2732. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2733. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2734. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  2745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  2746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  2747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  2748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  2749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  2750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  2751. );
  2752. }
  2753. else
  2754. {
  2755. 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\"}]}]}]"
  2756. ,MESSAGE_TYPE_CALL
  2757. ,guid
  2758. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  2759. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  2760. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  2761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  2762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  2763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  2764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  2765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  2766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  2767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  2768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  2769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  2770. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  2771. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  2772. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  2773. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  2774. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  2775. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  2776. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  2777. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  2778. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  2779. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  2780. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  2781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  2782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  2783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  2784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  2785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  2786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  2787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  2788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  2789. );
  2790. }
  2791. LWS_Send(queuedata);
  2792. // Put request guid to hash map
  2793. sprintf(tempdata, "MeterValues,%d", (gun_index));
  2794. 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*/)
  2795. {
  2796. result = PASS;
  2797. DEBUG_INFO("MeterValues mapitem pass\n");
  2798. }
  2799. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2800. return result;
  2801. }
  2802. //==========================================
  2803. // send confirm routine
  2804. //==========================================
  2805. int sendCancelReservationConfirmation(char *uuid,char *payload)
  2806. {
  2807. mtrace();
  2808. int result = FAIL;
  2809. char message[100]={0};
  2810. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  2811. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2812. LWS_Send(message);
  2813. result = TRUE;
  2814. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  2815. return result;
  2816. }
  2817. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[100]={0};
  2822. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  2823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2824. LWS_Send(message);
  2825. result = TRUE;
  2826. return result;
  2827. }
  2828. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  2829. {
  2830. mtrace();
  2831. int result = FAIL;
  2832. char message[100]={0};
  2833. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  2834. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  2835. LWS_Send(message);
  2836. result = TRUE;
  2837. return result;
  2838. }
  2839. int sendClearCacheConfirmation(char *uuid,char *payload)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[500]={0};
  2844. // int count = 0;
  2845. // int gun_index = 0;
  2846. // char guid[37];
  2847. // [ 3, "1570592744204", { "status": "Accepted" } ]
  2848. DEBUG_ERROR("sendClearCacheConfirmation\n");
  2849. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2850. LWS_Send(message);
  2851. return result;
  2852. }
  2853. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  2854. {
  2855. mtrace();
  2856. int result = FAIL;
  2857. char message[500]={0};
  2858. // [ 3, "1571284268200", { "status": "Unknown" } ]
  2859. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  2860. sprintf(message,"[ %d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  2861. LWS_Send(message);
  2862. return result;
  2863. }
  2864. int sendDataTransferConfirmation(char *uuid,char *payload)
  2865. {
  2866. mtrace();
  2867. char statusStr[20]={0};
  2868. char dataStr[10]={0};
  2869. char sstr[20]={0};
  2870. int c = 0;
  2871. char *loc;
  2872. int result = FAIL;
  2873. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  2874. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  2875. /**********************status**************************/
  2876. loc = strstr(payload, "status");
  2877. memset(sstr ,0, sizeof(sstr) );
  2878. c = 0;
  2879. while (loc[3+strlen("status")+c] != '\"')
  2880. {
  2881. sstr[c] = loc[3+strlen("status")+c];
  2882. c++;
  2883. }
  2884. sstr[c] = '\0';
  2885. strcpy(statusStr, sstr);
  2886. /**********************data**************************/
  2887. loc = strstr(payload, "data");
  2888. memset(sstr ,0, sizeof(sstr) );
  2889. c = 0;
  2890. while (loc[3+strlen("data")+c] != '\"')
  2891. {
  2892. sstr[c] = loc[3+strlen("data")+c];
  2893. c++;
  2894. }
  2895. sstr[c] = '\0';
  2896. strcpy(dataStr, sstr);
  2897. return result;
  2898. }
  2899. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  2900. {
  2901. mtrace();
  2902. int result = FAIL;
  2903. char message[1000]={0};
  2904. double diff_f = 0.0;
  2905. int diff_i = 0;
  2906. int diffSeconds = 0;
  2907. struct tm tp;
  2908. int TimeZero = FALSE;
  2909. int CompositeScheduleIndex = 0;
  2910. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  2911. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  2912. {
  2913. TimeZero = TRUE;
  2914. }
  2915. else
  2916. {
  2917. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  2918. }
  2919. if(TimeZero == FALSE)
  2920. {
  2921. tp.tm_isdst = -1;
  2922. time_t utc = mktime(&tp);
  2923. time_t t = time(NULL);
  2924. diff_f = difftime(t, utc);
  2925. diff_i = (int)diff_f;
  2926. diffSeconds = diff_i % 86400;//86400 seconds/day
  2927. }
  2928. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  2929. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  2930. #if 0 //remove temporally
  2931. 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}"
  2932. ,MESSAGE_TYPE_CALLRESULT
  2933. ,uuid
  2934. ,payload
  2935. ,connectorIdInt
  2936. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2937. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  2938. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  2939. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  2940. #endif
  2941. if(nPeriod == 0)
  2942. {
  2943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  2944. ,MESSAGE_TYPE_CALLRESULT
  2945. ,uuid
  2946. ,payload
  2947. ,connectorIdInt
  2948. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  2949. }
  2950. else
  2951. {
  2952. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  2953. ,MESSAGE_TYPE_CALLRESULT
  2954. ,uuid
  2955. ,payload
  2956. ,connectorIdInt
  2957. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2958. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  2959. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  2960. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  2961. int len = nPeriod;
  2962. //Last Period StartPriod is less than diffSeconds
  2963. if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod < diffSeconds)
  2964. {
  2965. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2966. , 0
  2967. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  2968. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  2969. }
  2970. else
  2971. {
  2972. for(int idx_sample=0;idx_sample< len;idx_sample++)
  2973. {
  2974. if((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod < diffSeconds) && (ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod > diffSeconds))//if (idx_sample == 0)
  2975. {
  2976. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2977. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  2978. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2979. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2980. }
  2981. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  2982. {
  2983. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  2984. , (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*/))
  2985. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  2986. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  2987. }
  2988. }
  2989. }
  2990. sprintf(message + strlen(message), "]}}]");
  2991. }
  2992. LWS_Send(message);
  2993. result = TRUE;
  2994. return result;
  2995. }
  2996. int sendGetConfigurationConfirmation(char *uuid)
  2997. {
  2998. mtrace();
  2999. int result = FAIL;
  3000. int MaxKeySupported = 0;
  3001. int sentConfigurationNumber= 0;
  3002. int sentunConfigurationNumber= 0;
  3003. char message[4000]={0};
  3004. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3005. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3006. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3007. sprintf(message,"[%d,\"%s\",{\"configurationKey\":[ "
  3008. ,MESSAGE_TYPE_CALLRESULT
  3009. ,uuid );
  3010. //configuration key
  3011. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3012. {
  3013. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3014. {
  3015. if (sentConfigurationNumber == 0)
  3016. {
  3017. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}"
  3018. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3019. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3020. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3021. }
  3022. else
  3023. {
  3024. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3025. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3026. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3027. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3028. }
  3029. sentConfigurationNumber = sentConfigurationNumber + 1;
  3030. }
  3031. }
  3032. sprintf(message + strlen(message), "]");
  3033. if(UnknownKeynum != 0)
  3034. {
  3035. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3036. //unkown key
  3037. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3038. {
  3039. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3040. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3041. if(sentunConfigurationNumber == 0)
  3042. {
  3043. sprintf(message + strlen(message), "\"%s\""
  3044. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3045. }
  3046. else
  3047. {
  3048. sprintf(message + strlen(message), ",\"%s\""
  3049. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3050. }
  3051. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3052. }
  3053. sprintf(message + strlen(message), "]");
  3054. }
  3055. sprintf(message + strlen(message), "} ]");
  3056. LWS_Send(message);
  3057. return result;
  3058. }
  3059. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3060. {
  3061. mtrace();
  3062. int result = FAIL;
  3063. char message[400]={0};
  3064. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3065. if(strcmp(payload,"")==0)
  3066. {
  3067. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3068. }
  3069. else
  3070. {
  3071. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3072. }
  3073. LWS_Send(message);
  3074. result = TRUE;
  3075. return result;
  3076. }
  3077. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3078. {
  3079. mtrace();
  3080. int result = FAIL;
  3081. char message[80]={0};
  3082. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3083. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3084. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3085. LWS_Send(message);
  3086. result = TRUE;
  3087. return result;
  3088. }
  3089. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3090. {
  3091. mtrace();
  3092. int result = FAIL;
  3093. char message[80]={0};
  3094. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3095. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3096. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3097. LWS_Send(message);
  3098. result = TRUE;
  3099. return result;
  3100. }
  3101. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3102. {
  3103. mtrace();
  3104. int result = FAIL;
  3105. char message[80]={0};
  3106. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3107. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3108. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3109. LWS_Send(message);
  3110. result = TRUE;
  3111. return result;
  3112. }
  3113. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3114. {
  3115. mtrace();
  3116. int result = FAIL;
  3117. char message[80]={0};
  3118. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3119. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3120. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3121. LWS_Send(message);
  3122. result = TRUE;
  3123. return result;
  3124. }
  3125. int sendResetConfirmation(char *uuid,char *payload)
  3126. {
  3127. mtrace();
  3128. int result = FAIL;
  3129. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3130. char message[80]={0};
  3131. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3132. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3133. LWS_Send(message);
  3134. result = TRUE;
  3135. return result;
  3136. }
  3137. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3138. {
  3139. mtrace();
  3140. int result = FAIL;
  3141. char message[500]={0};
  3142. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3143. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3144. LWS_Send(message);
  3145. result = TRUE;
  3146. return result;
  3147. }
  3148. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3149. {
  3150. mtrace();
  3151. int result = FAIL;
  3152. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3153. char message[80]={0};
  3154. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3155. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3156. LWS_Send(message);
  3157. result = TRUE;
  3158. return result;
  3159. }
  3160. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3161. {
  3162. mtrace();
  3163. int result = FAIL;
  3164. char message[80]={0};
  3165. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3166. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3167. LWS_Send(message);
  3168. result = TRUE;
  3169. return result;
  3170. }
  3171. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3172. {
  3173. mtrace();
  3174. int result = FAIL;
  3175. char message[80]={0};
  3176. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3177. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3178. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3179. LWS_Send(message);
  3180. result = TRUE;
  3181. return result;
  3182. }
  3183. int sendUpdateFirmwareConfirmation(char *uuid)
  3184. {
  3185. mtrace();
  3186. int result = FAIL;
  3187. char message[60]={0};
  3188. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3189. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3190. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3191. LWS_Send(message);
  3192. result = TRUE;
  3193. return result;
  3194. }
  3195. //==========================================
  3196. // send CallError routine
  3197. //==========================================
  3198. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3199. {
  3200. mtrace();
  3201. //int result = FAIL;
  3202. char message[220]={0};
  3203. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3204. #ifdef SystemLogMessage
  3205. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3206. uniqueId, action, errorCode, errorDescription);
  3207. #endif
  3208. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3209. LWS_Send(message);
  3210. //result = TRUE;
  3211. }
  3212. //==========================================
  3213. // Handle server request routine Start
  3214. //==========================================
  3215. #define GUN_NUM 1
  3216. int handleCancelReservationRequest(char *uuid, char *payload)
  3217. {
  3218. mtrace();
  3219. int result = FAIL;
  3220. int gunNO = 0;
  3221. int reservationIdInt =0;
  3222. char comfirmstr[20];
  3223. int c = 0;
  3224. char *loc;
  3225. char sstr[100]={0};
  3226. DEBUG_INFO("handle CancelReservationRequest\n");
  3227. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3228. c = 0;
  3229. loc = strstr(payload, "reservationId");
  3230. memset(sstr ,0, sizeof(sstr) );
  3231. while (loc[strlen("reservationId")+2+c] != '}')
  3232. {
  3233. sstr[c] = loc[strlen("reservationId")+2+c];
  3234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3235. c++;
  3236. }
  3237. sstr[c] = '\0';
  3238. reservationIdInt = atoi(sstr);
  3239. memset(comfirmstr, 0, sizeof comfirmstr);
  3240. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3241. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3242. //check Transaction active
  3243. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3244. {
  3245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3246. {
  3247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3248. {
  3249. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3250. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3251. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3252. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3253. goto end;
  3254. }
  3255. }
  3256. for (int index = 0; index < CCS_QUANTITY; index++)
  3257. {
  3258. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3259. {
  3260. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3261. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3262. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3263. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3264. goto end;
  3265. }
  3266. }
  3267. for (int index = 0; index < GB_QUANTITY; index++)
  3268. {
  3269. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3270. {
  3271. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3272. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3273. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3274. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3275. goto end;
  3276. }
  3277. }
  3278. }
  3279. else
  3280. {
  3281. for (int index = 0; index < AC_QUANTITY; index++)
  3282. {
  3283. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3284. {
  3285. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3286. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3287. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3288. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3289. goto end;
  3290. }
  3291. }
  3292. }// END FOR AC ELSE
  3293. //The reservationId does NOT match the reservationId
  3294. sendCancelReservationConfirmation(uuid, comfirmstr);
  3295. end:
  3296. // Fill in ocpp packet uuid
  3297. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3298. return result;
  3299. }
  3300. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3301. {
  3302. mtrace();
  3303. int result = FAIL;
  3304. int gunIndex = 0;
  3305. char sstr[90]={0};
  3306. char typeStr[16]={0};
  3307. char comfirmstr[20];
  3308. int specificId = FALSE;
  3309. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3310. char *loc;
  3311. //int intervalInt = 0;
  3312. int c = 0;
  3313. /*** connectorId ****/
  3314. c = 0;
  3315. loc = strstr(payload, "connectorId");
  3316. memset(sstr ,0, sizeof(sstr) );
  3317. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') )
  3318. {
  3319. sstr[c] = loc[strlen("connectorId")+2+c];
  3320. c++;
  3321. }
  3322. sstr[c] = '\0';
  3323. gunIndex = atoi(sstr);
  3324. /***type ****/
  3325. loc = strstr(payload, "type");
  3326. memset(sstr ,0, sizeof(sstr) );
  3327. c = 0;
  3328. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3329. {
  3330. sstr[c] = loc[3+strlen("type")+c];
  3331. c++;
  3332. }
  3333. sstr[c] = '\0';
  3334. strcpy(typeStr, sstr);
  3335. if(gunIndex != 0)
  3336. {
  3337. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3338. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3339. }
  3340. else
  3341. {
  3342. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3343. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3344. }
  3345. memset(comfirmstr, 0, sizeof comfirmstr);
  3346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3347. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3348. {
  3349. specificId = TRUE;
  3350. }
  3351. if(specificId == FALSE)
  3352. goto end;
  3353. if(gunIndex != 0)
  3354. {
  3355. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3356. }
  3357. else
  3358. {
  3359. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3360. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3361. }
  3362. /*
  3363. enum _SYSTEM_STATUS
  3364. {
  3365. S_BOOTING = 0,
  3366. S_IDLE, = 1
  3367. S_AUTHORIZING, =2
  3368. S_REASSIGN_CHECK, =3
  3369. S_REASSIGN, =4
  3370. S_PRECHARGE, =5
  3371. S_PREPARING_FOR_EV, =6
  3372. S_PREPARING_FOR_EVSE, =7
  3373. S_CHARGING, =8
  3374. S_TERMINATING, =9
  3375. S_COMPLETE, =10
  3376. S_ALARM, =11
  3377. S_FAULT =12
  3378. }
  3379. */
  3380. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3381. {
  3382. //check Transaction active
  3383. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3384. {
  3385. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3386. {
  3387. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1)))
  3388. {
  3389. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3390. {
  3391. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3392. }
  3393. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3394. {
  3395. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3396. }
  3397. else
  3398. {
  3399. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3400. }
  3401. goto end;
  3402. }
  3403. }//END FOR CHAdeMO_QUANTITY
  3404. for (int index = 0; index < CCS_QUANTITY; index++)
  3405. {
  3406. if ((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))
  3407. {
  3408. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3409. {
  3410. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3411. }
  3412. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3413. {
  3414. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3415. }
  3416. else
  3417. {
  3418. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3419. }
  3420. goto end;
  3421. }
  3422. }//END FOR CCS_QUANTITY
  3423. for (int index = 0; index < GB_QUANTITY; index++)
  3424. {
  3425. if ((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))
  3426. {
  3427. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3428. {
  3429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3430. }
  3431. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3432. {
  3433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3434. }
  3435. else
  3436. {
  3437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3438. }
  3439. goto end;
  3440. }
  3441. }// END FOR GB_QUANTITY
  3442. }
  3443. else
  3444. {
  3445. for (int index = 0; index < AC_QUANTITY; index++)
  3446. {
  3447. if ((gunIndex == 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1)))
  3448. {
  3449. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3450. {
  3451. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3452. }
  3453. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3454. {
  3455. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3456. }
  3457. else
  3458. {
  3459. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3460. }
  3461. goto end;
  3462. }
  3463. }//END FOR AC_QUANTITY
  3464. }// END FOR AC ELSE
  3465. }//END FOR AvailabilityTypeStr[Inoperative]
  3466. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3467. {
  3468. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3469. //check Transaction active
  3470. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3471. {
  3472. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3473. {
  3474. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3475. {
  3476. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3477. goto end;
  3478. }
  3479. }//END FOR CHAdeMO_QUANTITY
  3480. for (int index = 0; index < CCS_QUANTITY; index++)
  3481. {
  3482. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3483. {
  3484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3485. goto end;
  3486. }
  3487. }//END FOR CCS_QUANTITY
  3488. for (int index = 0; index < GB_QUANTITY; index++)
  3489. {
  3490. if (((gunIndex == 0)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (gunIndex - 1)))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3491. {
  3492. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3494. goto end;
  3495. }
  3496. }// END FOR GB_QUANTITY
  3497. //sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3498. }
  3499. else
  3500. {
  3501. for (int index = 0; index < AC_QUANTITY; index++)
  3502. {
  3503. if (((gunIndex == 0)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (gunIndex - 1))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3504. {
  3505. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3506. goto end;
  3507. }
  3508. }//END FOR CHAdeMO_QUANTITY
  3509. }//END FOR AC ELSE
  3510. }//END FOR AvailabilityTypeStr[Operative]
  3511. end:
  3512. if(gunIndex != 0)
  3513. {
  3514. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  3515. }
  3516. else
  3517. {
  3518. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  3519. }
  3520. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  3521. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  3522. return result;
  3523. }
  3524. int handleChangeConfigurationRequest(char *uuid, char *payload)
  3525. {
  3526. mtrace();
  3527. int result = FAIL;
  3528. char sstr[100]={0};
  3529. char keystr[40]={0};
  3530. char valuestr[100]={0};
  3531. char *loc;
  3532. int c = 0;
  3533. char comfirmstr[20]={0};
  3534. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  3535. /***key ****/
  3536. loc = strstr(payload, "key");
  3537. memset(sstr ,0, sizeof(sstr) );
  3538. c = 0;
  3539. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  3540. {
  3541. sstr[c] = loc[3+strlen("key")+c];
  3542. c++;
  3543. }
  3544. sstr[c] = '\0';
  3545. strcpy(keystr, sstr);
  3546. //DEBUG_INFO( "keystr=%s\n",keystr);
  3547. /***value ****/
  3548. loc = strstr(payload, "value");
  3549. memset(sstr ,0, sizeof(sstr) );
  3550. c = 0;
  3551. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  3552. {
  3553. sstr[c] = loc[3+strlen("value")+c];
  3554. c++;
  3555. }
  3556. sstr[c] = '\0';
  3557. strcpy(valuestr, sstr);
  3558. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  3559. if((uuid==NULL) || (payload ==NULL) )
  3560. {
  3561. #ifdef Debug
  3562. DEBUG_INFO("payload is null\n");
  3563. #endif
  3564. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3565. }
  3566. else
  3567. {
  3568. int status = setKeyValue(keystr, valuestr);
  3569. switch(status)
  3570. {
  3571. case ConfigurationStatus_Accepted:
  3572. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  3573. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  3574. StoreConfigurationTable();
  3575. break;
  3576. case ConfigurationStatus_Rejected:
  3577. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  3578. break;
  3579. case RebootRequired:
  3580. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  3581. StoreConfigurationTable();
  3582. break;
  3583. case NotSupported:
  3584. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  3585. break;
  3586. default:
  3587. break;
  3588. }
  3589. }
  3590. //confirmation.setStatus(ConfigurationStatus.Rejected);
  3591. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  3592. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  3593. return result;
  3594. }
  3595. int handleClearCacheRequest(char *uuid, char *payload)
  3596. {
  3597. mtrace();
  3598. int result = FAIL;
  3599. char comfirmstr[20];
  3600. int fd;
  3601. char rmFileCmd[100]={0};
  3602. struct stat stats;
  3603. DEBUG_INFO("handle ClearCacheRequest\n");
  3604. stat("../Storage/OCPP", &stats);
  3605. // Check for directory existence
  3606. if (S_ISDIR(stats.st_mode) == 1)
  3607. {
  3608. //DEBUG_ERROR("\n OCPP directory exist \n");
  3609. }
  3610. else
  3611. {
  3612. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  3613. sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
  3614. system(rmFileCmd);
  3615. }
  3616. memset(rmFileCmd, 0, sizeof rmFileCmd);
  3617. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  3618. {
  3619. DEBUG_INFO("AuthorizationCache file exist.\n");
  3620. }
  3621. else
  3622. {
  3623. DEBUG_INFO("AuthorizationCache file not exist\n");
  3624. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  3625. if(log == NULL)
  3626. {
  3627. DEBUG_INFO("AuthorizationCache file is NULL\n");
  3628. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3629. goto end;
  3630. }
  3631. else
  3632. {
  3633. fclose(log);
  3634. }
  3635. }
  3636. fd = open(AuthorizationCache_JSON,O_RDWR);
  3637. if(fd < 0)
  3638. {
  3639. DEBUG_INFO("open AuthorizationCache file failed\n");
  3640. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  3641. }
  3642. else
  3643. {
  3644. DEBUG_INFO("open AuthorizationCache file successful\n");
  3645. //* 清空? 件 */
  3646. ftruncate(fd,0);
  3647. //* ? 新设置? 件? 移??*/
  3648. lseek(fd,0,SEEK_SET);
  3649. close(fd);
  3650. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  3651. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  3652. }
  3653. end:
  3654. sendClearCacheConfirmation(uuid, comfirmstr);
  3655. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  3656. return result;
  3657. }
  3658. int handleClearChargingProfileRequest(char *uuid, char *payload)
  3659. {
  3660. mtrace();
  3661. int result = FAIL;
  3662. int resultRename;
  3663. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  3664. char chargingProfilePurposeStr[26]={0};
  3665. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  3666. char tempchargingProfilePurposeStr[26]={0};
  3667. char sstr[160]={0};//sstr[200]={ 0 };
  3668. char str[100]={0};
  3669. int c = 0;
  3670. //int i = 0;
  3671. //char * pch;
  3672. char *loc;
  3673. char fname[200];
  3674. char comfirmstr[20]={0};
  3675. char word[1000]={0};
  3676. int clearflag = FALSE;
  3677. int chargingProfileIdIsNULL = FALSE;
  3678. int connectorIsNULL = FALSE;
  3679. int chargingProfilePurposeIsNULL = FALSE;
  3680. int stackLevelIsNULL = FALSE;
  3681. FILE *fptr1, *fptr2;
  3682. char temp[] = "../Storage/OCPP/ClearChargingProfiletemp.json";
  3683. int n_chargingProfile=0;
  3684. char sLineWord[1060]={0};
  3685. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  3686. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  3687. //***id ****/
  3688. c = 0;
  3689. loc = strstr(payload, "id");
  3690. memset(sstr ,0, sizeof(sstr) );
  3691. if(loc == NULL)
  3692. {
  3693. chargingProfileIdIsNULL = TRUE;
  3694. }
  3695. else
  3696. {
  3697. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  3698. {
  3699. sstr[c] = loc[strlen("id")+2+c];
  3700. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3701. c++;
  3702. }
  3703. sstr[c] = '\0';
  3704. chargingProfileIdInt = atoi(sstr);
  3705. }
  3706. //***connectorId ****/
  3707. c=0;
  3708. loc = strstr(payload, "connectorId");
  3709. memset(sstr ,0, sizeof(sstr) );
  3710. if(loc == NULL)
  3711. {
  3712. connectorIsNULL = TRUE;
  3713. }
  3714. else
  3715. {
  3716. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  3717. {
  3718. sstr[c] = loc[strlen("connectorId")+2+c];
  3719. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3720. c++;
  3721. }
  3722. sstr[c] = '\0';
  3723. connectorIdInt = atoi(sstr);
  3724. }
  3725. //***chargingProfilePurpose ****/
  3726. loc = strstr(payload, "chargingProfilePurpose");
  3727. memset(sstr ,0, sizeof(sstr) );
  3728. c = 0;
  3729. if(loc == NULL)
  3730. {
  3731. chargingProfilePurposeIsNULL = TRUE;
  3732. }
  3733. else
  3734. {
  3735. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  3736. {
  3737. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3738. c++;
  3739. }
  3740. sstr[c] = '\0';
  3741. strcpy(chargingProfilePurposeStr, sstr);
  3742. }
  3743. //***stackLevel ****/
  3744. c=0;
  3745. loc = strstr(payload, "stackLevel");
  3746. memset(sstr ,0, sizeof(sstr) );
  3747. if(loc == NULL)
  3748. {
  3749. stackLevelIsNULL = TRUE;
  3750. }
  3751. else
  3752. {
  3753. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  3754. {
  3755. sstr[c] = loc[strlen("stackLevel")+2+c];
  3756. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3757. c++;
  3758. }
  3759. sstr[c] = '\0';
  3760. stackLevelInt = atoi(sstr);
  3761. }
  3762. if(connectorIsNULL == FALSE)
  3763. {
  3764. switch(connectorIdInt)
  3765. {
  3766. case 0:
  3767. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0)))
  3768. {
  3769. strcpy(fname, ChargePointMaxProfile_JSON);
  3770. }
  3771. // else
  3772. // {
  3773. // strcpy(fname, TxDefaultProfile_0_JSON);
  3774. // }
  3775. break;
  3776. case 1:
  3777. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3778. {
  3779. strcpy(fname, TxDefaultProfile_1_JSON);
  3780. }
  3781. // else
  3782. // {
  3783. // strcpy(fname, TxProfile_1_JSON);
  3784. // }
  3785. break;
  3786. case 2:
  3787. if((chargingProfilePurposeIsNULL == TRUE)||((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0)))
  3788. {
  3789. strcpy(fname, TxDefaultProfile_2_JSON);
  3790. }
  3791. // else
  3792. // {
  3793. // strcpy(fname, TxProfile_2_JSON);
  3794. // }
  3795. break;
  3796. default:
  3797. strcpy(fname, ChargePointMaxProfile_JSON );
  3798. break;
  3799. }
  3800. }
  3801. else
  3802. {
  3803. strcpy(fname, ChargePointMaxProfile_JSON );
  3804. }
  3805. fptr1 = fopen(fname, "r");
  3806. if (!fptr1)
  3807. {
  3808. //file not exist
  3809. DEBUG_INFO("Unable to open the input file!!\n");
  3810. fptr1 = fopen(fname, "w+");
  3811. }
  3812. fclose(fptr1);
  3813. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ ) )
  3814. {
  3815. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3816. goto end;
  3817. }
  3818. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  3819. {
  3820. //clear the whole contents of a file in C
  3821. fclose(fopen(ChargePointMaxProfile_JSON, "w"));
  3822. fclose(fopen(TxDefaultProfile_0_JSON, "w"));
  3823. fclose(fopen(TxDefaultProfile_1_JSON, "w"));
  3824. fclose(fopen(TxDefaultProfile_2_JSON, "w"));
  3825. fclose(fopen(TxProfile_1_JSON, "w"));
  3826. fclose(fopen(TxProfile_2_JSON, "w"));
  3827. #if 0
  3828. fclose(fopen(ChargingProfile_0_JSON, "w"));
  3829. fclose(fopen(ChargingProfile_1_JSON, "w"));
  3830. fclose(fopen(ChargingProfile_2_JSON, "w"));
  3831. #endif
  3832. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3833. }
  3834. else
  3835. {
  3836. fptr1 = fopen(fname, "r");
  3837. fptr2 = fopen(temp, "w+");
  3838. while(fscanf(fptr1, "%s", word) != EOF)
  3839. {
  3840. //DEBUG_INFO("word=%s\n",word);
  3841. if(strcmp(word, "chargingProfileId") == 0)
  3842. {
  3843. n_chargingProfile = n_chargingProfile + 1;
  3844. DEBUG_INFO("chargingProfileId Found\n");
  3845. }
  3846. }
  3847. rewind(fptr1);
  3848. //search Charging Profile Element
  3849. //int i= 0;
  3850. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  3851. {
  3852. //*************************tempconnectorIdInt*********************************/
  3853. loc = strstr(sLineWord, "connectorId");
  3854. c = 0;
  3855. memset(sstr ,0, sizeof(sstr) );
  3856. while (loc[strlen("connectorId")+2+c] != ',')
  3857. {
  3858. sstr[c] = loc[strlen("connectorId")+2+c];
  3859. c++;
  3860. }
  3861. sstr[c] = '\0';
  3862. tempconnectorIdInt = atoi(sstr);
  3863. //chargingProfileId
  3864. c = 0;
  3865. loc = strstr(sLineWord, "chargingProfileId");
  3866. memset(sstr ,0, sizeof(sstr) );
  3867. while (loc[strlen("chargingProfileId")+2+c] != ',')
  3868. {
  3869. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  3870. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3871. c++;
  3872. }
  3873. sstr[c] = '\0';
  3874. tempchargingProfileIdInt = atoi(sstr);
  3875. //stackLevel
  3876. c = 0;
  3877. loc = strstr(sLineWord, "stackLevel");
  3878. memset(sstr ,0, sizeof(sstr) );
  3879. while (loc[strlen("stackLevel")+2+c] != ',')
  3880. {
  3881. sstr[c] = loc[strlen("stackLevel")+2+c];
  3882. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3883. c++;
  3884. }
  3885. sstr[c] = '\0';
  3886. tempstackLevelInt = atoi(sstr);
  3887. c = 0;
  3888. loc = strstr(sLineWord, "chargingProfilePurpose");
  3889. memset(sstr ,0, sizeof(sstr) );
  3890. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  3891. {
  3892. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  3893. c++;
  3894. }
  3895. sstr[c] = '\0';
  3896. strcpy(tempchargingProfilePurposeStr, sstr);
  3897. if(chargingProfileIdIsNULL == FALSE)
  3898. {
  3899. if(tempchargingProfileIdInt == chargingProfileIdInt)
  3900. {
  3901. //DEBUG_INFO("\n OCPP clear 0-1 !!!\n");
  3902. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3903. clearflag = TRUE;
  3904. continue;
  3905. }
  3906. else
  3907. {
  3908. //DEBUG_INFO("\n OCPP clear 0-2 !!!\n");
  3909. //json_object_array_add(newHeatMap, jsonitem);
  3910. fprintf(fptr2, sLineWord);//writing data into file
  3911. }
  3912. }
  3913. else
  3914. {
  3915. if((connectorIsNULL == FALSE) && (connectorIdInt != 0) && ( connectorIdInt == tempconnectorIdInt))
  3916. {
  3917. if((stackLevelIsNULL == TRUE)||((stackLevelIsNULL == FALSE)&& (tempstackLevelInt == stackLevelInt)))
  3918. {
  3919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3920. clearflag = TRUE;
  3921. continue;
  3922. }
  3923. }
  3924. else if((connectorIsNULL == TRUE) && ((tempstackLevelInt == stackLevelInt) || (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)))
  3925. {
  3926. if((stackLevelIsNULL == FALSE)|| (chargingProfilePurposeIsNULL == FALSE))
  3927. {
  3928. if( ((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt)) ||
  3929. ((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0)) )
  3930. {
  3931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  3932. clearflag = TRUE;
  3933. continue;
  3934. }
  3935. }
  3936. }
  3937. else
  3938. {
  3939. //json_object_array_add(newHeatMap, jsonitem);
  3940. fprintf(fptr2, sLineWord);//writing data into file
  3941. }
  3942. }
  3943. memset(sLineWord, 0, sizeof sLineWord);
  3944. }
  3945. if(clearflag == FALSE)
  3946. {
  3947. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  3948. goto end;
  3949. }
  3950. fclose(fptr1);
  3951. fclose(fptr2);
  3952. sprintf(str,"rm -f %s",fname);
  3953. system(str);
  3954. resultRename = rename(temp, fname);
  3955. if(resultRename == 0)
  3956. {
  3957. DEBUG_INFO("File ChargingProfile renamed successfully");
  3958. }
  3959. else
  3960. {
  3961. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  3962. }
  3963. }
  3964. end:
  3965. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  3966. return result;
  3967. }
  3968. int handleDataTransferRequest(char *uuid, char *payload)
  3969. {
  3970. mtrace();
  3971. int result = FAIL;
  3972. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  3973. char tempvendorId[255]={0};
  3974. char tempmessageId[50]={0};
  3975. char tempdata[50]={0};
  3976. char sstr[160]={0};//sstr[200]={ 0 };
  3977. char message[80]={0};
  3978. int c = 0;
  3979. char *loc;
  3980. DEBUG_INFO("handle DataTransferRequest\n");
  3981. if((uuid != NULL) && (payload != NULL))
  3982. {
  3983. //===============================
  3984. // vendorId
  3985. //===============================
  3986. c = 0;
  3987. loc = strstr(payload, "vendorId");
  3988. while (loc[strlen("vendorId")+3+c] != '\"')
  3989. {
  3990. sstr[c] = loc[strlen("vendorId")+3+c];
  3991. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3992. c++;
  3993. }
  3994. sstr[c] = '\0';
  3995. strcpy(tempvendorId,sstr);
  3996. //===============================
  3997. // messageId
  3998. //===============================
  3999. memset(sstr ,0, sizeof(sstr) );
  4000. c = 0;
  4001. loc = strstr(payload, "messageId");
  4002. while (loc[strlen("messageId")+3+c] != '\"')
  4003. {
  4004. sstr[c] = loc[strlen("messageId")+3+c];
  4005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4006. c++;
  4007. }
  4008. sstr[c] = '\0';
  4009. strcpy(tempmessageId,sstr);
  4010. //===============================
  4011. // data
  4012. //===============================
  4013. memset(sstr ,0, sizeof(sstr) );
  4014. c = 0;
  4015. loc = strstr(payload, "data");
  4016. printf("loc=%s\n",loc);
  4017. while (loc[strlen("data")+3+c] != '\"')
  4018. {
  4019. sstr[c] = loc[strlen("data")+3+c];
  4020. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4021. c++;
  4022. }
  4023. sstr[c] = '\0';
  4024. strcpy(tempdata,sstr);
  4025. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4026. }
  4027. else
  4028. {
  4029. char guid[37]={0};
  4030. random_uuid(guid);
  4031. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4032. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4033. }
  4034. LWS_Send(message);
  4035. return result;
  4036. }
  4037. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4038. {
  4039. mtrace();
  4040. int result = FAIL;
  4041. int connectorIdInt, durationInt;
  4042. char chargingRateUnitStr[4]={0};
  4043. //int tempconnectorIdInt,
  4044. int tempdurationInt;
  4045. float tempminChargingRateFloat = 0.0;
  4046. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4047. int tempStartPeriodInt=0;
  4048. float tempLimitInt=0.0;//0.1;
  4049. int tempNumberPhasesInt=0;
  4050. char fname[200];
  4051. char comfirmstr[20];
  4052. //float totallimit =0.0;
  4053. float MinChargingRate =0.0;
  4054. //double diff_t;
  4055. //struct tm tp;
  4056. FILE *fptr1;
  4057. int c = 0;
  4058. //int i = 0;
  4059. char * pch;
  4060. char *loc;
  4061. char sstr[200]={ 0 };
  4062. int n_chargingProfile = 0;
  4063. int n_SchedulePeriods = 0;
  4064. char SchedulePeriodList[10][200]={0};
  4065. char sLineWord[800]={0};
  4066. //int n_periods = 0;
  4067. char word[1000]={0};
  4068. int confirmPeriods = 0;
  4069. struct StructProfile ChargePointMaxProfile;
  4070. struct StructProfile TxDefaultProfile;
  4071. struct StructProfile TxProfile;
  4072. struct StructProfile TxDefaultProfiletemp[2]={0};
  4073. int TxDefaultProfileFileIsNull=FALSE;
  4074. int ChargePointMaxProfileIsNull=FALSE;
  4075. int TxProfileIsNull=FALSE;
  4076. int CompositeSceduleIndex = 0;
  4077. char ChargePointMaxProfileScheduleStr[30]={0};
  4078. char TxDefaultProfileScheduleStr[30]={0};
  4079. char TxProfileScheduleStr[30]={0};
  4080. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4081. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4082. memset(&TxProfile,0,sizeof(struct StructProfile));
  4083. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4084. c=0;
  4085. loc = strstr(payload, "connectorId");
  4086. memset(sstr ,0, sizeof(sstr) );
  4087. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4088. {
  4089. sstr[c] = loc[strlen("connectorId")+2+c];
  4090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4091. c++;
  4092. }
  4093. sstr[c] = '\0';
  4094. connectorIdInt = atoi(sstr);
  4095. c=0;
  4096. loc = strstr(payload, "duration");
  4097. memset(sstr ,0, sizeof(sstr) );
  4098. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4099. {
  4100. sstr[c] = loc[strlen("duration")+2+c];
  4101. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4102. c++;
  4103. }
  4104. sstr[c] = '\0';
  4105. durationInt = atoi(sstr);
  4106. c = 0;
  4107. loc = strstr(payload, "chargingRateUnit");
  4108. memset(sstr ,0, sizeof(sstr) );
  4109. if(loc == NULL)
  4110. {
  4111. }
  4112. else
  4113. {
  4114. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4115. {
  4116. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4117. c++;
  4118. }
  4119. sstr[c] = '\0';
  4120. strcpy(chargingRateUnitStr, sstr);
  4121. }
  4122. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4123. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4124. if(connectorIdInt==0) // connectorId is 0
  4125. {
  4126. //******************************ChargePointMaxProfile*****************************************************/
  4127. strcpy(fname, ChargePointMaxProfile_JSON );
  4128. char word[30]={0};
  4129. char sLineWord[1060]={0};
  4130. int n_chargingProfile=0;
  4131. ChargePointMaxProfileIsNull=TRUE;
  4132. if((access(fname,F_OK))!=-1)
  4133. {
  4134. fptr1 = fopen(fname, "r");
  4135. int c;
  4136. c = fgetc(fptr1);
  4137. //DEBUG_INFO("c:%d\n",c);
  4138. rewind(fptr1);
  4139. if(c == EOF)
  4140. {
  4141. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4142. ChargePointMaxProfileIsNull=TRUE;
  4143. fclose(fptr1);
  4144. }
  4145. else
  4146. {
  4147. ChargePointMaxProfileIsNull=FALSE;
  4148. while(fscanf(fptr1, "%s", word) != EOF)
  4149. {
  4150. if(strcmp(word, "chargingProfileId") == 0)
  4151. {
  4152. n_chargingProfile = n_chargingProfile + 1;
  4153. printf("Found\n");
  4154. }
  4155. }
  4156. rewind(fptr1);
  4157. //search Charging Profile Element
  4158. int i= 0;
  4159. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4160. #if 0
  4161. /***********connectorId****************/
  4162. c = 0;
  4163. loc = strstr(sLineWord, "connectorId");
  4164. // printf("loc=%s\n",loc);
  4165. memset(sstr ,0, sizeof(sstr) );
  4166. while (loc[strlen("connectorId")+2+c] != ',')
  4167. {
  4168. sstr[c] = loc[strlen("connectorId")+2+c];
  4169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4170. c++;
  4171. }
  4172. sstr[c] = '\0';
  4173. tempconnectorIdInt = atoi(sstr);
  4174. #endif
  4175. //***********validFrom**************/
  4176. c = 0;
  4177. loc = strstr(sLineWord, "validFrom");
  4178. //DEBUG_INFO("loc=%s\n",loc);
  4179. memset(sstr ,0, sizeof(sstr) );
  4180. if(loc != NULL)
  4181. {
  4182. while (loc[3+strlen("validFrom")+c] != '\"')
  4183. {
  4184. sstr[c] = loc[3+strlen("validFrom")+c];
  4185. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4186. c++;
  4187. }
  4188. sstr[c] = '\0';
  4189. DEBUG_INFO("validFrom=%s\n",sstr);
  4190. strcpy(tempvalidFromStr,sstr);
  4191. }
  4192. else
  4193. {
  4194. strcpy(tempvalidFromStr,"");
  4195. }
  4196. //**********startSchedule**********/
  4197. c = 0;
  4198. loc = strstr(sLineWord, "startSchedule");
  4199. //DEBUG_INFO("loc=%s\n",loc);
  4200. memset(sstr ,0, sizeof(sstr) );
  4201. while (loc[3+strlen("startSchedule")+c] != '\"')
  4202. {
  4203. sstr[c] = loc[3+strlen("startSchedule")+c];
  4204. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4205. c++;
  4206. }
  4207. sstr[c] = '\0';
  4208. strcpy(tempstartScheduleStr, sstr);
  4209. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4210. //**********chargingRateUnit**********/
  4211. c = 0;
  4212. loc = strstr(sLineWord, "chargingRateUnit");
  4213. memset(sstr ,0, sizeof(sstr) );
  4214. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4215. {
  4216. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4217. c++;
  4218. }
  4219. sstr[c] = '\0';
  4220. strcpy(tempchargingRateUnitStr, sstr);
  4221. //**********minChargingRate*******/
  4222. c = 0;
  4223. loc = strstr(sLineWord, "minChargingRate");
  4224. //printf("loc=%s\n",loc);
  4225. if(loc != NULL)
  4226. {
  4227. memset(sstr ,0, sizeof(sstr) );
  4228. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4229. {
  4230. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4232. c++;
  4233. }
  4234. sstr[c] = '\0';
  4235. tempminChargingRateFloat = atof(sstr);
  4236. }
  4237. else
  4238. {
  4239. tempminChargingRateFloat = 0.0;
  4240. }
  4241. //
  4242. #if 0
  4243. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4244. tp.tm_isdst = -1;
  4245. time_t utc = mktime(&tp);
  4246. // current time
  4247. time_t t = time(NULL);
  4248. #endif
  4249. //diff_t = difftime(t, utc);
  4250. //parsing strings to words
  4251. i = 0;
  4252. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4253. loc = loc+3+strlen("chargingSchedulePeriod");
  4254. pch = strtok(loc ,"{");
  4255. while (pch != NULL)
  4256. {
  4257. strcpy(SchedulePeriodList[i], pch);
  4258. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4259. //printf ("%s\n",pch);
  4260. pch = strtok (NULL, "{");
  4261. i = i + 1;
  4262. }
  4263. n_SchedulePeriods = i;
  4264. for(int i=0;i<n_SchedulePeriods;i++)
  4265. {
  4266. //*************startPeriod****************/
  4267. c = 0;
  4268. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4269. memset(sstr ,0, sizeof(sstr) );
  4270. while (loc[strlen("startPeriod")+2+c] != ',')
  4271. {
  4272. sstr[c] = loc[strlen("startPeriod")+2+c];
  4273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4274. c++;
  4275. }
  4276. sstr[c] = '\0';
  4277. tempStartPeriodInt = atoi(sstr);
  4278. //*************limit****************/
  4279. c = 0;
  4280. loc = strstr(SchedulePeriodList[i], "limit");
  4281. memset(sstr ,0, sizeof(sstr) );
  4282. while (loc[strlen("limit")+2+c] != ',')
  4283. {
  4284. sstr[c] = loc[strlen("limit")+2+c];
  4285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4286. c++;
  4287. }
  4288. sstr[c] = '\0';
  4289. tempLimitInt = atof(sstr);
  4290. //*************numberPhases****************/
  4291. c = 0;
  4292. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4293. memset(sstr ,0, sizeof(sstr) );
  4294. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4295. {
  4296. sstr[c] = loc[strlen("numberPhases")+2+c];
  4297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4298. c++;
  4299. }
  4300. sstr[c] = '\0';
  4301. tempNumberPhasesInt = atoi(sstr);
  4302. ChargePointMaxProfile.Duration = durationInt;
  4303. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4304. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4305. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4306. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4307. }
  4308. if(MinChargingRate < tempminChargingRateFloat)
  4309. MinChargingRate = tempminChargingRateFloat;
  4310. }
  4311. }// End of file ChargingProfile
  4312. } //THE END OF ACCESS ChargePointMaxProfile
  4313. //******************************TxDefaultProfile***********************************************/
  4314. strcpy(fname, TxDefaultProfile_0_JSON);
  4315. memset(word, 0, 30);
  4316. memset(sLineWord, 0, 1060);
  4317. //char word[30]={0};
  4318. //char sLineWord[1060]={0};
  4319. n_chargingProfile=0;
  4320. TxDefaultProfileFileIsNull=TRUE;
  4321. if((access(fname,F_OK))!=-1)
  4322. {
  4323. fptr1 = fopen(fname, "r");
  4324. c = 0;
  4325. c = fgetc(fptr1);
  4326. //DEBUG_INFO("c:%d\n",c);
  4327. rewind(fptr1);
  4328. if(c == EOF)
  4329. {
  4330. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4331. TxDefaultProfileFileIsNull=TRUE;
  4332. fclose(fptr1);
  4333. }
  4334. else
  4335. {
  4336. TxDefaultProfileFileIsNull=FALSE;
  4337. while(fscanf(fptr1, "%s", word) != EOF)
  4338. {
  4339. if(strcmp(word, "chargingProfileId") == 0)
  4340. {
  4341. n_chargingProfile = n_chargingProfile + 1;
  4342. printf("Found\n");
  4343. }
  4344. }
  4345. rewind(fptr1);
  4346. //search Charging Profile Element
  4347. int i= 0;
  4348. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4349. #if 0
  4350. /***********connectorId****************/
  4351. c = 0;
  4352. loc = strstr(sLineWord, "connectorId");
  4353. // printf("loc=%s\n",loc);
  4354. memset(sstr ,0, sizeof(sstr) );
  4355. while (loc[strlen("connectorId")+2+c] != ',')
  4356. {
  4357. sstr[c] = loc[strlen("connectorId")+2+c];
  4358. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4359. c++;
  4360. }
  4361. sstr[c] = '\0';
  4362. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  4363. tempconnectorIdInt = atoi(sstr);
  4364. #endif
  4365. //***********validFrom**************/
  4366. c = 0;
  4367. loc = strstr(sLineWord, "validFrom");
  4368. //DEBUG_INFO("loc=%s\n",loc);
  4369. memset(sstr ,0, sizeof(sstr) );
  4370. if(loc != NULL)
  4371. {
  4372. while (loc[3+strlen("validFrom")+c] != '\"')
  4373. {
  4374. sstr[c] = loc[3+strlen("validFrom")+c];
  4375. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4376. c++;
  4377. }
  4378. sstr[c] = '\0';
  4379. DEBUG_INFO("validFrom=%s\n",sstr);
  4380. strcpy(tempvalidFromStr,sstr);
  4381. }
  4382. else
  4383. {
  4384. strcpy(tempvalidFromStr,"");
  4385. }
  4386. //**********startSchedule**********/
  4387. c = 0;
  4388. loc = strstr(sLineWord, "startSchedule");
  4389. //DEBUG_INFO("loc=%s\n",loc);
  4390. memset(sstr ,0, sizeof(sstr) );
  4391. while (loc[3+strlen("startSchedule")+c] != '\"')
  4392. {
  4393. sstr[c] = loc[3+strlen("startSchedule")+c];
  4394. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4395. c++;
  4396. }
  4397. sstr[c] = '\0';
  4398. strcpy(tempstartScheduleStr, sstr);
  4399. strcpy(TxDefaultProfileScheduleStr, sstr);
  4400. DEBUG_INFO(" debug 3-1\n");
  4401. //**********chargingRateUnit**********/
  4402. c = 0;
  4403. loc = strstr(sLineWord, "chargingRateUnit");
  4404. memset(sstr ,0, sizeof(sstr) );
  4405. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4406. {
  4407. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4408. c++;
  4409. }
  4410. sstr[c] = '\0';
  4411. strcpy(tempchargingRateUnitStr, sstr);
  4412. //**********minChargingRate*******/
  4413. c = 0;
  4414. loc = strstr(sLineWord, "minChargingRate");
  4415. //printf("loc=%s\n",loc);
  4416. if(loc != NULL)
  4417. {
  4418. memset(sstr ,0, sizeof(sstr) );
  4419. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4420. {
  4421. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4423. c++;
  4424. }
  4425. sstr[c] = '\0';
  4426. tempminChargingRateFloat = atof(sstr);
  4427. }
  4428. else
  4429. {
  4430. tempminChargingRateFloat = 0.0;
  4431. }
  4432. #if 0
  4433. //
  4434. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4435. tp.tm_isdst = -1;
  4436. time_t utc = mktime(&tp);
  4437. // current time
  4438. time_t t = time(NULL);
  4439. //diff_t = difftime(t, utc);
  4440. #endif
  4441. //parsing strings to words
  4442. i = 0;
  4443. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4444. loc = loc+3+strlen("chargingSchedulePeriod");
  4445. pch = strtok(loc ,"{");
  4446. while (pch != NULL)
  4447. {
  4448. strcpy(SchedulePeriodList[i], pch);
  4449. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  4450. //printf ("%s\n",pch);
  4451. pch = strtok (NULL, "{");
  4452. i = i + 1;
  4453. }
  4454. n_SchedulePeriods = i;
  4455. for(int i=0;i<n_SchedulePeriods;i++)
  4456. {
  4457. //*************startPeriod****************/
  4458. c = 0;
  4459. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4460. memset(sstr ,0, sizeof(sstr) );
  4461. while (loc[strlen("startPeriod")+2+c] != ',')
  4462. {
  4463. sstr[c] = loc[strlen("startPeriod")+2+c];
  4464. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4465. c++;
  4466. }
  4467. sstr[c] = '\0';
  4468. tempStartPeriodInt = atoi(sstr);
  4469. //*************limit****************/
  4470. c = 0;
  4471. loc = strstr(SchedulePeriodList[i], "limit");
  4472. memset(sstr ,0, sizeof(sstr) );
  4473. while (loc[strlen("limit")+2+c] != ',')
  4474. {
  4475. sstr[c] = loc[strlen("limit")+2+c];
  4476. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4477. c++;
  4478. }
  4479. sstr[c] = '\0';
  4480. tempLimitInt = atof(sstr);
  4481. //*************numberPhases****************/
  4482. c = 0;
  4483. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4484. memset(sstr ,0, sizeof(sstr) );
  4485. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  4486. {
  4487. sstr[c] = loc[strlen("numberPhases")+2+c];
  4488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4489. c++;
  4490. }
  4491. sstr[c] = '\0';
  4492. tempNumberPhasesInt = atoi(sstr);
  4493. TxDefaultProfile.Duration = durationInt;
  4494. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4495. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4496. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4497. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4498. }
  4499. if(MinChargingRate < tempminChargingRateFloat)
  4500. MinChargingRate = tempminChargingRateFloat;
  4501. }
  4502. }
  4503. }// the end of ACCESS TxDefaultProfile
  4504. // Composite Schedule
  4505. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  4506. {
  4507. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  4508. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  4509. {
  4510. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  4511. {
  4512. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = TxDefaultProfile.Period[index].Limit;
  4513. }
  4514. else
  4515. {
  4516. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[0].Limit;
  4517. }
  4518. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  4519. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = TxDefaultProfile.Period[index].StartPeriod;
  4520. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  4521. }
  4522. }
  4523. //* Define temporary variables */
  4524. struct tm *gtime;
  4525. time_t now;
  4526. char buf[28];
  4527. /* Read the current system time */
  4528. time(&now);
  4529. /* Convert the system time to GMT (now UTC) */
  4530. gtime = gmtime(&now);
  4531. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  4532. // make .conf
  4533. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  4534. //MaxChargingProfilesInstalled is 10
  4535. // ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod = (struct StructChargingSchedulePeriod *) malloc(sizeof(struct StructChargingSchedulePeriod)* 9);
  4536. memset(ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod, 0, sizeof(struct StructChargingSchedulePeriod)* 9);
  4537. //nPeriod = 1;
  4538. if(chargingRateUnitStr[0] != 0)
  4539. {
  4540. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, chargingRateUnitStr );
  4541. }
  4542. else
  4543. {
  4544. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, "" );
  4545. }
  4546. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  4547. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  4548. confirmPeriods = 1;
  4549. }
  4550. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  4551. {
  4552. //*****************************ChargePointMaxProfile******************************************/
  4553. strcpy(fname, ChargePointMaxProfile_JSON);
  4554. ChargePointMaxProfileIsNull=TRUE;
  4555. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  4556. {
  4557. fptr1 = fopen(fname, "r");
  4558. int c;
  4559. c = fgetc(fptr1);
  4560. //DEBUG_INFO("c:%d\n",c);
  4561. rewind(fptr1);
  4562. if(c == EOF)
  4563. {
  4564. DEBUG_INFO("\n End of file reached.");
  4565. ChargePointMaxProfileIsNull=TRUE;
  4566. fclose(fptr1);
  4567. }
  4568. else
  4569. {
  4570. ChargePointMaxProfileIsNull=FALSE;
  4571. while(fscanf(fptr1, "%s", word) != EOF)
  4572. {
  4573. if(strcmp(word, "chargingProfileId") == 0)
  4574. {
  4575. n_chargingProfile = n_chargingProfile + 1;
  4576. }
  4577. }
  4578. rewind(fptr1);
  4579. //search Charging Profile Element
  4580. int i = 0;
  4581. int j = 0;
  4582. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4583. #if 0
  4584. /***********connectorId****************/
  4585. c = 0;
  4586. loc = strstr(sLineWord, "connectorId");
  4587. memset(sstr ,0, sizeof(sstr) );
  4588. while (loc[strlen("connectorId")+2+c] != ',')
  4589. {
  4590. sstr[c] = loc[strlen("connectorId")+2+c];
  4591. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4592. c++;
  4593. }
  4594. sstr[c] = '\0';
  4595. tempconnectorIdInt = atoi(sstr);
  4596. #endif
  4597. //***********validFrom**************/
  4598. c = 0;
  4599. loc = strstr(sLineWord, "validFrom");
  4600. if(loc != NULL)
  4601. {
  4602. memset(sstr ,0, sizeof(sstr) );
  4603. while (loc[3+strlen("validFrom")+c] != '\"')
  4604. {
  4605. sstr[c] = loc[3+strlen("validFrom")+c];
  4606. c++;
  4607. }
  4608. sstr[c] = '\0';
  4609. strcpy(tempvalidFromStr,sstr);
  4610. }
  4611. else
  4612. {
  4613. strcpy(tempvalidFromStr,"");
  4614. }
  4615. //***********validFrom**************/
  4616. c = 0;
  4617. loc = strstr(sLineWord, "duration");
  4618. if(loc != NULL)
  4619. {
  4620. memset(sstr ,0, sizeof(sstr) );
  4621. while (loc[2+strlen("duration")+c] != ',')
  4622. {
  4623. sstr[c] = loc[2+strlen("duration")+c];
  4624. c++;
  4625. }
  4626. sstr[c] = '\0';
  4627. tempdurationInt = atoi(sstr);
  4628. }
  4629. else
  4630. {
  4631. tempdurationInt = 0;
  4632. }
  4633. //**********startSchedule**********/
  4634. c = 0;
  4635. loc = strstr(sLineWord, "startSchedule");
  4636. memset(sstr ,0, sizeof(sstr) );
  4637. while (loc[3+strlen("startSchedule")+c] != '\"')
  4638. {
  4639. sstr[c] = loc[3+strlen("startSchedule")+c];
  4640. c++;
  4641. }
  4642. sstr[c] = '\0';
  4643. strcpy(tempstartScheduleStr, sstr);
  4644. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  4645. //**********chargingRateUnit**********/
  4646. c = 0;
  4647. loc = strstr(sLineWord, "chargingRateUnit");
  4648. memset(sstr ,0, sizeof(sstr) );
  4649. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4650. {
  4651. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4652. c++;
  4653. }
  4654. sstr[c] = '\0';
  4655. strcpy(tempchargingRateUnitStr, sstr);
  4656. //**********minChargingRate*******/
  4657. c = 0;
  4658. loc = strstr(sLineWord, "minChargingRate");
  4659. if(loc != NULL)
  4660. {
  4661. memset(sstr ,0, sizeof(sstr) );
  4662. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4663. {
  4664. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4665. c++;
  4666. }
  4667. sstr[c] = '\0';
  4668. tempminChargingRateFloat = atof(sstr);
  4669. }
  4670. else
  4671. {
  4672. tempminChargingRateFloat = 0.0;
  4673. }
  4674. #if 0
  4675. //
  4676. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4677. tp.tm_isdst = -1;
  4678. time_t utc = mktime(&tp);
  4679. time_t t = time(NULL);
  4680. //diff_t = difftime(t, utc);
  4681. #endif
  4682. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4683. //DEBUG_INFO(" debug 5 -1\n");
  4684. //parsing strings to words
  4685. i = 0;
  4686. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4687. loc = loc+3+strlen("chargingSchedulePeriod");
  4688. pch = strtok(loc ,"{");
  4689. while (pch != NULL)
  4690. {
  4691. strcpy(SchedulePeriodList[i], pch);
  4692. pch = strtok (NULL, "{");
  4693. i = i + 1;
  4694. }
  4695. n_SchedulePeriods = i;
  4696. for(int i=0;i<n_SchedulePeriods;i++)
  4697. {
  4698. //*************startPeriod****************/
  4699. c = 0;
  4700. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4701. memset(sstr ,0, sizeof(sstr) );
  4702. while (loc[strlen("startPeriod")+2+c] != ',')
  4703. {
  4704. sstr[c] = loc[strlen("startPeriod")+2+c];
  4705. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4706. c++;
  4707. }
  4708. sstr[c] = '\0';
  4709. tempStartPeriodInt = atoi(sstr);
  4710. //*************limit****************/
  4711. c = 0;
  4712. loc = strstr(SchedulePeriodList[i], "limit");
  4713. memset(sstr ,0, sizeof(sstr) );
  4714. while (loc[strlen("limit")+2+c] != ',')
  4715. {
  4716. sstr[c] = loc[strlen("limit")+2+c];
  4717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4718. c++;
  4719. }
  4720. sstr[c] = '\0';
  4721. tempLimitInt = atof(sstr);
  4722. //*************numberPhases****************/
  4723. c = 0;
  4724. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4725. memset(sstr ,0, sizeof(sstr) );
  4726. while (loc[strlen("numberPhases")+2+c] != '}')
  4727. {
  4728. sstr[c] = loc[strlen("numberPhases")+2+c];
  4729. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4730. c++;
  4731. }
  4732. sstr[c] = '\0';
  4733. tempNumberPhasesInt = atoi(sstr);
  4734. if(j == 0)
  4735. {
  4736. ChargePointMaxProfile.Duration = tempdurationInt;
  4737. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  4738. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  4739. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4740. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4741. }
  4742. }
  4743. if(MinChargingRate < tempminChargingRateFloat)
  4744. {
  4745. MinChargingRate = tempminChargingRateFloat;
  4746. }
  4747. if(confirmPeriods < n_SchedulePeriods)
  4748. {
  4749. confirmPeriods = n_SchedulePeriods;
  4750. }
  4751. j = j + 1;
  4752. }
  4753. fclose(fptr1);
  4754. }
  4755. }// the end of access file ChargePointMaxProfile
  4756. //****************************TxDefaultProfile************************************************/
  4757. switch(connectorIdInt)
  4758. {
  4759. case 0:
  4760. break;
  4761. case 1:
  4762. strcpy(fname, TxDefaultProfile_1_JSON );
  4763. break;
  4764. case 2:
  4765. strcpy(fname, TxDefaultProfile_2_JSON );
  4766. break;
  4767. default:
  4768. strcpy(fname, TxDefaultProfile_1_JSON );
  4769. break;
  4770. }
  4771. TxDefaultProfileFileIsNull=TRUE;
  4772. if((access(fname,F_OK))!=-1)
  4773. {
  4774. fptr1 = fopen(fname, "r");
  4775. c = 0;
  4776. c = fgetc(fptr1);
  4777. //DEBUG_INFO("c:%d\n",c);
  4778. rewind(fptr1);
  4779. if(c == EOF)
  4780. {
  4781. DEBUG_INFO("\n End of file reached.");
  4782. TxDefaultProfileFileIsNull=TRUE;
  4783. fclose(fptr1);
  4784. }
  4785. else
  4786. {
  4787. TxDefaultProfileFileIsNull=FALSE;
  4788. while(fscanf(fptr1, "%s", word) != EOF)
  4789. {
  4790. if(strcmp(word, "chargingProfileId") == 0)
  4791. {
  4792. n_chargingProfile = n_chargingProfile + 1;
  4793. }
  4794. }
  4795. rewind(fptr1);
  4796. //search Charging Profile Element
  4797. int i = 0;
  4798. int j = 0;
  4799. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4800. //DEBUG_INFO(" 1-1\n");
  4801. #if 0
  4802. /***********connectorId****************/
  4803. c = 0;
  4804. loc = strstr(sLineWord, "connectorId");
  4805. memset(sstr ,0, sizeof(sstr) );
  4806. while (loc[strlen("connectorId")+2+c] != ',')
  4807. {
  4808. sstr[c] = loc[strlen("connectorId")+2+c];
  4809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4810. c++;
  4811. }
  4812. sstr[c] = '\0';
  4813. tempconnectorIdInt = atoi(sstr);
  4814. #endif
  4815. //***********validFrom**************/
  4816. c = 0;
  4817. loc = strstr(sLineWord, "validFrom");
  4818. if(loc != NULL)
  4819. {
  4820. memset(sstr ,0, sizeof(sstr) );
  4821. while (loc[3+strlen("validFrom")+c] != '\"')
  4822. {
  4823. sstr[c] = loc[3+strlen("validFrom")+c];
  4824. c++;
  4825. }
  4826. sstr[c] = '\0';
  4827. strcpy(tempvalidFromStr,sstr);
  4828. }
  4829. else
  4830. {
  4831. strcpy(tempvalidFromStr,"");
  4832. }
  4833. //***********validFrom**************/
  4834. c = 0;
  4835. loc = strstr(sLineWord, "duration");
  4836. if(loc != NULL)
  4837. {
  4838. memset(sstr ,0, sizeof(sstr) );
  4839. while (loc[2+strlen("duration")+c] != ',')
  4840. {
  4841. sstr[c] = loc[2+strlen("duration")+c];
  4842. c++;
  4843. }
  4844. sstr[c] = '\0';
  4845. tempdurationInt = atoi(sstr);
  4846. }
  4847. else
  4848. {
  4849. tempdurationInt = 0;
  4850. }
  4851. //**********startSchedule**********/
  4852. c = 0;
  4853. loc = strstr(sLineWord, "startSchedule");
  4854. memset(sstr ,0, sizeof(sstr) );
  4855. while (loc[3+strlen("startSchedule")+c] != '\"')
  4856. {
  4857. sstr[c] = loc[3+strlen("startSchedule")+c];
  4858. c++;
  4859. }
  4860. sstr[c] = '\0';
  4861. strcpy(tempstartScheduleStr, sstr);
  4862. strcpy(TxDefaultProfileScheduleStr, sstr);
  4863. //**********chargingRateUnit**********/
  4864. c = 0;
  4865. loc = strstr(sLineWord, "chargingRateUnit");
  4866. memset(sstr ,0, sizeof(sstr) );
  4867. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4868. {
  4869. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4870. c++;
  4871. }
  4872. sstr[c] = '\0';
  4873. strcpy(tempchargingRateUnitStr, sstr);
  4874. //**********minChargingRate*******/
  4875. c = 0;
  4876. loc = strstr(sLineWord, "minChargingRate");
  4877. if(loc != NULL)
  4878. {
  4879. memset(sstr ,0, sizeof(sstr) );
  4880. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  4881. {
  4882. sstr[c] = loc[2+strlen("minChargingRate")+c];
  4883. c++;
  4884. }
  4885. sstr[c] = '\0';
  4886. tempminChargingRateFloat = atof(sstr);
  4887. }
  4888. else
  4889. {
  4890. tempminChargingRateFloat = 0.0;
  4891. }
  4892. #if 0
  4893. //
  4894. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  4895. tp.tm_isdst = -1;
  4896. time_t utc = mktime(&tp);
  4897. time_t t = time(NULL);
  4898. //diff_t = difftime(t, utc);
  4899. #endif
  4900. //DEBUG_INFO("diff_t=%f\n",diff_t);
  4901. //parsing strings to words
  4902. i = 0;
  4903. loc = strstr(sLineWord, "chargingSchedulePeriod");
  4904. loc = loc+3+strlen("chargingSchedulePeriod");
  4905. pch = strtok(loc ,"{");
  4906. while (pch != NULL)
  4907. {
  4908. strcpy(SchedulePeriodList[i], pch);
  4909. pch = strtok (NULL, "{");
  4910. i = i + 1;
  4911. }
  4912. n_SchedulePeriods = i;
  4913. for(int i=0;i<n_SchedulePeriods;i++)
  4914. {
  4915. //*************startPeriod****************/
  4916. c = 0;
  4917. loc = strstr(SchedulePeriodList[i], "startPeriod");
  4918. memset(sstr ,0, sizeof(sstr) );
  4919. while (loc[strlen("startPeriod")+2+c] != ',')
  4920. {
  4921. sstr[c] = loc[strlen("startPeriod")+2+c];
  4922. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4923. c++;
  4924. }
  4925. sstr[c] = '\0';
  4926. tempStartPeriodInt = atoi(sstr);
  4927. //*************limit****************/
  4928. c = 0;
  4929. loc = strstr(SchedulePeriodList[i], "limit");
  4930. memset(sstr ,0, sizeof(sstr) );
  4931. while (loc[strlen("limit")+2+c] != ',')
  4932. {
  4933. sstr[c] = loc[strlen("limit")+2+c];
  4934. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4935. c++;
  4936. }
  4937. sstr[c] = '\0';
  4938. tempLimitInt = atof(sstr);
  4939. //*************numberPhases****************/
  4940. c = 0;
  4941. loc = strstr(SchedulePeriodList[i], "numberPhases");
  4942. memset(sstr ,0, sizeof(sstr) );
  4943. while (loc[strlen("numberPhases")+2+c] != '}')
  4944. {
  4945. sstr[c] = loc[strlen("numberPhases")+2+c];
  4946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4947. c++;
  4948. }
  4949. sstr[c] = '\0';
  4950. tempNumberPhasesInt = atoi(sstr);
  4951. if(j == 0)
  4952. {
  4953. TxDefaultProfile.Duration = tempdurationInt;
  4954. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  4955. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  4956. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  4957. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  4958. }
  4959. else
  4960. {
  4961. //other stack level charging Profile
  4962. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  4963. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  4964. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  4965. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  4966. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  4967. }
  4968. }
  4969. if(MinChargingRate < tempminChargingRateFloat)
  4970. MinChargingRate = tempminChargingRateFloat;
  4971. if(confirmPeriods < n_SchedulePeriods)
  4972. confirmPeriods = n_SchedulePeriods;
  4973. j = j + 1;
  4974. //DEBUG_INFO(" 1-2\n");
  4975. }
  4976. fclose(fptr1);
  4977. //Stacking Charging Profiles
  4978. for(int l=0; l <(j-1) ;l++)
  4979. {
  4980. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  4981. {
  4982. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  4983. {
  4984. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  4985. {
  4986. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  4987. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  4988. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  4989. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4990. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4991. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  4992. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  4993. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  4994. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  4995. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  4996. }
  4997. else
  4998. {
  4999. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5000. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5001. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5002. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5003. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5004. }
  5005. }
  5006. }
  5007. }
  5008. //end of Stacking Charging Profiles
  5009. }
  5010. }// the end of ACCESS TxDefaultProfile
  5011. //****************************TxProfile************************************************/
  5012. switch(connectorIdInt)
  5013. {
  5014. case 0:
  5015. break;
  5016. case 1:
  5017. strcpy(fname, TxProfile_1_JSON );
  5018. break;
  5019. case 2:
  5020. strcpy(fname, TxProfile_2_JSON );
  5021. break;
  5022. default:
  5023. strcpy(fname, TxProfile_1_JSON );
  5024. break;
  5025. }
  5026. TxProfileIsNull=TRUE;
  5027. if((access(fname,F_OK))!=-1)
  5028. {
  5029. fptr1 = fopen(fname, "r");
  5030. c = 0;
  5031. c = fgetc(fptr1);
  5032. //DEBUG_INFO("c:%d\n",c);
  5033. rewind(fptr1);
  5034. if(c == EOF)
  5035. {
  5036. DEBUG_INFO("\n End of file reached.");
  5037. TxProfileIsNull=TRUE;
  5038. fclose(fptr1);
  5039. }
  5040. else
  5041. {
  5042. TxProfileIsNull=FALSE;
  5043. while(fscanf(fptr1, "%s", word) != EOF)
  5044. {
  5045. if(strcmp(word, "chargingProfileId") == 0)
  5046. {
  5047. n_chargingProfile = n_chargingProfile + 1;
  5048. }
  5049. }
  5050. rewind(fptr1);
  5051. //search Charging Profile Element
  5052. int i= 0;
  5053. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5054. #if 0
  5055. /***********connectorId****************/
  5056. c = 0;
  5057. loc = strstr(sLineWord, "connectorId");
  5058. memset(sstr ,0, sizeof(sstr) );
  5059. while (loc[strlen("connectorId")+2+c] != ',')
  5060. {
  5061. sstr[c] = loc[strlen("connectorId")+2+c];
  5062. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5063. c++;
  5064. }
  5065. sstr[c] = '\0';
  5066. tempconnectorIdInt = atoi(sstr);
  5067. #endif
  5068. //***********validFrom**************/
  5069. c = 0;
  5070. loc = strstr(sLineWord, "validFrom");
  5071. if(loc != NULL)
  5072. {
  5073. memset(sstr ,0, sizeof(sstr) );
  5074. while (loc[3+strlen("validFrom")+c] != '\"')
  5075. {
  5076. sstr[c] = loc[3+strlen("validFrom")+c];
  5077. c++;
  5078. }
  5079. sstr[c] = '\0';
  5080. strcpy(tempvalidFromStr,sstr);
  5081. }
  5082. else
  5083. {
  5084. strcpy(tempvalidFromStr,"");
  5085. }
  5086. //**********startSchedule**********/
  5087. c = 0;
  5088. loc = strstr(sLineWord, "startSchedule");
  5089. memset(sstr ,0, sizeof(sstr) );
  5090. while (loc[3+strlen("startSchedule")+c] != '\"')
  5091. {
  5092. sstr[c] = loc[3+strlen("startSchedule")+c];
  5093. c++;
  5094. }
  5095. sstr[c] = '\0';
  5096. strcpy(tempstartScheduleStr, sstr);
  5097. strcpy(TxProfileScheduleStr, sstr);
  5098. //**********chargingRateUnit**********/
  5099. c = 0;
  5100. loc = strstr(sLineWord, "chargingRateUnit");
  5101. memset(sstr ,0, sizeof(sstr) );
  5102. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5103. {
  5104. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5105. c++;
  5106. }
  5107. sstr[c] = '\0';
  5108. strcpy(tempchargingRateUnitStr, sstr);
  5109. //**********minChargingRate*******/
  5110. c = 0;
  5111. loc = strstr(sLineWord, "minChargingRate");
  5112. if(loc != NULL)
  5113. {
  5114. memset(sstr ,0, sizeof(sstr) );
  5115. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5116. {
  5117. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5118. c++;
  5119. }
  5120. sstr[c] = '\0';
  5121. tempminChargingRateFloat = atof(sstr);
  5122. }
  5123. else
  5124. {
  5125. tempminChargingRateFloat = 0.0;
  5126. }
  5127. #if 0
  5128. //
  5129. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5130. tp.tm_isdst = -1;
  5131. time_t utc = mktime(&tp);
  5132. time_t t = time(NULL);
  5133. //diff_t = difftime(t, utc);
  5134. #endif
  5135. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5136. //parsing strings to words
  5137. i = 0;
  5138. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5139. loc = loc+3+strlen("chargingSchedulePeriod");
  5140. pch = strtok(loc ,"{");
  5141. while (pch != NULL)
  5142. {
  5143. strcpy(SchedulePeriodList[i], pch);
  5144. pch = strtok (NULL, "{");
  5145. i = i + 1;
  5146. }
  5147. n_SchedulePeriods = i;
  5148. for(int i=0;i<n_SchedulePeriods;i++)
  5149. {
  5150. //*************startPeriod****************/
  5151. c = 0;
  5152. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5153. memset(sstr ,0, sizeof(sstr) );
  5154. while (loc[strlen("startPeriod")+2+c] != ',')
  5155. {
  5156. sstr[c] = loc[strlen("startPeriod")+2+c];
  5157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5158. c++;
  5159. }
  5160. sstr[c] = '\0';
  5161. tempStartPeriodInt = atoi(sstr);
  5162. //*************limit****************/
  5163. c = 0;
  5164. loc = strstr(SchedulePeriodList[i], "limit");
  5165. memset(sstr ,0, sizeof(sstr) );
  5166. while (loc[strlen("limit")+2+c] != ',')
  5167. {
  5168. sstr[c] = loc[strlen("limit")+2+c];
  5169. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5170. c++;
  5171. }
  5172. sstr[c] = '\0';
  5173. tempLimitInt = atof(sstr);
  5174. //*************numberPhases****************/
  5175. c = 0;
  5176. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5177. memset(sstr ,0, sizeof(sstr) );
  5178. while (loc[strlen("numberPhases")+2+c] != '}')
  5179. {
  5180. sstr[c] = loc[strlen("numberPhases")+2+c];
  5181. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5182. c++;
  5183. }
  5184. sstr[c] = '\0';
  5185. tempNumberPhasesInt = atoi(sstr);
  5186. TxProfile.Duration = durationInt;
  5187. TxProfile.TotalPeriod = n_SchedulePeriods;
  5188. TxProfile.Period[i].Limit = tempLimitInt;
  5189. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5190. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5191. }
  5192. if(MinChargingRate < tempminChargingRateFloat)
  5193. MinChargingRate = tempminChargingRateFloat;
  5194. if(confirmPeriods < n_SchedulePeriods)
  5195. confirmPeriods = n_SchedulePeriods;
  5196. }
  5197. fclose(fptr1);
  5198. }
  5199. }// the end of ACCESS TxProfile
  5200. //CompositeSchedule
  5201. int period=0;
  5202. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  5203. {
  5204. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  5205. for(int k=0; k < TxProfile.TotalPeriod;k++)
  5206. {
  5207. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  5208. {
  5209. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  5210. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5211. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5212. period = period + 1;
  5213. }
  5214. else
  5215. {
  5216. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  5217. {
  5218. }
  5219. else
  5220. {
  5221. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5222. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  5223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  5224. period = period + 1;
  5225. }
  5226. }
  5227. }
  5228. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5229. {
  5230. if((TxDefaultProfile.Period[l].StartPeriod < durationInt)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  5231. {
  5232. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5233. {
  5234. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  5235. }
  5236. else
  5237. {
  5238. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5239. }
  5240. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5241. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5242. period = period + 1;
  5243. }
  5244. }
  5245. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  5246. {
  5247. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5248. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  5249. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  5250. period = period + 1;
  5251. }
  5252. }
  5253. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  5254. {
  5255. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5256. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5257. {
  5258. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  5259. {
  5260. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5261. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5262. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5263. period = period + 1;
  5264. }
  5265. else
  5266. {
  5267. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  5268. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5269. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5270. period = period + 1;
  5271. }
  5272. }
  5273. }
  5274. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  5275. {
  5276. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  5277. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  5278. {
  5279. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  5280. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  5281. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  5282. period = period + 1;
  5283. }
  5284. }
  5285. confirmPeriods = period;
  5286. //DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  5287. //* Define temporary variables */
  5288. struct tm *gtime;
  5289. time_t now;
  5290. char buf[28];
  5291. //* Read the current system time */
  5292. time(&now);
  5293. //* Convert the system time to GMT (now UTC) */
  5294. gtime = gmtime(&now);
  5295. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5296. // make .conf
  5297. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5298. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5299. //DEBUG_INFO(" debug 11\n");
  5300. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5301. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5302. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5303. }
  5304. else
  5305. {
  5306. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5307. }
  5308. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  5309. return result;
  5310. }
  5311. int handleGetConfigurationRequest(char *uuid, char *payload)
  5312. {
  5313. mtrace();
  5314. int result = FAIL;
  5315. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  5316. //struct json_object *jsonitem;
  5317. int MaxKeySupported = 0;
  5318. int n_keys = 0;
  5319. char requestKey[43][50]={0};
  5320. char search[]="[";
  5321. char sstr[500]={ 0 };
  5322. //int pos;
  5323. int l, c = 0;
  5324. int i = 0;
  5325. char *delim = "\",\"";
  5326. char * pch;
  5327. char *loc = strstr(payload, search);
  5328. //********************* Parsing String ***********************************/
  5329. if(loc == NULL) {
  5330. DEBUG_INFO("no key match in Configuration \n");
  5331. }
  5332. else {
  5333. //pos = loc - payload;
  5334. l = strlen(loc)-4;
  5335. while (c < l)
  5336. {
  5337. sstr[c] = loc[c+2];
  5338. c++;
  5339. }
  5340. sstr[c] = '\0';
  5341. //parsing strings to words
  5342. pch = strtok(sstr,delim);
  5343. if(pch == NULL)
  5344. {
  5345. strcpy(requestKey[0], sstr);
  5346. }
  5347. else
  5348. {
  5349. while (pch != NULL)
  5350. {
  5351. strcpy(requestKey[i], pch);
  5352. pch = strtok (NULL, delim);
  5353. i = i + 1;
  5354. }
  5355. n_keys = i;
  5356. }
  5357. }
  5358. UnknownKeynum = 0;
  5359. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  5360. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  5361. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  5362. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  5363. if(n_keys != 0)
  5364. {
  5365. for(int i=0;i<n_keys;i++)
  5366. {
  5367. getKeyValue(requestKey[i]);
  5368. //json_object_put(jsonitem);
  5369. }
  5370. }
  5371. else
  5372. {
  5373. DEBUG_INFO("There is no key in Message, get all configuration\n");
  5374. getKeyValue("");
  5375. }
  5376. processUnkownKey();
  5377. sendGetConfigurationConfirmation(uuid);
  5378. return result;
  5379. }
  5380. static char GetDiagnosticspayloadData[300]={0};
  5381. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  5382. {
  5383. mtrace();
  5384. int result = FAIL;
  5385. //void *ret; //
  5386. char fnamePlusPath[100]="";
  5387. char fname[40]="";
  5388. pthread_t t; // pthread 變數
  5389. time_t rawtime;
  5390. struct tm * timeinfo;
  5391. //system("exec /root/Module_WebService 'log' 6"); // for OCTT TEST
  5392. system("exec /root/logPackTools 'log' 6");
  5393. //char buffer [128];
  5394. time (&rawtime);
  5395. //printf("%ld\n", rawtime);
  5396. timeinfo = localtime (&rawtime);
  5397. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5398. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5399. if((access(fnamePlusPath,F_OK))!=-1)
  5400. {
  5401. DEBUG_INFO("fnamePlusPath exist.\n");
  5402. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5403. }
  5404. else
  5405. {
  5406. DEBUG_INFO("fnamePlusPath not exist!\n");
  5407. }
  5408. memset(GetDiagnosticspayloadData, 0, 300);
  5409. strcpy(GetDiagnosticspayloadData, payload);
  5410. sendGetDiagnosticsConfirmation(uuid,fname/*(char*) ret*/);
  5411. pthread_create(&t, NULL, GetDiagnosticsProcess, payload);
  5412. // pthread_join(t, NULL/*&ret*/);
  5413. return result;
  5414. }
  5415. void* GetDiagnosticsProcess(void* data)
  5416. {
  5417. pthread_detach(pthread_self());
  5418. mtrace();
  5419. int retriesInt=0, retryIntervalInt=0;
  5420. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  5421. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  5422. 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};
  5423. int port=0;
  5424. char fnamePlusPath[100]="";//="00000_2019-06-09_160902_CSULog.zip";
  5425. char fname[40]="";
  5426. char sstr[260]={ 0 };//sstr[200]={ 0 };
  5427. int c = 0;
  5428. char *loc;
  5429. int isSuccess = FALSE;
  5430. char ftpbuf[200]={0};
  5431. //char temp[100]={0};
  5432. char * pch;
  5433. // [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"}]
  5434. //char *str = (char*) data; // ? ?輸入資 ?
  5435. char str[300]={ 0 };
  5436. strcpy(str,(const char*)GetDiagnosticspayloadData);
  5437. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  5438. DEBUG_INFO("GetDiagnosticsProcess\n");
  5439. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  5440. //****************location*******************/
  5441. c = 0;
  5442. memset(sstr ,0, sizeof(sstr) );
  5443. loc = strstr(str, "location");
  5444. while (loc[3+strlen("location")+c] != '\"')
  5445. {
  5446. sstr[c] = loc[3+strlen("location")+c];
  5447. c++;
  5448. }
  5449. sstr[c] = '\0';
  5450. strcpy(locationstr,sstr);
  5451. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  5452. if(strcmp(locationstr,"")==0)
  5453. {
  5454. DEBUG_INFO("location is <Empty>!\n");
  5455. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5456. goto end;
  5457. }
  5458. //****************retries*******************/
  5459. c = 0;
  5460. loc = strstr(str, "retries");
  5461. if(loc == NULL)
  5462. {
  5463. retriesIsNULL = TRUE;
  5464. }
  5465. else
  5466. {
  5467. while (loc[strlen("retries")+2+c] != ',')
  5468. {
  5469. sstr[c] = loc[strlen("retries")+2+c];
  5470. c++;
  5471. }
  5472. sstr[c] = '\0';
  5473. retriesInt = atoi(sstr);
  5474. }
  5475. if(retriesIsNULL == TRUE)
  5476. {
  5477. retriesInt = 0;
  5478. }
  5479. //****************retryInterval*******************/
  5480. c = 0;
  5481. loc = strstr(str, "retryInterval");
  5482. if(loc == NULL)
  5483. {
  5484. retryIntervalIsNULL = TRUE;
  5485. }
  5486. else
  5487. {
  5488. while (loc[strlen("retryInterval")+2+c] != ',')
  5489. {
  5490. sstr[c] = loc[strlen("retryInterval")+2+c];
  5491. c++;
  5492. }
  5493. sstr[c] = '\0';
  5494. retryIntervalInt = atoi(sstr);
  5495. }
  5496. //****************startTime*******************/
  5497. c = 0;
  5498. memset(sstr ,0, sizeof(sstr) );
  5499. loc = strstr(str, "startTime");
  5500. if(loc == NULL)
  5501. {
  5502. startTimeIsNULL = TRUE;
  5503. }
  5504. else
  5505. {
  5506. while (loc[3+strlen("startTime")+c] != '\"')
  5507. {
  5508. sstr[c] = loc[3+strlen("startTime")+c];
  5509. c++;
  5510. }
  5511. sstr[c] = '\0';
  5512. strcpy(startTimestr,sstr);
  5513. }
  5514. //****************stopTime*******************/
  5515. c = 0;
  5516. memset(sstr ,0, sizeof(sstr) );
  5517. loc = strstr(str, "stopTime");
  5518. if(loc == NULL)
  5519. {
  5520. stopTimeIsNULL = TRUE;
  5521. }
  5522. else
  5523. {
  5524. while (loc[3+strlen("stopTime")+c] != '\"')
  5525. {
  5526. sstr[c] = loc[3+strlen("stopTime")+c];
  5527. c++;
  5528. }
  5529. sstr[c] = '\0';
  5530. strcpy(stopTimestr,sstr);
  5531. }
  5532. memset(protocol, 0, sizeof(protocol));
  5533. memset(user, 0, sizeof(user) );
  5534. memset(password, 0, sizeof(password));
  5535. memset(host, 0, sizeof(host));
  5536. memset(path, 0, sizeof(path));
  5537. memset(ftppath, 0, sizeof(ftppath));
  5538. memset(host1, 0, sizeof(host1));
  5539. memset(path1, 0, sizeof(path1));
  5540. /*location: ftp://user:password@host:port/path*/
  5541. time_t rawtime;
  5542. struct tm * timeinfo;
  5543. //char buffer [128];
  5544. time (&rawtime);
  5545. //printf("%ld\n", rawtime);
  5546. timeinfo = localtime (&rawtime);
  5547. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  5548. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  5549. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  5550. if((access(fnamePlusPath,F_OK))!=-1)
  5551. {
  5552. DEBUG_INFO("fnamePlusPath exist.\n");
  5553. }
  5554. else
  5555. {
  5556. DEBUG_INFO("fnamePlusPath not exist!\n");
  5557. goto end;
  5558. }
  5559. pch=strchr(locationstr,'@');
  5560. if(pch==NULL)
  5561. {
  5562. sscanf(locationstr,
  5563. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  5564. protocol, host, &port, path);
  5565. strcpy(user,"anonymous");
  5566. strcpy(password,"");
  5567. }
  5568. else
  5569. {
  5570. DEBUG_INFO("pch=%s\n", pch);
  5571. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  5572. protocol, user, password, host, &port, path);
  5573. }
  5574. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  5575. {
  5576. DEBUG_INFO("protocol is not ftp/http ! \n");
  5577. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5578. goto end;
  5579. }
  5580. if(strncmp(locationstr,"http", 4) == 0)
  5581. {
  5582. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  5583. protocol, host, path);
  5584. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  5585. // protocol, user, password, host, path);
  5586. sprintf(ftppath,"/%s", path);
  5587. //DEBUG_INFO("protocol =%s\n",protocol);
  5588. //DEBUG_INFO("host =%s\n",host);
  5589. //DEBUG_INFO("path =%s\n",path);
  5590. //DEBUG_INFO("ftppath=%s\n",ftppath);
  5591. //int ftppathlen=strlen(ftppath);
  5592. //int i=1;
  5593. //char filenametemp[50];
  5594. //while(i < ftppathlen)
  5595. //{
  5596. // int len=ftppathlen-i;
  5597. // if(ftppath[len]== 47) // '/' ascll code: 47
  5598. // {
  5599. // DEBUG_INFO("compare '/' all right\n");
  5600. // break;
  5601. // }
  5602. // i=i+1;
  5603. //}
  5604. //memset(filenametemp, 0, sizeof(filenametemp));
  5605. //strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5606. //filenametemp[i+1] = 0;
  5607. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  5608. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  5609. strftime (fnamePlusPath,sizeof(fnamePlusPath),"/mnt/%4Y-%2m.zip",timeinfo);
  5610. do{
  5611. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);//httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  5612. sleep(retryIntervalInt);
  5613. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  5614. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  5615. if(!isSuccess)
  5616. {
  5617. //BulldogUtil.sleepMs(interval*1000);
  5618. DEBUG_INFO("Diagnostics fail.\n");
  5619. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5620. }
  5621. else
  5622. {
  5623. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5624. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5625. //isUpdateRequest = TRUE;
  5626. }
  5627. }
  5628. else
  5629. {
  5630. sscanf(host,"%[^/]%s",host1, path1);
  5631. sprintf(ftppath,"%s", path1);
  5632. DEBUG_INFO("protocol =%s\n",protocol);
  5633. DEBUG_INFO("user =%s\n",user);
  5634. DEBUG_INFO("password =%s\n",password);
  5635. DEBUG_INFO("host1 =%s\n",host1);
  5636. DEBUG_INFO("port =%d\n",port);
  5637. DEBUG_INFO("path1 =%s\n",path1);
  5638. DEBUG_INFO("ftppath=%s\n",ftppath);
  5639. int ftppathlen=strlen(ftppath);
  5640. int i=1;
  5641. char filenametemp[50];
  5642. while(i < ftppathlen)
  5643. {
  5644. int len=ftppathlen-i;
  5645. if(ftppath[len]== 47) // '/' ascll code: 47
  5646. {
  5647. DEBUG_INFO("find '/' all right\n");
  5648. break;
  5649. }
  5650. i=i+1;
  5651. }
  5652. memset(filenametemp, 0, sizeof(filenametemp));
  5653. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  5654. filenametemp[i+1] = 0;
  5655. memset(ftpbuf, 0, sizeof(ftpbuf));
  5656. if(port == 0)
  5657. port = 21;
  5658. do{
  5659. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fname);
  5660. sleep(retryIntervalInt);
  5661. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  5662. if(!isSuccess)
  5663. {
  5664. //BulldogUtil.sleepMs(interval*1000);
  5665. DEBUG_INFO("Diagnostics fail.\n");
  5666. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  5667. }
  5668. else
  5669. {
  5670. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  5671. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  5672. //isUpdateRequest = TRUE;
  5673. }
  5674. }
  5675. end:
  5676. // json_object_put(obj);
  5677. DiagnosticsStatusNotificationStatus = 0; //Idle
  5678. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  5679. }
  5680. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  5681. {
  5682. mtrace();
  5683. int result = FAIL;
  5684. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  5685. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  5686. {
  5687. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  5688. localversion = -1;
  5689. }
  5690. else
  5691. {
  5692. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  5693. OCPP_getListVerion();
  5694. }
  5695. //from db.OCPP_getListVerion
  5696. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  5697. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  5698. sendGetLocalListVersionConfirmation(uuid,"");
  5699. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  5700. return result;
  5701. }
  5702. int handleRemoteStartRequest(char *uuid, char *payload)
  5703. {
  5704. mtrace();
  5705. int result = FAIL;
  5706. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  5707. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  5708. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  5709. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  5710. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  5711. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  5712. int chargingSchedulePeriodCount = 0;
  5713. char sstr[30]={ 0 };//sstr[200]={ 0 };
  5714. int c = 0;
  5715. char *loc;
  5716. char comfirmstr[20]={0};
  5717. DEBUG_INFO("handleRemoteStartRequest ...\n");
  5718. if(server_pending == TRUE)
  5719. {
  5720. return 0;
  5721. }
  5722. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  5723. //**********connectorId****************/
  5724. c = 0;
  5725. memset(sstr ,0, sizeof(sstr) );
  5726. loc = strstr(payload, "connectorId");
  5727. if(loc == NULL)
  5728. {
  5729. connectorIdIsNULL = TRUE;
  5730. }
  5731. else
  5732. {
  5733. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5734. {
  5735. sstr[c] = loc[strlen("connectorId")+2+c];
  5736. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5737. c++;
  5738. }
  5739. sstr[c] = '\0';
  5740. connectorIdInt = atoi(sstr);
  5741. }
  5742. if(connectorIdIsNULL == TRUE) // need to discussion
  5743. {
  5744. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  5745. goto end;
  5746. }
  5747. //****************idTag*******************/
  5748. c = 0;
  5749. memset(sstr ,0, sizeof(sstr) );
  5750. loc = strstr(payload, "idTag");
  5751. while (loc[3+strlen("idTag")+c] != '\"')
  5752. {
  5753. sstr[c] = loc[3+strlen("idTag")+c];
  5754. c++;
  5755. }
  5756. sstr[c] = '\0';
  5757. strcpy(idTagstr,sstr);
  5758. //****************chargingProfile*******************/
  5759. c = 0;
  5760. memset(sstr ,0, sizeof(sstr) );
  5761. loc = strstr(payload, "chargingProfile");
  5762. if(loc == NULL)
  5763. {
  5764. chargingProfileIsNULL = TRUE;
  5765. }
  5766. else
  5767. {
  5768. //****************chargingProfileId*******************/
  5769. c=0;
  5770. loc = strstr(payload, "chargingProfileId");
  5771. memset(sstr ,0, sizeof(sstr) );
  5772. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  5773. {
  5774. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5776. c++;
  5777. }
  5778. sstr[c] = '\0';
  5779. chargingProfileIdInt = atoi(sstr);
  5780. //****************transactionId*******************/
  5781. loc = strstr(payload, "transactionId");
  5782. if(loc == NULL)
  5783. {
  5784. transactionIdIsNULL = TRUE;
  5785. }
  5786. else
  5787. {
  5788. c=0;
  5789. memset(sstr ,0, sizeof(sstr) );
  5790. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  5791. {
  5792. sstr[c] = loc[strlen("transactionId")+2+c];
  5793. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5794. c++;
  5795. }
  5796. sstr[c] = '\0';
  5797. transactionIdInt = atoi(sstr);
  5798. }
  5799. //****************stackLevel*******************/
  5800. c=0;
  5801. loc = strstr(payload, "stackLevel");
  5802. memset(sstr ,0, sizeof(sstr) );
  5803. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  5804. {
  5805. sstr[c] = loc[strlen("stackLevel")+2+c];
  5806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5807. c++;
  5808. }
  5809. sstr[c] = '\0';
  5810. stackLevelInt = atoi(sstr);
  5811. //****************chargingProfilePurpose*******************/
  5812. c = 0;
  5813. memset(sstr ,0, sizeof(sstr) );
  5814. loc = strstr(payload, "chargingProfilePurpose");
  5815. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5816. {
  5817. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5818. c++;
  5819. }
  5820. sstr[c] = '\0';
  5821. strcpy(chargingProfilePurposestr,sstr);
  5822. //****************chargingProfileKind*******************/
  5823. c = 0;
  5824. memset(sstr ,0, sizeof(sstr) );
  5825. loc = strstr(payload, "chargingProfileKind");
  5826. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  5827. {
  5828. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  5829. c++;
  5830. }
  5831. sstr[c] = '\0';
  5832. strcpy(chargingProfileKindstr,sstr);
  5833. //****************recurrencyKind*******************/
  5834. loc = strstr(payload, "recurrencyKind");
  5835. if(loc == NULL)
  5836. {
  5837. recurrencyKindIsNULL = TRUE;
  5838. }
  5839. else
  5840. {
  5841. c = 0;
  5842. memset(sstr ,0, sizeof(sstr) );
  5843. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  5844. {
  5845. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  5846. c++;
  5847. }
  5848. sstr[c] = '\0';
  5849. strcpy(recurrencyKindstr,sstr);
  5850. }
  5851. //****************validFrom*******************/
  5852. loc = strstr(payload, "validFrom");
  5853. if(loc == NULL)
  5854. {
  5855. validFromIsNULL = TRUE;
  5856. }
  5857. else
  5858. {
  5859. c = 0;
  5860. memset(sstr ,0, sizeof(sstr) );
  5861. while (loc[3+strlen("validFrom")+c] != '\"')
  5862. {
  5863. sstr[c] = loc[3+strlen("validFrom")+c];
  5864. c++;
  5865. }
  5866. sstr[c] = '\0';
  5867. strcpy(validFromstr,sstr);
  5868. }
  5869. //****************validTo*******************/
  5870. loc = strstr(payload, "validTo");
  5871. if(loc == NULL)
  5872. {
  5873. validToIsNULL = TRUE;
  5874. }
  5875. else
  5876. {
  5877. c = 0;
  5878. memset(sstr ,0, sizeof(sstr) );
  5879. while (loc[3+strlen("validTo")+c] != '\"')
  5880. {
  5881. sstr[c] = loc[3+strlen("validTo")+c];
  5882. c++;
  5883. }
  5884. sstr[c] = '\0';
  5885. strcpy(validTostr,sstr);
  5886. }
  5887. //****************chargingSchedule*******************/
  5888. loc = strstr(payload, "chargingSchedule");
  5889. if(loc != NULL)
  5890. {
  5891. //****************duration*******************/
  5892. loc = strstr(payload, "duration");
  5893. if(loc == NULL)
  5894. {
  5895. durationIsNULL = TRUE;
  5896. }
  5897. else
  5898. {
  5899. c=0;
  5900. memset(sstr ,0, sizeof(sstr) );
  5901. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5902. {
  5903. sstr[c] = loc[strlen("duration")+2+c];
  5904. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5905. c++;
  5906. }
  5907. sstr[c] = '\0';
  5908. durationInt = atoi(sstr);
  5909. }
  5910. //****************startSchedule******************/
  5911. loc = strstr(payload, "startSchedule");
  5912. if(loc == NULL)
  5913. {
  5914. startScheduleIsNULL = TRUE;
  5915. }
  5916. else
  5917. {
  5918. c = 0;
  5919. memset(sstr ,0, sizeof(sstr) );
  5920. while (loc[3+strlen("startSchedule")+c] != '\"')
  5921. {
  5922. sstr[c] = loc[3+strlen("startSchedule")+c];
  5923. c++;
  5924. }
  5925. sstr[c] = '\0';
  5926. strcpy(startSchedulestr,sstr);
  5927. }
  5928. //****************chargingRateUnit*******************/
  5929. c = 0;
  5930. memset(sstr ,0, sizeof(sstr) );
  5931. loc = strstr(payload, "chargingRateUnit");
  5932. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5933. {
  5934. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5935. c++;
  5936. }
  5937. sstr[c] = '\0';
  5938. strcpy(chargingRateUnitstr,sstr);
  5939. //****************minChargingRate*******************/
  5940. loc = strstr(payload, "minChargingRate");
  5941. if(loc == NULL)
  5942. {
  5943. minChargingRateIsNULL = TRUE;
  5944. }
  5945. else
  5946. {
  5947. c=0;
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  5950. {
  5951. sstr[c] = loc[strlen("minChargingRate")+2+c];
  5952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5953. c++;
  5954. }
  5955. sstr[c] = '\0';
  5956. minChargingRateflaot = atof(sstr);
  5957. }
  5958. //****************chargingSchedulePeriod count*******************/
  5959. int what_len = strlen("startPeriod");
  5960. char *where = payload;
  5961. while ((where = strstr(where, "startPeriod"))) {
  5962. where += what_len;
  5963. chargingSchedulePeriodCount++;
  5964. }
  5965. where = payload;
  5966. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  5967. {
  5968. //****************startPeriod*******************/
  5969. c=0;
  5970. loc = strstr(where, "startPeriod");
  5971. memset(sstr ,0, sizeof(sstr) );
  5972. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  5973. {
  5974. sstr[c] = loc[strlen("startPeriod")+2+c];
  5975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5976. c++;
  5977. }
  5978. sstr[c] = '\0';
  5979. startPeriodInt[periodNums] = atoi(sstr);
  5980. //****************limit*******************/
  5981. c=0;
  5982. loc = strstr(where, "limit");
  5983. memset(sstr ,0, sizeof(sstr) );
  5984. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  5985. {
  5986. sstr[c] = loc[strlen("limit")+2+c];
  5987. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5988. c++;
  5989. }
  5990. sstr[c] = '\0';
  5991. limitflaot[periodNums] = atof(sstr);
  5992. //****************numberPhases*******************/
  5993. loc = strstr(where, "numberPhases");
  5994. if(loc == NULL)
  5995. {
  5996. numberPhasesIsNULL = TRUE;
  5997. }
  5998. else
  5999. {
  6000. c=0;
  6001. memset(sstr ,0, sizeof(sstr) );
  6002. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6003. {
  6004. sstr[c] = loc[strlen("numberPhases")+2+c];
  6005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6006. c++;
  6007. }
  6008. sstr[c] = '\0';
  6009. numberPhasesInt[periodNums] = atoi(sstr);
  6010. }
  6011. where = loc;
  6012. }
  6013. }
  6014. }
  6015. /*
  6016. enum _SYSTEM_STATUS
  6017. {
  6018. S_BOOTING = 0,
  6019. S_IDLE, = 1
  6020. S_AUTHORIZING, =2
  6021. S_REASSIGN_CHECK, =3
  6022. S_REASSIGN, =4
  6023. S_PRECHARGE, =5
  6024. S_PREPARING_FOR_EV, =6
  6025. S_PREPARING_FOR_EVSE, =7
  6026. S_CHARGING, =8
  6027. S_TERMINATING, =9
  6028. S_COMPLETE, =10
  6029. S_ALARM, =11
  6030. S_FAULT =12
  6031. }
  6032. */
  6033. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6034. {
  6035. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6036. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6037. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6038. //check Transaction active
  6039. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6040. {
  6041. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6042. {
  6043. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6044. {
  6045. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6046. {
  6047. //Reserved
  6048. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6049. }
  6050. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6051. {
  6052. //Reserved
  6053. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6054. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6055. goto end;
  6056. }
  6057. else
  6058. {
  6059. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6060. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6061. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6062. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6063. {
  6064. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6065. goto end;
  6066. }
  6067. }//END FOR ELSE
  6068. }
  6069. }// END FOR CHAdeMO_QUANTITY
  6070. for (int index = 0; index < CCS_QUANTITY; index++)
  6071. {
  6072. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6073. {
  6074. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6075. {
  6076. //Reserved
  6077. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6078. }
  6079. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6080. {
  6081. //Reserved
  6082. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6083. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6084. goto end;
  6085. }
  6086. else
  6087. {
  6088. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6089. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6090. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6091. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6092. {
  6093. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6094. goto end;
  6095. }
  6096. }// END FOR ELSE
  6097. }
  6098. }// END FOR CCS_QUANTITY
  6099. for (int index = 0; index < GB_QUANTITY; index++)
  6100. {
  6101. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  6102. {
  6103. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6104. {
  6105. //Reserved
  6106. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6107. }
  6108. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6109. {
  6110. //Reserved
  6111. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6112. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6113. goto end;
  6114. }
  6115. else
  6116. {
  6117. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6118. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6119. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6120. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6121. {
  6122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6123. goto end;
  6124. }
  6125. }// END FOR ELSE
  6126. }
  6127. } // END FOR GB_QUANTITY
  6128. }
  6129. else
  6130. {
  6131. for (int index = 0; index < AC_QUANTITY; index++)
  6132. {
  6133. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6134. {
  6135. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  6136. {
  6137. //Reserved
  6138. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6139. }
  6140. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  6141. {
  6142. //Reserved
  6143. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6144. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6145. goto end;
  6146. }
  6147. else
  6148. {
  6149. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6150. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6151. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6152. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6153. {
  6154. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6155. goto end;
  6156. }
  6157. }//END FOR ELSE
  6158. }
  6159. }// END FOR AC_QUANTITY
  6160. }
  6161. if(chargingProfileIsNULL == FALSE)
  6162. {
  6163. //ChargingProfile
  6164. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6166. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6167. if(recurrencyKindIsNULL == FALSE) //OPTION
  6168. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6169. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6170. if(transactionIdIsNULL == FALSE) // OPTION
  6171. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6172. if(validFromIsNULL == FALSE) // OPTION
  6173. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6174. if(validToIsNULL == FALSE) //OPTION
  6175. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6176. //ChargingSchedule
  6177. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6178. if(durationIsNULL == FALSE) //OPTION
  6179. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6180. if(minChargingRateIsNULL == FALSE) //OPTION
  6181. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6182. if(startScheduleIsNULL == FALSE) //OPTION
  6183. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6184. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6185. {
  6186. //ChargingSchedulePeriod
  6187. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6188. if(numberPhasesIsNULL == FALSE)
  6189. {
  6190. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6191. }
  6192. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6193. }
  6194. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6195. {
  6196. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6197. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6198. //memset idTag
  6199. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6200. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6201. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6202. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6203. }
  6204. else
  6205. {
  6206. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6207. }
  6208. }
  6209. else
  6210. {
  6211. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6212. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6213. //memset idTag
  6214. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6215. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6216. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6217. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6218. }
  6219. }
  6220. else
  6221. {
  6222. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6223. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6224. }
  6225. end:
  6226. if(connectorIdIsNULL == FALSE)
  6227. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6228. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6229. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6230. //OCPP send RemoteStartConfirmation by first.
  6231. sendRemoteStartConfirmation(uuid, comfirmstr);
  6232. return result;
  6233. }
  6234. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6235. {
  6236. mtrace();
  6237. int result = FAIL;
  6238. int match = FALSE;
  6239. int GunNO = 0;
  6240. int transactionIdInt=0;
  6241. int transactionIdIsNULL= FALSE;
  6242. char sstr[16]={ 0 };//sstr[200]={ 0 };
  6243. int c = 0;
  6244. char *loc;
  6245. char comfirmstr[20];
  6246. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6247. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6248. if(server_pending == TRUE)
  6249. {
  6250. return 0;
  6251. }
  6252. c=0;
  6253. loc = strstr(payload, "transactionId");
  6254. if(loc == NULL)
  6255. {
  6256. transactionIdIsNULL= TRUE;
  6257. }
  6258. else
  6259. {
  6260. memset(sstr ,0, sizeof(sstr) );
  6261. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6262. {
  6263. sstr[c] = loc[strlen("transactionId")+2+c];
  6264. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6265. c++;
  6266. }
  6267. sstr[c] = '\0';
  6268. transactionIdInt = atoi(sstr);
  6269. }
  6270. if(transactionIdIsNULL == FALSE)
  6271. {
  6272. for(int gun_index=0;gun_index < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;gun_index++)
  6273. {
  6274. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6275. {
  6276. //check Transaction active
  6277. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6278. {
  6279. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6280. {
  6281. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6282. {
  6283. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6284. {
  6285. match = TRUE;
  6286. GunNO = gun_index;
  6287. }
  6288. }
  6289. }// END FOR CHAdeMO_QUANTITY
  6290. for (int index = 0; index < CCS_QUANTITY; index++)
  6291. {
  6292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6293. {
  6294. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6295. {
  6296. match = TRUE;
  6297. GunNO = gun_index;
  6298. }
  6299. }
  6300. }// END FOR CCS_QUANTITY
  6301. for (int index = 0; index < GB_QUANTITY; index++)
  6302. {
  6303. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6304. {
  6305. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6306. {
  6307. match = TRUE;
  6308. GunNO = gun_index;
  6309. }
  6310. }
  6311. }// END FOR GB_QUANTITY
  6312. }
  6313. else
  6314. {
  6315. for (int index = 0; index < AC_QUANTITY; index++)
  6316. {
  6317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6318. {
  6319. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  6320. {
  6321. match = TRUE;
  6322. GunNO = gun_index;
  6323. }
  6324. }
  6325. }// END FOR CHAdeMO_QUANTITY
  6326. }// END FOR AC ELSE
  6327. }// CHECK IF ResponseTransactionId == transactionIdInt
  6328. }//END FOR
  6329. if( match == TRUE)
  6330. {
  6331. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  6332. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6333. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  6334. }
  6335. else
  6336. {
  6337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6338. }
  6339. }
  6340. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  6341. return result;
  6342. }
  6343. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  6344. {
  6345. mtrace();
  6346. int result = FAIL;
  6347. int connectorIdInt=0, reservationIdInt=0;
  6348. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  6349. char comfirmstr[20]={0};
  6350. char sstr[180]={ 0 };
  6351. int c = 0;
  6352. char *loc;
  6353. //char *ptr;
  6354. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  6355. //***(1)connectorId ****/
  6356. c=0;
  6357. loc = strstr(payload, "connectorId");
  6358. memset(sstr ,0, sizeof(sstr) );
  6359. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ','))
  6360. {
  6361. sstr[c] = loc[strlen("connectorId")+2+c];
  6362. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6363. c++;
  6364. }
  6365. sstr[c] = '\0';
  6366. connectorIdInt = atoi(sstr);
  6367. //***(2)expiryDate ****/
  6368. loc = strstr(payload, "expiryDate");
  6369. memset(sstr ,0, sizeof(sstr) );
  6370. c = 0;
  6371. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  6372. {
  6373. sstr[c] = loc[3+strlen("expiryDate")+c];
  6374. c++;
  6375. }
  6376. sstr[c] = '\0';
  6377. strcpy(expiryDatestr, sstr);
  6378. //***(3)idTag ****/
  6379. loc = strstr(payload, "idTag");
  6380. memset(sstr ,0, sizeof(sstr) );
  6381. c = 0;
  6382. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  6383. {
  6384. sstr[c] = loc[3+strlen("idTag")+c];
  6385. c++;
  6386. }
  6387. sstr[c] = '\0';
  6388. strcpy(idTagstr, sstr);
  6389. //***(4)parentIdTag ****/
  6390. loc = strstr(payload, "parentIdTag");
  6391. memset(sstr ,0, sizeof(sstr) );
  6392. c = 0;
  6393. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  6394. {
  6395. sstr[c] = loc[3+strlen("parentIdTag")+c];
  6396. c++;
  6397. }
  6398. sstr[c] = '\0';
  6399. strcpy(parentIdTagstr, sstr);
  6400. //***(5)reservationId ****/
  6401. c=0;
  6402. loc = strstr(payload, "reservationId");
  6403. memset(sstr ,0, sizeof(sstr) );
  6404. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  6405. {
  6406. sstr[c] = loc[strlen("reservationId")+2+c];
  6407. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6408. c++;
  6409. }
  6410. sstr[c] = '\0';
  6411. reservationIdInt = atoi(sstr);
  6412. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6413. /*
  6414. enum _SYSTEM_STATUS
  6415. {
  6416. S_BOOTING = 0,
  6417. S_IDLE, = 1
  6418. S_AUTHORIZING, =2
  6419. S_REASSIGN_CHECK, =3
  6420. S_REASSIGN, =4
  6421. S_PRECHARGE, =5
  6422. S_PREPARING_FOR_EV, =6
  6423. S_PREPARING_FOR_EVSE, =7
  6424. S_CHARGING, =8
  6425. S_TERMINATING, =9
  6426. S_COMPLETE, =10
  6427. S_ALARM, =11
  6428. S_FAULT =12
  6429. }
  6430. */
  6431. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  6432. {
  6433. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6434. goto end;
  6435. }
  6436. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  6437. {
  6438. //check Transaction active
  6439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6440. {
  6441. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6442. {
  6443. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  6444. {
  6445. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6446. {
  6447. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6448. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6449. {
  6450. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6451. {
  6452. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6454. }
  6455. 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'))
  6456. {
  6457. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6458. }
  6459. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6460. {
  6461. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6462. }
  6463. else
  6464. {
  6465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6466. }
  6467. }
  6468. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6469. {
  6470. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6471. }
  6472. }
  6473. else
  6474. {
  6475. //replace reservation
  6476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6477. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6478. }
  6479. }
  6480. } // END FOR CHAdeMO_QUANTITY
  6481. for (int index = 0; index < CCS_QUANTITY; index++)
  6482. {
  6483. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  6484. {
  6485. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6486. {
  6487. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6488. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6489. {
  6490. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6491. {
  6492. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6493. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6494. }
  6495. 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'))
  6496. {
  6497. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6498. }
  6499. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6500. {
  6501. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6502. }
  6503. else
  6504. {
  6505. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6506. }
  6507. }
  6508. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6509. {
  6510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6511. }
  6512. }
  6513. else
  6514. {
  6515. //replace reservation
  6516. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6518. }
  6519. }
  6520. } // END FOR CCS_QUANTITY
  6521. for (int index = 0; index < GB_QUANTITY; index++)
  6522. {
  6523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt - 1))
  6524. {
  6525. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6526. {
  6527. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6528. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6529. {
  6530. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6531. {
  6532. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6534. }
  6535. 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'))
  6536. {
  6537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6538. }
  6539. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6540. {
  6541. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6542. }
  6543. else
  6544. {
  6545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6546. }
  6547. }
  6548. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6549. {
  6550. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6551. }
  6552. }
  6553. else
  6554. {
  6555. //replace reservation
  6556. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6558. }
  6559. }
  6560. }// END FOR GB_QUANTITY
  6561. }
  6562. else
  6563. {
  6564. for (int index = 0; index < AC_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt -1))
  6567. {
  6568. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6569. {
  6570. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  6571. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT) //S_FAULT
  6572. {
  6573. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  6574. {
  6575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6577. }
  6578. 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'))
  6579. {
  6580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6581. }
  6582. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6583. {
  6584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6585. }
  6586. else
  6587. {
  6588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6589. }
  6590. }
  6591. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6592. {
  6593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6594. }
  6595. }
  6596. else
  6597. {
  6598. //replace reservation
  6599. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  6600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6601. }
  6602. }
  6603. } // END FOR AC_QUANTITY
  6604. }//END FOR AC ELSE
  6605. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6606. }
  6607. else if(connectorIdInt == 0)
  6608. {
  6609. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6610. {
  6611. //check Transaction active
  6612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6613. {
  6614. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  6615. {
  6616. 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'))
  6617. {
  6618. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6619. goto end;
  6620. }
  6621. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6622. {
  6623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6624. goto end;
  6625. }
  6626. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6627. {
  6628. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6629. goto end;
  6630. }
  6631. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6632. {
  6633. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6634. goto end;
  6635. }
  6636. }
  6637. }// END FOR CHAdeMO_QUANTITY
  6638. for (int index = 0; index < CCS_QUANTITY; index++)
  6639. {
  6640. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  6641. {
  6642. 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'))
  6643. {
  6644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6645. }
  6646. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6647. {
  6648. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6649. }
  6650. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6651. {
  6652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6653. }
  6654. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6655. {
  6656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6657. }
  6658. }
  6659. } // END FOR CCS_QUANTITY
  6660. for (int index = 0; index < GB_QUANTITY; index++)
  6661. {
  6662. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  6663. {
  6664. 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'))
  6665. {
  6666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6667. }
  6668. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6669. {
  6670. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6671. }
  6672. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) //S_FAULT
  6673. {
  6674. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6675. }
  6676. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6677. {
  6678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6679. }
  6680. }
  6681. } // END FOR GB_QUANTITY
  6682. }
  6683. else
  6684. {
  6685. for (int index = 0; index < AC_QUANTITY; index++)
  6686. {
  6687. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  6688. {
  6689. 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'))
  6690. {
  6691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  6692. goto end;
  6693. }
  6694. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  6695. {
  6696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  6697. goto end;
  6698. }
  6699. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT
  6700. {
  6701. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  6702. goto end;
  6703. }
  6704. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6705. {
  6706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6707. goto end;
  6708. }
  6709. }
  6710. }// END FOR AC_QUANTITY
  6711. }
  6712. //The connectorId is 0
  6713. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  6714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  6715. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  6716. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  6717. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  6718. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  6719. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  6720. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  6721. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  6722. result = TRUE;
  6723. return result;
  6724. }
  6725. else
  6726. {
  6727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  6728. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  6729. }
  6730. if(strcmp(comfirmstr,"Accepted") == 0)
  6731. {
  6732. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  6733. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  6734. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  6735. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  6736. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  6737. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  6738. result = TRUE;
  6739. return result;
  6740. }
  6741. end:
  6742. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  6743. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  6744. return result;
  6745. }
  6746. int handleResetRequest(char *uuid, char *payload)
  6747. {
  6748. mtrace();
  6749. int result = FAIL;
  6750. char sstr[10]={0};
  6751. char typestr[10]={0};
  6752. char comfirmstr[20]={0};
  6753. int c = 0;
  6754. char *loc;
  6755. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  6756. DEBUG_INFO("handleResetRequest ...\n");
  6757. loc = strstr(payload, "type");
  6758. memset(sstr ,0, sizeof(sstr) );
  6759. c = 0;
  6760. while (loc[3+strlen("type")+c] != '\"')
  6761. {
  6762. sstr[c] = loc[3+strlen("type")+c];
  6763. c++;
  6764. }
  6765. sstr[c] = '\0';
  6766. strcpy(typestr,sstr);
  6767. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  6768. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  6769. if(strcmp(typestr, ResetTypeStr[Hard])==0)
  6770. {
  6771. //check Transaction active
  6772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6773. {
  6774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6775. {
  6776. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6777. {
  6778. //0: unplug, 1: Plug-in
  6779. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6780. }
  6781. }
  6782. for (int index = 0; index < CCS_QUANTITY; index++)
  6783. {
  6784. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6785. {
  6786. //0: unplug, 1: Plug-in
  6787. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6788. }
  6789. }
  6790. for (int index = 0; index < GB_QUANTITY; index++)
  6791. {
  6792. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6793. {
  6794. //0: unplug, 1: Plug-in
  6795. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6796. }
  6797. }
  6798. }
  6799. else
  6800. {
  6801. for (int index = 0; index < AC_QUANTITY; index++)
  6802. {
  6803. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6804. {
  6805. //0: unplug, 1: Plug-in
  6806. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6807. }
  6808. }
  6809. }// END FOR AC ELSE
  6810. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6811. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6812. result = TRUE;
  6813. return result;
  6814. }
  6815. else if(strcmp(typestr, ResetTypeStr[Soft])==0)
  6816. {
  6817. //check Transaction active
  6818. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6819. {
  6820. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6821. {
  6822. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6823. {
  6824. //0: unplug, 1: Plug-in
  6825. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6826. }
  6827. }
  6828. for (int index = 0; index < CCS_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6831. {
  6832. //0: unplug, 1: Plug-in
  6833. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn = 0;
  6834. }
  6835. }
  6836. for (int index = 0; index < GB_QUANTITY; index++)
  6837. {
  6838. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6839. {
  6840. //0: unplug, 1: Plug-in
  6841. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn = 0;
  6842. }
  6843. }
  6844. }
  6845. else
  6846. {
  6847. for (int index = 0; index < AC_QUANTITY; index++)
  6848. {
  6849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6850. {
  6851. //0: unplug, 1: Plug-in
  6852. //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn = 0;
  6853. }
  6854. }
  6855. }// END FOR AC ELSE
  6856. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  6857. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  6858. result = TRUE;
  6859. return result;
  6860. }
  6861. else
  6862. {
  6863. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  6864. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  6865. goto errorend;
  6866. }
  6867. errorend:
  6868. sendResetConfirmation(uuid, comfirmstr);
  6869. return result;
  6870. }
  6871. int handleSendLocalListRequest(char *uuid, char *payload)
  6872. {
  6873. mtrace();
  6874. int result = FAIL;
  6875. int listVersionInt;
  6876. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  6877. char listsearch[]="listVersion";
  6878. char updateTypesearch[]="updateType";
  6879. char localAuthorizationListsearch[]="localAuthorizationList";
  6880. char sstr[60500]={ 0 };//sstr[200]={ 0 };
  6881. char CardList[500][160]={0};
  6882. char updateTypestr[15]={0};
  6883. char idTagstr[20]={0};
  6884. char parentIdTag[20]={0};
  6885. char expiryDate[30]={0};
  6886. char idTagstatus[16]={0};
  6887. int c = 0;
  6888. int i = 0;
  6889. char *delim1 = "}";
  6890. char * pch;
  6891. char *loc;
  6892. //char *ptr;
  6893. char comfirmstr[20];
  6894. //int n_localAuthorizations = 0;
  6895. int checkState_Faulted = FALSE;
  6896. DEBUG_INFO("handleSendLocalListRequest\n");
  6897. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  6898. {
  6899. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6900. goto end;
  6901. }
  6902. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6903. {
  6904. //check Charge Point state
  6905. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6906. {
  6907. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6908. {
  6909. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6910. }
  6911. }
  6912. for (int index = 0; index < CCS_QUANTITY; index++)
  6913. {
  6914. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6915. {
  6916. checkState_Faulted = TRUE; //OCPP Status
  6917. }
  6918. }
  6919. for (int index = 0; index < GB_QUANTITY; index++)
  6920. {
  6921. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6922. {
  6923. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6924. }
  6925. }
  6926. }
  6927. else
  6928. {
  6929. //check Charge Point state
  6930. for (int index = 0; index < AC_QUANTITY; index++)
  6931. {
  6932. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  6933. {
  6934. checkState_Faulted = TRUE; //OCPP Status: Faulted
  6935. }
  6936. }
  6937. }// END FOR AC ELSE
  6938. if(checkState_Faulted == TRUE)
  6939. {
  6940. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  6941. goto end;
  6942. }
  6943. //listVersion
  6944. c = 0;
  6945. loc = strstr(payload, listsearch);
  6946. while (loc[strlen("listVersion")+2+c] != ',')
  6947. {
  6948. sstr[c] = loc[strlen("listVersion")+2+c];
  6949. c++;
  6950. }
  6951. sstr[c] = '\0';
  6952. listVersionInt = atoi(sstr);
  6953. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  6954. //updateType
  6955. loc = strstr(payload, updateTypesearch);
  6956. c = 0;
  6957. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  6958. {
  6959. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  6960. c++;
  6961. }
  6962. sstr[c] = '\0';
  6963. strcpy(updateTypestr, sstr);
  6964. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  6965. //localAuthorizationList
  6966. memset(sstr ,0, sizeof(sstr) );
  6967. loc = strstr(payload, localAuthorizationListsearch);
  6968. if(loc != NULL) // localAuthorizationList is not NULL
  6969. {
  6970. //Check UpdateType
  6971. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  6972. {
  6973. //Local list full update
  6974. printf("Local list full update.\n");
  6975. OCPP_cleanLocalList();
  6976. }
  6977. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  6978. {
  6979. //Local list different update
  6980. printf("Local list different update.\n");
  6981. OCPP_getListVerion();
  6982. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  6983. {
  6984. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  6985. goto end;
  6986. }
  6987. }
  6988. else
  6989. {
  6990. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  6991. goto end;
  6992. }
  6993. c = 0;
  6994. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  6995. {
  6996. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  6997. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6998. c++;
  6999. }
  7000. sstr[c] = '\0';
  7001. //DEBUG_INFO("sstr=%s\n", sstr);
  7002. //parsing strings to words
  7003. i = 0;
  7004. pch = strtok(sstr,delim1);
  7005. while (pch != NULL)
  7006. {
  7007. strcpy(CardList[i], pch);
  7008. DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7009. pch = strtok (NULL, delim1);
  7010. i = i + 1;
  7011. }
  7012. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7013. //local Authorizations List Numbers
  7014. //n_localAuthorizations = i;
  7015. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7016. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7017. c= 0;
  7018. while(c < i)
  7019. {
  7020. //Search "IdToken"
  7021. memset(sstr ,0, sizeof(sstr) );
  7022. loc = strstr(CardList[c], "idTag");
  7023. int j = 0;
  7024. while (loc[3+strlen("idTag")+j] != '\"')
  7025. {
  7026. sstr[j] = loc[3+strlen("idTag")+j];
  7027. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7028. j++;
  7029. }
  7030. sstr[j] = '\0';
  7031. strcpy(idTagstr, sstr);
  7032. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7033. //Search "expiryDate"
  7034. memset(sstr ,0, sizeof(sstr) );
  7035. loc = strstr(CardList[c], "expiryDate");
  7036. j = 0;
  7037. if(loc != NULL)
  7038. {
  7039. while (loc[3+strlen("expiryDate")+j] != '\"')
  7040. {
  7041. sstr[j] = loc[3+strlen("expiryDate")+j];
  7042. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7043. j++;
  7044. }
  7045. sstr[j] = '\0';
  7046. strcpy(expiryDate, sstr);
  7047. }
  7048. else
  7049. {
  7050. strcpy(expiryDate, "");
  7051. }
  7052. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7053. //Search "parentIdTag"
  7054. memset(sstr ,0, sizeof(sstr) );
  7055. loc = strstr(CardList[c], "parentIdTag");
  7056. j = 0;
  7057. if(loc != NULL)
  7058. {
  7059. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7060. {
  7061. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7062. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7063. j++;
  7064. }
  7065. sstr[j] = '\0';
  7066. strcpy(parentIdTag, sstr);
  7067. }
  7068. else
  7069. {
  7070. strcpy(parentIdTag, "");
  7071. }
  7072. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7073. //Search "status"
  7074. memset(sstr ,0, sizeof(sstr) );
  7075. loc = strstr(CardList[c], "status");
  7076. j = 0;
  7077. while (loc[3+strlen("status")+j] != '\"')
  7078. {
  7079. sstr[j] = loc[3+strlen("status")+j];
  7080. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7081. j++;
  7082. }
  7083. sstr[j] = '\0';
  7084. strcpy(idTagstatus, sstr);
  7085. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7086. OCPP_getIdTag(idTagstr);
  7087. //OCPP_getIdTag("test"); For Test
  7088. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7089. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7090. {
  7091. //Local list full update
  7092. DEBUG_INFO("Local list full update.\n");
  7093. // update list
  7094. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7095. OCPP_get_TableAuthlocalAllData();
  7096. }
  7097. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7098. {
  7099. if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] != '\0'))
  7100. {
  7101. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7102. }
  7103. else if((strcmp(idTagstr, idTagAuthorization) == 0) && (parentIdTag[0] == '\0'))
  7104. {
  7105. OCPP_deleteIdTag(idTagstr);
  7106. }
  7107. else if((strcmp(idTagstr, idTagAuthorization) != 0) && (parentIdTag[0] != '\0'))
  7108. {
  7109. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7110. }
  7111. }
  7112. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7113. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7114. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7115. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7116. c++;
  7117. }
  7118. }
  7119. else
  7120. {
  7121. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7122. {
  7123. //Local list different update
  7124. DEBUG_INFO("Local list different update.\n");
  7125. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7126. goto end;
  7127. }
  7128. }
  7129. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7130. end:
  7131. sendSendLocalListConfirmation(uuid, comfirmstr);
  7132. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7133. #if 0
  7134. if(ShmOCPP16Data->SendLocalList.LocalAuthorizationList != NULL)
  7135. free(ShmOCPP16Data->SendLocalList.LocalAuthorizationList);
  7136. #endif
  7137. return result;
  7138. }
  7139. /*
  7140. enum _SYSTEM_STATUS
  7141. {
  7142. S_BOOTING = 0,
  7143. S_IDLE, =1
  7144. S_AUTHORIZING, =2
  7145. S_REASSIGN_CHECK, =3
  7146. S_REASSIGN, =4
  7147. S_PRECHARGE, =5
  7148. S_PREPARING_FOR_EV, =6
  7149. S_PREPARING_FOR_EVSE, =7
  7150. S_CHARGING, =8
  7151. S_TERMINATING, =9
  7152. S_COMPLETE, =10
  7153. S_ALARM, =11
  7154. S_FAULT =12
  7155. };
  7156. */
  7157. #define MAX 200
  7158. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7159. {
  7160. mtrace();
  7161. int result = FAIL;
  7162. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7163. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7164. char chargingProfilePurposeStr[30]={0};
  7165. char chargingProfileKindStr[16]={0};
  7166. char recurrencyKindStr[10]={0};
  7167. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7168. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7169. int chargingSchedulePeriodCount = 0;
  7170. //int updateflag = FALSE;
  7171. char comfirmstr[20]={0};
  7172. int meet= FALSE;
  7173. char sstr[10]={0};
  7174. int c = 0;
  7175. char *loc;
  7176. FILE *fptr1;//, *fptr2;
  7177. //int lno=0;//, linectr = 0;
  7178. //int modifyflag = FALSE;
  7179. char filename[MAX]={0};
  7180. char tempfile[] = "../Storage/OCPP/temp.json";
  7181. //int resultRename=0;
  7182. char rmFileCmd[50]={0};
  7183. char tempchargingProfilePurposeStr[30]={0};
  7184. //[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}}}]
  7185. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7186. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7187. //*********************connectorId***************************/
  7188. loc = strstr(payload, "connectorId");
  7189. c = 0;
  7190. memset(sstr ,0, sizeof(sstr) );
  7191. while (loc[strlen("connectorId")+2+c] != ',')
  7192. {
  7193. sstr[c] = loc[strlen("connectorId")+2+c];
  7194. c++;
  7195. }
  7196. sstr[c] = '\0';
  7197. connectorIdInt = atoi(sstr);
  7198. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7199. {
  7200. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7201. }
  7202. else
  7203. {
  7204. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7205. }
  7206. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7207. //*********************chargingProfileId***************************/
  7208. loc = strstr(payload, "chargingProfileId");
  7209. c = 0;
  7210. memset(sstr ,0, sizeof(sstr) );
  7211. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7212. {
  7213. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7214. c++;
  7215. }
  7216. sstr[c] = '\0';
  7217. chargingProfileIdInt = atoi(sstr);
  7218. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7219. {
  7220. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7221. }
  7222. else
  7223. {
  7224. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7225. }
  7226. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7227. //*********************transactionId***************************/
  7228. loc = strstr(payload, "transactionId");
  7229. if(loc != NULL)
  7230. {
  7231. c = 0;
  7232. memset(sstr ,0, sizeof(sstr) );
  7233. while (loc[strlen("transactionId")+2+c] != ',')
  7234. {
  7235. sstr[c] = loc[strlen("transactionId")+2+c];
  7236. c++;
  7237. }
  7238. sstr[c] = '\0';
  7239. transactionIdInt = atoi(sstr);
  7240. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7241. {
  7242. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7243. }
  7244. else
  7245. {
  7246. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7247. }
  7248. }
  7249. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7250. //*********************stackLevel***************************/
  7251. loc = strstr(payload, "stackLevel");
  7252. c = 0;
  7253. memset(sstr ,0, sizeof(sstr) );
  7254. while (loc[strlen("stackLevel")+2+c] != ',')
  7255. {
  7256. sstr[c] = loc[strlen("stackLevel")+2+c];
  7257. c++;
  7258. }
  7259. sstr[c] = '\0';
  7260. stackLevelInt = atoi(sstr);
  7261. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7262. {
  7263. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7264. }
  7265. else
  7266. {
  7267. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7268. }
  7269. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7270. //*********************chargingProfilePurpose***************************/
  7271. loc = strstr(payload, "chargingProfilePurpose");
  7272. c = 0;
  7273. memset(sstr ,0, sizeof(sstr) );
  7274. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7275. {
  7276. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7277. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7278. c++;
  7279. }
  7280. sstr[c] = '\0';
  7281. strcpy(chargingProfilePurposeStr,sstr);
  7282. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  7283. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7284. {
  7285. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7286. }
  7287. else
  7288. {
  7289. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  7290. }
  7291. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  7292. //*********************chargingProfileKind***************************/
  7293. loc = strstr(payload, "chargingProfileKind");
  7294. c = 0;
  7295. memset(sstr ,0, sizeof(sstr) );
  7296. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  7297. {
  7298. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  7299. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7300. c++;
  7301. }
  7302. sstr[c] = '\0';
  7303. strcpy(chargingProfileKindStr,sstr);
  7304. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7305. {
  7306. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7307. }
  7308. else
  7309. {
  7310. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  7311. }
  7312. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  7313. //*********************recurrencyKind***************************/
  7314. loc = strstr(payload, "recurrencyKind");
  7315. if(loc != NULL)
  7316. {
  7317. c = 0;
  7318. memset(sstr ,0, sizeof(sstr) );
  7319. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  7320. {
  7321. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  7322. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7323. c++;
  7324. }
  7325. sstr[c] = '\0';
  7326. strcpy(recurrencyKindStr,sstr);
  7327. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7328. {
  7329. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7330. }
  7331. else
  7332. {
  7333. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  7334. }
  7335. }
  7336. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  7337. //*********************validFrom***************************/
  7338. loc = strstr(payload, "validFrom");
  7339. if(loc != NULL)
  7340. {
  7341. c = 0;
  7342. memset(sstr ,0, sizeof(sstr) );
  7343. while (loc[3+strlen("validFrom")+c] != '\"')
  7344. {
  7345. sstr[c] = loc[3+strlen("validFrom")+c];
  7346. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7347. c++;
  7348. }
  7349. sstr[c] = '\0';
  7350. strcpy(validFromStr,sstr);
  7351. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7352. {
  7353. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  7354. }
  7355. else
  7356. {
  7357. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  7358. }
  7359. }
  7360. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  7361. //*********************validTo***************************/
  7362. loc = strstr(payload, "validTo");
  7363. if(loc != NULL)
  7364. {
  7365. c = 0;
  7366. memset(sstr ,0, sizeof(sstr) );
  7367. while (loc[3+strlen("validTo")+c] != '\"')
  7368. {
  7369. sstr[c] = loc[3+strlen("validTo")+c];
  7370. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. strcpy(validToStr,sstr);
  7375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7376. {
  7377. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  7378. }
  7379. else
  7380. {
  7381. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  7382. }
  7383. }
  7384. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  7385. //*********************duration***************************/
  7386. loc = strstr(payload, "duration");
  7387. if(loc != NULL)
  7388. {
  7389. c = 0;
  7390. memset(sstr ,0, sizeof(sstr) );
  7391. while (loc[strlen("duration")+2+c] != ',')
  7392. {
  7393. sstr[c] = loc[strlen("duration")+2+c];
  7394. c++;
  7395. }
  7396. sstr[c] = '\0';
  7397. durationInt = atoi(sstr);
  7398. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7399. {
  7400. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7401. }
  7402. else
  7403. {
  7404. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7405. }
  7406. }
  7407. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  7408. //*********************startSchedule***************************/
  7409. loc = strstr(payload, "startSchedule");
  7410. if(loc != NULL)
  7411. {
  7412. c = 0;
  7413. memset(sstr ,0, sizeof(sstr) );
  7414. while (loc[3+strlen("startSchedule")+c] != '\"')
  7415. {
  7416. sstr[c] = loc[3+strlen("startSchedule")+c];
  7417. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7418. c++;
  7419. }
  7420. sstr[c] = '\0';
  7421. strcpy(startScheduleStr,sstr);
  7422. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7423. {
  7424. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7425. }
  7426. else
  7427. {
  7428. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  7429. }
  7430. }
  7431. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  7432. //*********************chargingRateUnit***************************/
  7433. loc = strstr(payload, "chargingRateUnit");
  7434. if(loc != NULL)
  7435. {
  7436. c = 0;
  7437. memset(sstr ,0, sizeof(sstr) );
  7438. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7439. {
  7440. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7441. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7442. c++;
  7443. }
  7444. sstr[c] = '\0';
  7445. strcpy(chargingRateUnitStr,sstr);
  7446. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7447. {
  7448. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7449. }
  7450. else
  7451. {
  7452. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  7453. }
  7454. }
  7455. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  7456. //****************chargingSchedulePeriod count start*******************/
  7457. int what_len = strlen("startPeriod");
  7458. char *where = payload;
  7459. if (what_len)
  7460. while ((where = strstr(where, "startPeriod"))) {
  7461. where += what_len;
  7462. chargingSchedulePeriodCount++;
  7463. }
  7464. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  7465. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1\n");
  7466. where = payload;
  7467. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7468. {
  7469. //****************startPeriod*******************/
  7470. c=0;
  7471. loc = strstr(where, "startPeriod");
  7472. memset(sstr ,0, sizeof(sstr) );
  7473. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7474. {
  7475. sstr[c] = loc[strlen("startPeriod")+2+c];
  7476. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7477. c++;
  7478. }
  7479. sstr[c] = '\0';
  7480. startPeriodInt[periodNums] = atoi(sstr);
  7481. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  7482. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  7483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7484. {
  7485. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7486. }
  7487. else
  7488. {
  7489. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7490. }
  7491. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  7492. //****************limit*******************/
  7493. c=0;
  7494. loc = strstr(where, "limit");
  7495. memset(sstr ,0, sizeof(sstr) );
  7496. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7497. {
  7498. sstr[c] = loc[strlen("limit")+2+c];
  7499. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7500. c++;
  7501. }
  7502. sstr[c] = '\0';
  7503. limitflaot[periodNums] = atof(sstr);
  7504. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7505. {
  7506. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7507. }
  7508. else
  7509. {
  7510. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  7511. }
  7512. //DEBUG_INFO("handleSetChargingProfileRequest -13 -3\n");
  7513. //****************numberPhases*******************/
  7514. loc = strstr(where, "numberPhases");
  7515. if(loc != NULL)
  7516. {
  7517. c=0;
  7518. memset(sstr ,0, sizeof(sstr) );
  7519. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7520. {
  7521. sstr[c] = loc[strlen("numberPhases")+2+c];
  7522. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7523. c++;
  7524. }
  7525. sstr[c] = '\0';
  7526. numberPhasesInt[periodNums] = atoi(sstr);
  7527. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7528. {
  7529. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7530. }
  7531. else
  7532. {
  7533. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7534. }
  7535. }
  7536. where = loc;
  7537. }
  7538. //DEBUG_INFO("handleSetChargingProfileRequest -14\n");
  7539. //****************chargingSchedulePeriod count end*******************/
  7540. //*********************minChargingRate***************************/
  7541. loc = strstr(payload, "minChargingRate");
  7542. if(loc != NULL)
  7543. {
  7544. c = 0;
  7545. memset(sstr ,0, sizeof(sstr) );
  7546. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  7547. {
  7548. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7549. c++;
  7550. }
  7551. sstr[c] = '\0';
  7552. minChargingRateFloat = atof(sstr);
  7553. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7554. {
  7555. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7556. }
  7557. else
  7558. {
  7559. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  7560. }
  7561. }
  7562. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  7563. {
  7564. //printf("set chargingProfile 1-2\n");
  7565. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  7566. if(connectorIdInt != 0)
  7567. {
  7568. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7569. goto end;
  7570. }
  7571. strcpy(filename, ChargePointMaxProfile_JSON );
  7572. fptr1 = fopen(filename, "r");
  7573. if (!fptr1)
  7574. {
  7575. //file not exist
  7576. DEBUG_INFO("Unable to open the input file!!\n");
  7577. fptr1 = fopen(filename, "w+");
  7578. }
  7579. fclose(fptr1);
  7580. }
  7581. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  7582. {
  7583. //printf("set chargingProfile 1-3\n");
  7584. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  7585. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7586. {
  7587. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7588. goto end;
  7589. }
  7590. switch(connectorIdInt)
  7591. {
  7592. case 0:
  7593. strcpy(filename, TxDefaultProfile_0_JSON );
  7594. break;
  7595. case 1:
  7596. strcpy(filename, TxDefaultProfile_1_JSON );
  7597. break;
  7598. case 2:
  7599. strcpy(filename, TxDefaultProfile_2_JSON );
  7600. break;
  7601. default:
  7602. strcpy(filename, TxDefaultProfile_0_JSON );
  7603. break;
  7604. }
  7605. fptr1 = fopen(filename, "r");
  7606. if (!fptr1)
  7607. {
  7608. //file not exist
  7609. //DEBUG_INFO("Unable to open the input file!!\n");
  7610. fptr1 = fopen(filename, "w+");
  7611. }
  7612. fclose(fptr1);
  7613. }
  7614. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7615. {
  7616. //printf("set chargingProfile 1-4\n");
  7617. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  7618. //check Transaction active
  7619. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7620. {
  7621. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt -1))
  7622. {
  7623. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7624. {
  7625. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7626. {
  7627. meet = TRUE;
  7628. break;
  7629. }
  7630. }
  7631. }
  7632. }
  7633. for (int index = 0; index < CCS_QUANTITY; index++)
  7634. {
  7635. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt -1))
  7636. {
  7637. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7638. {
  7639. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7640. {
  7641. meet = TRUE;
  7642. break;
  7643. }
  7644. }
  7645. }
  7646. }
  7647. for (int index = 0; index < GB_QUANTITY; index++)
  7648. {
  7649. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt -1))
  7650. {
  7651. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  7652. {
  7653. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  7654. {
  7655. meet = TRUE;
  7656. break;
  7657. }
  7658. }
  7659. }
  7660. }
  7661. if(meet == FALSE)
  7662. {
  7663. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7664. goto end;
  7665. }
  7666. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7667. {
  7668. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  7669. goto end;
  7670. }
  7671. switch(connectorIdInt)
  7672. {
  7673. case 0:
  7674. break;
  7675. case 1:
  7676. strcpy(filename, TxProfile_1_JSON);
  7677. break;
  7678. case 2:
  7679. strcpy(filename, TxProfile_2_JSON);
  7680. break;
  7681. default:
  7682. strcpy(filename, TxProfile_1_JSON);
  7683. break;
  7684. }
  7685. fptr1 = fopen(filename, "r");
  7686. if (!fptr1)
  7687. {
  7688. //file not exist
  7689. DEBUG_INFO("Unable to open the input file!!\n");
  7690. fptr1 = fopen(filename, "w+");
  7691. }
  7692. fclose(fptr1);
  7693. }
  7694. //**********************************Write to File********************************************************/
  7695. FILE *infile;
  7696. FILE *outfile;
  7697. // open file for writing
  7698. infile = fopen (filename, "r");
  7699. outfile = fopen (tempfile, "w");
  7700. int d =0;
  7701. d = fgetc(infile);
  7702. //DEBUG_INFO("d:%d\n",d);
  7703. rewind(infile);
  7704. //*检测到文件结束标识返回1,否则返回0。*/
  7705. if(d == EOF)
  7706. {
  7707. //DEBUG_INFO("ChargingProfile content is NULL\n");
  7708. fprintf(outfile,"%s\n",payload);
  7709. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7710. fclose(infile);
  7711. fclose(outfile);
  7712. sprintf(rmFileCmd,"rm -f %s",filename);
  7713. system(rmFileCmd);
  7714. rename(tempfile, filename);
  7715. #if 0
  7716. resultRename = rename(tempfile, filename);
  7717. if(resultRename == 0)
  7718. {
  7719. DEBUG_INFO("File chargingProfile renamed successfully");
  7720. }
  7721. else
  7722. {
  7723. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7724. }
  7725. #endif
  7726. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  7727. //system(rmFileCmd);
  7728. }
  7729. else
  7730. {
  7731. char buf[1000]={0};
  7732. int ChargingProfileAdded = FALSE;
  7733. while (fgets(buf, sizeof(buf), infile) != NULL)
  7734. {
  7735. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  7736. //*************************tempconnectorIdInt*********************************/
  7737. loc = strstr(buf, "connectorId");
  7738. c = 0;
  7739. memset(sstr ,0, sizeof(sstr) );
  7740. while (loc[strlen("connectorId")+2+c] != ',')
  7741. {
  7742. sstr[c] = loc[strlen("connectorId")+2+c];
  7743. c++;
  7744. }
  7745. sstr[c] = '\0';
  7746. tempconnectorIdInt = atoi(sstr);
  7747. //*************************tempchargingProfileIdInt*********************************/
  7748. loc = strstr(buf, "chargingProfileId");
  7749. c = 0;
  7750. memset(sstr ,0, sizeof(sstr) );
  7751. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7752. {
  7753. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7754. c++;
  7755. }
  7756. sstr[c] = '\0';
  7757. tempchargingProfileIdInt = atoi(sstr);
  7758. //*************************tempstackLevelInt*********************************/
  7759. loc = strstr(buf, "stackLevel");
  7760. c = 0;
  7761. memset(sstr ,0, sizeof(sstr) );
  7762. while (loc[strlen("stackLevel")+2+c] != ',')
  7763. {
  7764. sstr[c] = loc[strlen("stackLevel")+2+c];
  7765. c++;
  7766. }
  7767. sstr[c] = '\0';
  7768. tempstackLevelInt = atoi(sstr);
  7769. //*************************tempchargingProfilePurposeStr*********************************/
  7770. loc = strstr(payload, "chargingProfilePurpose");
  7771. c = 0;
  7772. memset(sstr ,0, sizeof(sstr) );
  7773. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  7774. {
  7775. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  7776. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7777. c++;
  7778. }
  7779. sstr[c] = '\0';
  7780. strcpy(tempchargingProfilePurposeStr,sstr);
  7781. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  7782. {
  7783. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  7784. {
  7785. //DEBUG_INFO("update set chargingProfile to file -0\n");
  7786. if(ChargingProfileAdded == FALSE)
  7787. {
  7788. fprintf(outfile,"%s\n",payload);
  7789. ChargingProfileAdded = TRUE;
  7790. }
  7791. }
  7792. else
  7793. {
  7794. if(tempstackLevelInt < stackLevelInt)
  7795. {
  7796. if(ChargingProfileAdded == FALSE)
  7797. {
  7798. fprintf(outfile,"%s\n",payload);
  7799. ChargingProfileAdded = TRUE;
  7800. fprintf(outfile,"%s\n",buf);
  7801. }
  7802. else
  7803. {
  7804. fprintf(outfile,"%s\n",buf);
  7805. }
  7806. }
  7807. else
  7808. {
  7809. if(ChargingProfileAdded == FALSE)
  7810. {
  7811. fprintf(outfile,"%s\n",buf);
  7812. fprintf(outfile,"%s\n",payload);
  7813. ChargingProfileAdded = TRUE;
  7814. }
  7815. else
  7816. {
  7817. fprintf(outfile,"%s\n",buf);
  7818. }
  7819. }
  7820. }
  7821. }
  7822. else
  7823. {
  7824. if(tempchargingProfileIdInt < chargingProfileIdInt)
  7825. {
  7826. if(ChargingProfileAdded == FALSE)
  7827. {
  7828. fprintf(outfile,"%s\n",payload);
  7829. ChargingProfileAdded = TRUE;
  7830. fprintf(outfile,"%s\n",buf);
  7831. }
  7832. else
  7833. {
  7834. fprintf(outfile,"%s\n",buf);
  7835. }
  7836. }
  7837. else if(tempstackLevelInt < stackLevelInt)
  7838. {
  7839. if(ChargingProfileAdded == FALSE)
  7840. {
  7841. fprintf(outfile,"%s\n",payload);
  7842. ChargingProfileAdded = TRUE;
  7843. fprintf(outfile,"%s\n",buf);
  7844. }
  7845. else
  7846. {
  7847. fprintf(outfile,"%s\n",buf);
  7848. }
  7849. }
  7850. else
  7851. {
  7852. if(ChargingProfileAdded == FALSE)
  7853. {
  7854. fprintf(outfile,"%s\n",buf);
  7855. fprintf(outfile,"%s\n",payload);
  7856. ChargingProfileAdded = TRUE;
  7857. }
  7858. else
  7859. {
  7860. fprintf(outfile,"%s\n",buf);
  7861. }
  7862. }
  7863. }
  7864. } // end of while loop
  7865. fclose(infile);
  7866. fclose(outfile);
  7867. sprintf(rmFileCmd,"rm -f %s",filename);
  7868. system(rmFileCmd);
  7869. rename(tempfile, filename);
  7870. #if 0
  7871. resultRename = rename(tempfile, filename);
  7872. if(resultRename == 0)
  7873. {
  7874. DEBUG_INFO("File chargingProfile renamed successfully");
  7875. }
  7876. else
  7877. {
  7878. DEBUG_INFO("Error: unable to rename the chargingProfile file");
  7879. }
  7880. #endif
  7881. result = TRUE;
  7882. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  7883. }
  7884. end:
  7885. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  7886. return result;
  7887. return result;
  7888. }
  7889. int handleTriggerMessageRequest(char *uuid, char *payload)
  7890. {
  7891. mtrace();
  7892. int result = FAIL;
  7893. int connectorIdIsNULL = FALSE;
  7894. int connectorIdInt =0;
  7895. char sstr[40]={0};
  7896. char requestedMessagestr[40]={0};
  7897. char comfirmstr[20]={0};
  7898. int c = 0;
  7899. char *loc;
  7900. DEBUG_INFO("handleTriggerMessageRequest\n");
  7901. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  7902. c = 0;
  7903. loc = strstr(payload, "requestedMessage");
  7904. while (loc[3+strlen("requestedMessage")+c] != '\"')
  7905. {
  7906. sstr[c] = loc[3+strlen("requestedMessage")+c];
  7907. c++;
  7908. }
  7909. sstr[c] = '\0';
  7910. strcpy(requestedMessagestr, sstr);
  7911. c = 0;
  7912. loc = strstr(payload, "connectorId");
  7913. if(loc == NULL)
  7914. {
  7915. connectorIdIsNULL = TRUE;
  7916. }
  7917. else
  7918. {
  7919. memset(sstr ,0, sizeof(sstr) );
  7920. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  7921. {
  7922. sstr[c] = loc[strlen("connectorId")+2+c];
  7923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7924. c++;
  7925. }
  7926. sstr[c] = '\0';
  7927. connectorIdInt = atoi(sstr);
  7928. }
  7929. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  7930. {
  7931. //connectorIdInt = json_object_get_int(connectorId);
  7932. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  7933. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  7934. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7935. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7936. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7937. }
  7938. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  7939. {
  7940. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  7941. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7942. return TRUE;
  7943. }
  7944. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  7945. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  7946. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  7947. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  7948. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  7949. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  7950. {
  7951. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  7952. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7953. return TRUE;
  7954. }
  7955. else
  7956. {
  7957. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7958. sendTriggerMessageConfirmation(uuid,comfirmstr);
  7959. }
  7960. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  7961. {
  7962. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  7963. {
  7964. FirmwareStatusNotificationStatus = 3;
  7965. }
  7966. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  7967. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7968. }
  7969. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  7970. {
  7971. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  7972. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  7973. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7974. }
  7975. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  7976. {
  7977. sendBootNotificationRequest();
  7978. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7979. }
  7980. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  7981. {
  7982. sendHeartbeatRequest(connectorIdInt);
  7983. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  7984. }
  7985. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  7986. {
  7987. if(connectorIdIsNULL == FALSE)
  7988. {
  7989. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7990. {
  7991. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  7992. sendMeterValuesRequest(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. {
  8000. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8001. sendMeterValuesRequest(idx);
  8002. }
  8003. }
  8004. }
  8005. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8006. {
  8007. if(connectorIdIsNULL == FALSE)
  8008. {
  8009. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8010. {
  8011. sendStatusNotificationRequest(connectorIdInt -1);
  8012. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8013. }
  8014. }
  8015. else
  8016. {
  8017. for(int idx=0;idx< gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/;idx++)
  8018. sendStatusNotificationRequest(idx);
  8019. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8020. }
  8021. }
  8022. return result;
  8023. }
  8024. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8025. {
  8026. mtrace();
  8027. int result = FAIL;
  8028. char sstr[6]={0};
  8029. int connectorIdInt =0;
  8030. char comfirmstr[20]={0};
  8031. int c = 0;
  8032. char *loc;
  8033. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8034. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8035. c = 0;
  8036. loc = strstr(payload, "connectorId");
  8037. memset(sstr ,0, sizeof(sstr) );
  8038. while (loc[strlen("connectorId")+2+c] != '}')
  8039. {
  8040. sstr[c] = loc[strlen("connectorId")+2+c];
  8041. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8042. c++;
  8043. }
  8044. sstr[c] = '\0';
  8045. connectorIdInt = atoi(sstr);
  8046. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  8047. if(/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/gunTotalNumber == 0)
  8048. {
  8049. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8050. goto end;
  8051. }
  8052. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8053. {
  8054. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8055. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8056. goto end;
  8057. }
  8058. else
  8059. {
  8060. //check Transaction active
  8061. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8062. {
  8063. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8064. {
  8065. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8066. {
  8067. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8068. }
  8069. }
  8070. for (int index = 0; index < CCS_QUANTITY; index++)
  8071. {
  8072. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8073. {
  8074. //stop Transaction
  8075. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8076. }
  8077. }
  8078. for (int index = 0; index < GB_QUANTITY; index++)
  8079. {
  8080. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == (connectorIdInt-1) ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  8081. {
  8082. //stop Transaction
  8083. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8084. }
  8085. }
  8086. }
  8087. else
  8088. {
  8089. for (int index = 0; index < AC_QUANTITY; index++)
  8090. {
  8091. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == (connectorIdInt-1) ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8092. {
  8093. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8094. }
  8095. }
  8096. }// END FOR AC ELSE
  8097. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  8098. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  8099. result = TRUE;
  8100. return result;
  8101. }
  8102. end:
  8103. //json_object_put(obj); --- remove temporally
  8104. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  8105. return result;
  8106. }
  8107. static char UpdateFirmwarepayloadData[300]={0};
  8108. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  8109. {
  8110. mtrace();
  8111. int result = FAIL;
  8112. pthread_t t;
  8113. sendUpdateFirmwareConfirmation(uuid);
  8114. memset(UpdateFirmwarepayloadData, 0, 300);
  8115. strcpy(UpdateFirmwarepayloadData, payload);
  8116. pthread_create(&t, NULL, UpdateFirmwareProcess, payload);
  8117. ////pthread_join(t, NULL); //
  8118. //pthread_detach(t);
  8119. //sendUpdateFirmwareConfirmation(uuid);
  8120. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  8121. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8122. return result;
  8123. }
  8124. void *UpdateFirmwareProcess(void *data)
  8125. {
  8126. pthread_detach(pthread_self());
  8127. mtrace();
  8128. int retriesInt =0, retryIntervalInt=0;
  8129. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  8130. int port=0;
  8131. char locationstr[160]={0}, retrieveDatestr[30]={0};
  8132. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  8133. //char comfirmstr[20];
  8134. int isSuccess = 0;
  8135. char ftpbuf[200];
  8136. char temp[100];
  8137. char * pch;
  8138. int retriesISNULL=FALSE;
  8139. int retryInterval=FALSE;
  8140. int c = 0;
  8141. //int i = 0;
  8142. char *loc;
  8143. char sstr[300]={ 0 };
  8144. char str[300]={ 0 };
  8145. //char *str = (char*) data; // ? ?輸入資 ?
  8146. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  8147. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  8148. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  8149. //***************location **************/
  8150. loc = strstr(str, "location");
  8151. memset(sstr ,0, sizeof(sstr) );
  8152. c = 0;
  8153. while (loc[3+strlen("location")+c] != '\"')
  8154. {
  8155. sstr[c] = loc[3+strlen("location")+c];
  8156. c++;
  8157. }
  8158. sstr[c] = '\0';
  8159. strcpy(locationstr, sstr);
  8160. //***************retries**************/
  8161. c = 0;
  8162. loc = strstr(str, "retries");
  8163. if(loc == NULL)
  8164. {
  8165. retriesISNULL=TRUE;
  8166. }
  8167. else
  8168. {
  8169. memset(sstr ,0, sizeof(sstr) );
  8170. while (loc[strlen("retries")+2+c] != ',')
  8171. {
  8172. sstr[c] = loc[strlen("retries")+2+c];
  8173. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8174. c++;
  8175. }
  8176. sstr[c] = '\0';
  8177. }
  8178. if(retriesISNULL == FALSE)
  8179. {
  8180. retriesInt = atoi(sstr);
  8181. }
  8182. //***************retrieveDate **************/
  8183. loc = strstr(str, "retrieveDate");
  8184. memset(sstr ,0, sizeof(sstr) );
  8185. c = 0;
  8186. while (loc[3+strlen("retrieveDate")+c] != '\"')
  8187. {
  8188. sstr[c] = loc[3+strlen("retrieveDate")+c];
  8189. c++;
  8190. }
  8191. sstr[c] = '\0';
  8192. strcpy(retrieveDatestr, sstr);
  8193. //***************retryInterval **************/
  8194. c = 0;
  8195. loc = strstr(str, "retryInterval");
  8196. memset(sstr ,0, sizeof(sstr) );
  8197. if(loc == NULL)
  8198. {
  8199. retryInterval=TRUE;
  8200. }
  8201. else
  8202. {
  8203. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  8204. {
  8205. sstr[c] = loc[strlen("retryInterval")+2+c];
  8206. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  8207. c++;
  8208. }
  8209. sstr[c] = '\0';
  8210. }
  8211. if(retryInterval==FALSE)
  8212. {
  8213. retryIntervalInt = atoi(sstr);
  8214. }
  8215. memset(ftppath, 0, sizeof(ftppath));
  8216. memset(path, 0, sizeof(path));
  8217. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8218. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8219. if(strncmp(locationstr,"http", 4) == 0)
  8220. {
  8221. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  8222. protocol, host, path);
  8223. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  8224. // protocol, user, password, host, path);
  8225. sprintf(ftppath,"/%s", path);
  8226. //DEBUG_INFO("protocol =%s\n",protocol);
  8227. //DEBUG_INFO("host =%s\n",host);
  8228. //DEBUG_INFO("path =%s\n",path);
  8229. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8230. int ftppathlen=strlen(ftppath);
  8231. int i=1;
  8232. char filenametemp[50];
  8233. while(i < ftppathlen)
  8234. {
  8235. int len=ftppathlen-i;
  8236. if(ftppath[len]== 47) // '/' ascll code: 47
  8237. {
  8238. DEBUG_INFO("compare '/' all right\n");
  8239. break;
  8240. }
  8241. i=i+1;
  8242. }
  8243. memset(filenametemp, 0, sizeof(filenametemp));
  8244. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  8245. filenametemp[i+1] = 0;
  8246. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8247. do{
  8248. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8249. sleep(retryIntervalInt);
  8250. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  8251. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  8252. if(!isSuccess)
  8253. {
  8254. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8255. }
  8256. else
  8257. {
  8258. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8259. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8260. isUpdateRequest = TRUE;
  8261. }
  8262. }
  8263. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  8264. {
  8265. memset(ftpbuf, 0, sizeof(ftpbuf));
  8266. memset(temp, 0, sizeof(temp));
  8267. //DEBUG_INFO("locationstr=%s\n",locationstr);
  8268. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  8269. int ftppathlen=strlen(ftpbuf);
  8270. int i=1;
  8271. char filenametemp[50];
  8272. while(i < ftppathlen)
  8273. {
  8274. int len=ftppathlen-i;
  8275. if(ftpbuf[len]== 47) // '/' ascll code: 47
  8276. {
  8277. DEBUG_INFO(" compare '/' all right\n");
  8278. break;
  8279. }
  8280. i=i+1;
  8281. }
  8282. memset(filenametemp, 0, sizeof(filenametemp));
  8283. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  8284. filenametemp[i+1] = 0;
  8285. strncpy(temp, ftpbuf, ftppathlen-i+1);
  8286. pch=strchr(temp,'@');
  8287. if(pch==NULL)
  8288. {
  8289. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  8290. protocol, host, &port, path);
  8291. strcpy(user,"anonymous");
  8292. strcpy(password,"");
  8293. }
  8294. else
  8295. {
  8296. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  8297. protocol, user, password, host, &port, path);
  8298. }
  8299. sscanf(host,"%[^/]%s",host1, path1);
  8300. sprintf(ftppath,"%s", path1);
  8301. //DEBUG_INFO("protocol =%s\n",protocol);
  8302. //DEBUG_INFO("user =%s\n",user);
  8303. //DEBUG_INFO("password =%s\n",password);
  8304. //DEBUG_INFO("host1 =%s\n",host1);
  8305. //DEBUG_INFO("port =%d\n",port);
  8306. //DEBUG_INFO("path1 =%s\n",path1);
  8307. //DEBUG_INFO("ftppath=%s\n",ftppath);
  8308. //ftpFile(host, user, password, port, ftppath, fname);
  8309. //download firmware pthred
  8310. if(port == 0)
  8311. {
  8312. port = 21;
  8313. }
  8314. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  8315. do{
  8316. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  8317. sleep(retryIntervalInt);
  8318. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  8319. if(!isSuccess)
  8320. {
  8321. //BulldogUtil.sleepMs(interval*1000);
  8322. DEBUG_INFO("Update firmware request and download file fail.\n");
  8323. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8324. }
  8325. else
  8326. {
  8327. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8328. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  8329. isUpdateRequest = TRUE;
  8330. }
  8331. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8332. }
  8333. else
  8334. {
  8335. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  8336. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  8337. }
  8338. pthread_exit(NULL);
  8339. }
  8340. //==========================================
  8341. // Handle server response routine
  8342. //==========================================
  8343. void handleAuthorizeResponse(char *payload, int gun_index)
  8344. {
  8345. mtrace();
  8346. char expiryDatestr[30]={0};
  8347. char parentIdTagstr[20]={0};
  8348. char statusstr[20]={0};
  8349. char expiryDatestrtemp[30]={0};
  8350. char parentIdTagstrtemp[20]={0};
  8351. char IdTagstrtemp[20]={0};
  8352. char statusstrtemp[20]={0};
  8353. int expiryDateISNULL=FALSE;
  8354. int parentIdTagISNULL=FALSE;
  8355. char sstr[160]={ 0 };
  8356. char* filename = AuthorizationCache_JSON;
  8357. char tempfile[] = "../Storage/OCPP/temp.json";
  8358. int c = 0;
  8359. char *loc;
  8360. int resultRename=0;
  8361. int responseIdTagInfoAsZero= 0;
  8362. char rmFileCmd[50]={0};
  8363. DEBUG_INFO("handleAuthorizeResponse ...\n");
  8364. //***********expiryDate*************/
  8365. loc = strstr(payload, "expiryDate");
  8366. memset(sstr ,0, sizeof(sstr) );
  8367. c = 0;
  8368. if(loc == NULL)
  8369. {
  8370. expiryDateISNULL = TRUE;
  8371. }
  8372. else
  8373. {
  8374. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  8375. {
  8376. sstr[c] = loc[3+strlen("expiryDate")+c];
  8377. c++;
  8378. }
  8379. sstr[c] = '\0';
  8380. strcpy(expiryDatestr, sstr);
  8381. }
  8382. //***********parentIdTag*************/
  8383. loc = strstr(payload, "parentIdTag");
  8384. memset(sstr ,0, sizeof(sstr) );
  8385. c = 0;
  8386. if(loc == NULL)
  8387. {
  8388. parentIdTagISNULL = TRUE;
  8389. }
  8390. else
  8391. {
  8392. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  8393. {
  8394. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8395. c++;
  8396. }
  8397. sstr[c] = '\0';
  8398. strcpy(parentIdTagstr, sstr);
  8399. }
  8400. //***********status*************/
  8401. loc = strstr(payload, "status");
  8402. memset(sstr ,0, sizeof(sstr) );
  8403. c = 0;
  8404. while (loc[3+strlen("status")+c] != '\"')
  8405. {
  8406. sstr[c] = loc[3+strlen("status")+c];
  8407. c++;
  8408. }
  8409. sstr[c] = '\0';
  8410. strcpy(statusstr, sstr);
  8411. //#ifdef SystemLogMessage
  8412. // if(expiryDateISNULL == FALSE)
  8413. // DEBUG_INFO("expiryDate: %s\n", expiryDatestr);
  8414. // if(parentIdTagISNULL == FALSE)
  8415. // DEBUG_INFO("parentIdTag: %s\n", parentIdTagstr);
  8416. // DEBUG_INFO("status: %s\n", statusstr);
  8417. //#endif
  8418. if(expiryDateISNULL == FALSE)
  8419. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  8420. if(parentIdTagISNULL == FALSE)
  8421. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  8422. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  8423. //Update idTag information to authorization cache if supproted
  8424. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "true") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  8425. {
  8426. if((access(filename,F_OK))!=-1)
  8427. {
  8428. DEBUG_INFO("AuthorizationCache exist.\n");
  8429. }
  8430. else
  8431. {
  8432. DEBUG_INFO("AuthorizationCache not exist\n");
  8433. FILE *log = fopen(filename, "w+");
  8434. if(log == NULL)
  8435. {
  8436. DEBUG_INFO("log is NULL\n");
  8437. goto out;
  8438. }
  8439. else
  8440. {
  8441. fclose(log);
  8442. }
  8443. }
  8444. FILE *infile;
  8445. FILE *outfile;
  8446. // open file for writing
  8447. infile = fopen (filename, "r");
  8448. outfile = fopen (tempfile, "w");
  8449. //*检测到文件结束标识返回1,否则返回0。*/
  8450. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  8451. int c;
  8452. c = fgetc(infile);
  8453. //DEBUG_INFO("c:%d\n",c);
  8454. rewind(infile);
  8455. if(c == EOF)
  8456. {
  8457. DEBUG_INFO("Orignal File is NULL\n");
  8458. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8459. {
  8460. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8461. }
  8462. else
  8463. {
  8464. strcpy(expiryDatestrtemp, "");
  8465. }
  8466. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8467. {
  8468. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8469. }
  8470. else
  8471. {
  8472. //write Authorize IdTag
  8473. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  8474. }
  8475. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8476. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8477. fclose(infile);
  8478. fclose(outfile);
  8479. sprintf(rmFileCmd,"rm -f %s",filename);
  8480. system(rmFileCmd);
  8481. resultRename = rename(tempfile, filename);
  8482. if(resultRename == 0)
  8483. {
  8484. DEBUG_INFO("File renamed successfully");
  8485. }
  8486. else
  8487. {
  8488. DEBUG_INFO("Error: unable to rename the file");
  8489. }
  8490. }
  8491. else
  8492. {
  8493. char buf[160]={0};
  8494. //DEBUG_INFO("Orignal File is not NULL\n");
  8495. while (fgets(buf, sizeof(buf), infile) != NULL)
  8496. {
  8497. //DEBUG_INFO("Orignal File is not NULL-1\n");
  8498. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8499. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  8500. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  8501. memset(statusstr, 0, sizeof(statusstrtemp));
  8502. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  8503. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  8504. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  8505. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  8506. //------------------IdTag-----------------------
  8507. loc = strstr(buf, "idTag");
  8508. memset(sstr ,0, sizeof(sstr) );
  8509. c = 0;
  8510. while (loc[3+strlen("idTag")+c] != '\"')
  8511. {
  8512. sstr[c] = loc[3+strlen("idTag")+c];
  8513. c++;
  8514. }
  8515. sstr[c] = '\0';
  8516. strcpy(IdTagstrtemp,sstr);
  8517. //*********************expiryDate***************/
  8518. loc = strstr(buf, "expiryDate");
  8519. memset(sstr ,0, sizeof(sstr) );
  8520. c = 0;
  8521. while (loc[3+strlen("expiryDate")+c] != '\"')
  8522. {
  8523. sstr[c] = loc[3+strlen("expiryDate")+c];
  8524. c++;
  8525. }
  8526. sstr[c] = '\0';
  8527. strcpy(expiryDatestr,sstr);
  8528. //*********************parentIdTag***************/
  8529. loc = strstr(buf, "parentIdTag");
  8530. memset(sstr ,0, sizeof(sstr) );
  8531. c = 0;
  8532. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8533. {
  8534. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8535. c++;
  8536. }
  8537. sstr[c] = '\0';
  8538. strcpy(parentIdTagstr,sstr);
  8539. //*********************status***************/
  8540. loc = strstr(buf, "status");
  8541. memset(sstr ,0, sizeof(sstr) );
  8542. c = 0;
  8543. while (loc[3+strlen("status")+c] != '\"')
  8544. {
  8545. sstr[c] = loc[3+strlen("status")+c];
  8546. c++;
  8547. }
  8548. sstr[c] = '\0';
  8549. strcpy(statusstr,sstr);
  8550. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  8551. {
  8552. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  8553. responseIdTagInfoAsZero = 1;
  8554. }
  8555. else
  8556. {
  8557. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8558. }
  8559. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  8560. {
  8561. //modify item
  8562. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  8563. {
  8564. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  8565. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate));
  8566. }
  8567. else
  8568. {
  8569. strcpy(expiryDatestrtemp, "");
  8570. //json_object_object_add(temp_obj, "expiryDate", json_object_new_string(""));
  8571. }
  8572. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  8573. {
  8574. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  8575. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag));
  8576. }
  8577. else
  8578. {
  8579. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8580. //json_object_object_add(temp_obj, "parentIdTag", json_object_new_string(json_object_get_string(parentIdTagitem)));
  8581. }
  8582. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  8583. }
  8584. else
  8585. {
  8586. //wrie original item
  8587. strcpy(expiryDatestrtemp, expiryDatestr);
  8588. strcpy(parentIdTagstrtemp, parentIdTagstr);
  8589. strcpy(statusstrtemp, statusstr);
  8590. }
  8591. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag,expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  8592. }
  8593. fclose(infile);
  8594. fclose(outfile);
  8595. sprintf(rmFileCmd,"rm -f %s",filename);
  8596. system(rmFileCmd);
  8597. resultRename = rename(tempfile, filename);
  8598. if(resultRename == 0)
  8599. {
  8600. DEBUG_INFO("File renamed successfully");
  8601. }
  8602. else
  8603. {
  8604. DEBUG_INFO("Error: unable to rename the file");
  8605. }
  8606. }
  8607. }
  8608. out:
  8609. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  8610. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  8611. authorizeRetryTimes = 0;
  8612. }
  8613. void handleBootNotificationResponse(char *payload, int gun_index)
  8614. {
  8615. mtrace();
  8616. char sstr[140]={ 0 };//sstr[200]={ 0 };
  8617. char statusStr[12]={0};
  8618. char currentTimeStr[30]={0};
  8619. char *loc;
  8620. int intervalInt = 0;
  8621. int c = 0;
  8622. //double diff_t;
  8623. struct tm tp;
  8624. char buf[28]={0};
  8625. char timebuf[50]={0};
  8626. DEBUG_INFO("handleBootNotificationResponse ...\n");
  8627. //*** interval ****/
  8628. c = 0;
  8629. loc = strstr(payload, "interval");
  8630. //printf("loc=%s\n",loc);
  8631. memset(sstr ,0, sizeof(sstr) );
  8632. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  8633. {
  8634. sstr[c] = loc[strlen("interval")+2+c];
  8635. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8636. c++;
  8637. }
  8638. sstr[c] = '\0';
  8639. //DEBUG_INFO("id=%d\n",atoi(sstr));
  8640. intervalInt = atoi(sstr);
  8641. //***status ****/
  8642. loc = strstr(payload, "status");
  8643. memset(sstr ,0, sizeof(sstr) );
  8644. c = 0;
  8645. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  8646. {
  8647. sstr[c] = loc[3+strlen("status")+c];
  8648. c++;
  8649. }
  8650. sstr[c] = '\0';
  8651. strcpy(statusStr, sstr);
  8652. //***currentTime ****/
  8653. loc = strstr(payload, "currentTime");
  8654. //printf("loc=%s\n",loc);
  8655. memset(sstr ,0, sizeof(sstr) );
  8656. c = 0;
  8657. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  8658. {
  8659. sstr[c] = loc[3+strlen("currentTime")+c];
  8660. c++;
  8661. }
  8662. sstr[c] = '\0';
  8663. strcpy(currentTimeStr, sstr);
  8664. BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8665. HeartBeatWaitTime = BootNotificationInterval;
  8666. clientTime.Heartbeat=time((time_t*)NULL);
  8667. //#ifdef SystemLogMessage
  8668. // DEBUG_INFO("currentTime: %s\n", currentTimeStr);
  8669. // DEBUG_INFO("interval: %d\n", intervalInt);
  8670. // DEBUG_INFO("status: %s\n", statusStr);
  8671. //#endif
  8672. //write back to ShmOCPP16Data->BootNotification
  8673. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  8674. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  8675. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  8676. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  8677. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  8678. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  8679. {
  8680. server_sign = TRUE;
  8681. server_pending =FALSE;
  8682. }
  8683. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  8684. {
  8685. server_pending = TRUE;
  8686. }
  8687. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8688. tp.tm_isdst = -1;
  8689. //time_t utc = mktime(&tp);
  8690. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8691. memset(timebuf, 0, sizeof timebuf);
  8692. sprintf(timebuf,"date -s '%s'",buf);
  8693. //DEBUG_INFO("timebuf=%s\n",timebuf);
  8694. system(timebuf);
  8695. //==============================================
  8696. // RTC sync
  8697. //==============================================
  8698. system("/sbin/hwclock -w --systohc");
  8699. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  8700. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  8701. }
  8702. void handleDataTransferResponse(char *payload, int gun_index)
  8703. {
  8704. char sstr[160]={0};//sstr[200]={ 0 };
  8705. int c = 0;
  8706. char *loc;
  8707. DEBUG_INFO("handleDataTransferResponse ...\n");
  8708. loc = strstr(payload, "status");
  8709. printf("loc=%s\n",loc);
  8710. c = 0;
  8711. while (loc[3+strlen("status")+c] != '\"')
  8712. {
  8713. sstr[c] = loc[3+strlen("status")+c];
  8714. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8715. c++;
  8716. }
  8717. sstr[c] = '\0';
  8718. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  8719. //#ifdef SystemLogMessage
  8720. //DEBUG_INFO("data: %s\n", payload);
  8721. //#endif
  8722. }
  8723. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  8724. {
  8725. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  8726. //struct json_object *obj;
  8727. // obj = json_tokener_parse(payload);
  8728. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  8729. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  8730. //No fields are defined.
  8731. }
  8732. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  8733. {
  8734. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  8735. //struct json_object *obj;
  8736. // obj = json_tokener_parse(payload);
  8737. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  8738. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  8739. //No fields are defined.
  8740. }
  8741. void handleHeartbeatResponse(char *payload, int gun_index)
  8742. {
  8743. mtrace();
  8744. //double diff_t;
  8745. struct tm tp;
  8746. char buf[28]={0};
  8747. char timebuf[50]={0};
  8748. char sstr[30]={ 0 };
  8749. int c = 0;
  8750. char *loc;
  8751. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  8752. if((HeartBeatCount%360) == 0)
  8753. {
  8754. DEBUG_INFO("handleHeartbeatResponse ...\n");
  8755. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  8756. }
  8757. HeartBeatCount = HeartBeatCount + 1;
  8758. c = 0;
  8759. loc = strstr(payload, "currentTime");
  8760. memset(sstr ,0, sizeof(sstr) );
  8761. while (loc[3+strlen("currentTime")+c] != '\"')
  8762. {
  8763. sstr[c] = loc[3+strlen("currentTime")+c];
  8764. c++;
  8765. }
  8766. sstr[c] = '\0';
  8767. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  8768. // #ifdef SystemLogMessage
  8769. // DEBUG_INFO("currentTime: %s\n", ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
  8770. // #endif
  8771. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  8772. tp.tm_isdst = -1;
  8773. //time_t utc = mktime(&tp);
  8774. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  8775. memset(timebuf, 0, sizeof timebuf);
  8776. sprintf(timebuf,"date -s '%s'",buf);
  8777. system(timebuf);
  8778. //==============================================
  8779. // RTC sync
  8780. //==============================================
  8781. system("/sbin/hwclock -w --systohc");
  8782. if(FirstHeartBeat == 0)
  8783. {
  8784. FirstHeartBeat = 1;
  8785. }
  8786. HeartBeatWithNOResponse = 0;
  8787. }
  8788. void handleMeterValuesResponse(char *payload, int gun_index)
  8789. {
  8790. mtrace();
  8791. //struct json_object *obj;
  8792. DEBUG_INFO("handleMeterValuesResponse ...\n");
  8793. //No fields are defined.
  8794. }
  8795. void handleStartTransactionResponse(char *payload, int gun_index)
  8796. {
  8797. mtrace();
  8798. char sstr[28]={ 0 };
  8799. int c = 0;
  8800. char *loc;
  8801. int transactionIdInt = 0;
  8802. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  8803. DEBUG_INFO("handleStartTransactionResponse\n");
  8804. //****************expiryDate********************/
  8805. loc = strstr(payload, "expiryDate");
  8806. if(loc == NULL)
  8807. {
  8808. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  8809. }
  8810. else
  8811. {
  8812. c = 0;
  8813. memset(sstr ,0, sizeof(sstr) );
  8814. while (loc[3+strlen("expiryDate")+c] != '\"')
  8815. {
  8816. sstr[c] = loc[3+strlen("expiryDate")+c];
  8817. c++;
  8818. }
  8819. sstr[c] = '\0';
  8820. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8821. }
  8822. //****************parentIdTag********************/
  8823. loc = strstr(payload, "parentIdTag");
  8824. if(loc == NULL)
  8825. {
  8826. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  8827. }
  8828. else
  8829. {
  8830. c = 0;
  8831. memset(sstr ,0, sizeof(sstr) );
  8832. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8833. {
  8834. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8835. c++;
  8836. }
  8837. sstr[c] = '\0';
  8838. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8839. }
  8840. //****************status********************/
  8841. loc = strstr(payload, "status");
  8842. if(loc == NULL)
  8843. {
  8844. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  8845. }
  8846. else
  8847. {
  8848. c = 0;
  8849. memset(sstr ,0, sizeof(sstr) );
  8850. while (loc[3+strlen("status")+c] != '\"')
  8851. {
  8852. sstr[c] = loc[3+strlen("status")+c];
  8853. c++;
  8854. }
  8855. sstr[c] = '\0';
  8856. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8857. }
  8858. //****************transactionId********************/
  8859. c=0;
  8860. loc = strstr(payload, "transactionId");
  8861. memset(sstr ,0, sizeof(sstr) );
  8862. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  8863. {
  8864. sstr[c] = loc[strlen("transactionId")+2+c];
  8865. c++;
  8866. }
  8867. sstr[c] = '\0';
  8868. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  8869. transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  8870. TransactionId[gun_index] = transactionIdInt;
  8871. DEBUG_INFO("gun_index: %d\n", gun_index);
  8872. DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  8873. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  8874. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  8875. #ifdef SystemLogMessage
  8876. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8877. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8878. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  8879. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  8880. #endif
  8881. if(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "Accepted") == 0)
  8882. {
  8883. //add Charging Record
  8884. SettingChargingRecord(gun_index, transactionIdInt);
  8885. }
  8886. //DEBUG_INFO("Start Charging ErrorCode=%s\n", ShmOCPP16Data->StatusNotification[gun_index].ErrorCode);
  8887. }
  8888. void handleStatusNotificationResponse(char *payload, int gun_index)
  8889. {
  8890. mtrace();
  8891. printf("handleStatusNotificationResponse\n");
  8892. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  8893. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  8894. }
  8895. void handleStopTransactionnResponse(char *payload, int gun_index)
  8896. {
  8897. mtrace();
  8898. char sstr[30]={ 0 };
  8899. int c = 0;
  8900. char *loc;
  8901. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  8902. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  8903. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  8904. loc = strstr(payload, "idTagInfo");
  8905. //***********************idTagInfo************************/
  8906. if(loc != NULL)
  8907. {
  8908. //***********************expiryDate************************/
  8909. loc = strstr(payload, "expiryDate");
  8910. if(loc != NULL)
  8911. {
  8912. memset(sstr ,0, sizeof(sstr) );
  8913. c = 0;
  8914. while (loc[3+strlen("expiryDate")+c] != '\"')
  8915. {
  8916. sstr[c] = loc[3+strlen("expiryDate")+c];
  8917. c++;
  8918. }
  8919. sstr[c] = '\0';
  8920. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  8921. }
  8922. //***********************parentIdTag************************/
  8923. loc = strstr(payload, "parentIdTag");
  8924. if(loc != NULL)
  8925. {
  8926. memset(sstr ,0, sizeof(sstr) );
  8927. c = 0;
  8928. while (loc[3+strlen("parentIdTag")+c] != '\"')
  8929. {
  8930. sstr[c] = loc[3+strlen("parentIdTag")+c];
  8931. c++;
  8932. }
  8933. sstr[c] = '\0';
  8934. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  8935. }
  8936. //***********************status************************/
  8937. loc = strstr(payload, "status");
  8938. memset(sstr ,0, sizeof(sstr) );
  8939. c = 0;
  8940. while (loc[3+strlen("status")+c] != '\"')
  8941. {
  8942. sstr[c] = loc[3+strlen("status")+c];
  8943. c++;
  8944. }
  8945. sstr[c] = '\0';
  8946. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  8947. }
  8948. #ifdef SystemLogMessage
  8949. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  8950. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  8951. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  8952. #endif
  8953. }
  8954. //==========================================
  8955. // Handle Error routine
  8956. //==========================================
  8957. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  8958. {
  8959. mtrace();
  8960. #ifdef SystemLogMessage
  8961. DEBUG_INFO("errorCode: %s\n", errorCode);
  8962. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  8963. DEBUG_INFO("errorDetails: %s\n", payload);
  8964. #endif
  8965. }
  8966. //===============================================
  8967. // Common routine
  8968. //===============================================
  8969. int initialConfigurationTable(void)
  8970. {
  8971. FILE *fp;
  8972. FILE *outfile;
  8973. char str[200]={0};
  8974. char sstr[100]={0};
  8975. int c = 0;
  8976. char *loc;
  8977. printf("initialConfigurationTable \n");
  8978. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  8979. if((access("../Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  8980. {
  8981. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  8982. if(outfile == NULL) {
  8983. DEBUG_INFO("Error opening file");
  8984. return FALSE;
  8985. }
  8986. //outfile = fopen ("../Storage/OCPP/OCPPConfiguration", "a");
  8987. /*Core Profile*/
  8988. //AllowOfflineTxForUnknownId
  8989. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  8990. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  8991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  8992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  8993. //DEBUG_INFO("data=%s\n",data);
  8994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "TRUE");
  8995. //AuthorizationCacheEnabled
  8996. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  8997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  8998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  8999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9000. //AuthorizeRemoteTxRequests
  9001. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "TRUE");
  9005. //BlinkRepeat
  9006. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9010. //ClockAlignedDataInterval
  9011. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9015. //ConnectionTimeOut
  9016. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9017. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9019. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9020. //GetConfigurationMaxKeys
  9021. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9022. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9024. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9025. // HeartbeatInterval
  9026. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9029. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9030. // LightIntensity
  9031. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9033. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9034. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9035. // LocalAuthorizeOffline
  9036. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9038. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9039. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9040. // LocalPreAuthorize
  9041. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9045. // MaxEnergyOnInvalidId
  9046. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9049. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9051. // MeterValuesAlignedData
  9052. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9055. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9056. // MeterValuesAlignedDataMaxLength
  9057. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9060. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9061. // MeterValuesSampledData
  9062. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9064. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9065. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  9066. // MeterValuesSampledDataMaxLength
  9067. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9070. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  9071. // MeterValueSampleInterval
  9072. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9073. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9075. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9076. // MinimumStatusDuration
  9077. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9080. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "0");
  9081. // NumberOfConnectors
  9082. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9084. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9085. {
  9086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9087. }
  9088. else
  9089. {
  9090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9091. }
  9092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9093. // ResetRetries
  9094. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9097. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9098. // ConnectorPhaseRotation
  9099. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9102. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9103. // ConnectorPhaseRotationMaxLength
  9104. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  9108. // StopTransactionOnEVSideDisconnect
  9109. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  9113. // StopTransactionOnInvalidId
  9114. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", "FALSE");
  9118. // StopTxnAlignedData
  9119. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", "Energy.Active.Import.Register");
  9123. // StopTxnAlignedDataMaxLength
  9124. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  9128. // StopTxnSampledData
  9129. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", "Energy.Active.Import.Register");
  9133. // StopTxnSampledDataMaxLength
  9134. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9137. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", "0");
  9138. // SupportedFeatureProfiles
  9139. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "0");
  9143. // SupportedFeatureProfilesMaxLength
  9144. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9147. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  9148. // TransactionMessageAttempts
  9149. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9152. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9153. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  9154. // TransactionMessageRetryInterval
  9155. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9158. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  9160. // UnlockConnectorOnEVSideDisconnect
  9161. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  9165. // WebSocketPingInterval
  9166. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  9170. //* Local Auth List Management Profile*/
  9171. #if 0
  9172. //For OCTT Test Case
  9173. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9176. #endif
  9177. #if 1
  9178. //LocalAuthListEnabled
  9179. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  9183. #endif
  9184. //LocalAuthListMaxLength
  9185. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9188. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  9189. //SendLocalListMaxLength
  9190. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9193. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  9194. //ReserveConnectorZeroSupported
  9195. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  9199. //* Smart Charging Profile */
  9200. //ChargeProfileMaxStackLevel
  9201. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  9205. // ChargingScheduleAllowedChargingRateUnit
  9206. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  9210. // ChargingScheduleMaxPeriods
  9211. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  9215. // ConnectorSwitch3to1PhaseSupported
  9216. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  9220. // MaxChargingProfilesInstalled
  9221. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "9");
  9225. fclose(outfile);
  9226. }
  9227. else
  9228. {
  9229. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  9230. char keystr[60]={0};
  9231. char readonlystr[10]={0};
  9232. char valuestr[100]={0};
  9233. fp = fopen("../Storage/OCPP/OCPPConfiguration" , "r");
  9234. if(fp == NULL) {
  9235. DEBUG_INFO("Error opening file");
  9236. return FALSE;
  9237. }
  9238. while( fgets (str, sizeof(str), fp)!=NULL )
  9239. {
  9240. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  9241. //*************************key*********************************/
  9242. loc = strstr(str, "key");
  9243. c = 0;
  9244. memset(sstr ,0, sizeof(sstr) );
  9245. while (loc[strlen("key")+3+c] != '\"')
  9246. {
  9247. sstr[c] = loc[strlen("key")+3+c];
  9248. c++;
  9249. }
  9250. sstr[c] = '\0';
  9251. strcpy(keystr,sstr);
  9252. //*************************readonly*********************************/
  9253. loc = strstr(str, "readonly");
  9254. c = 0;
  9255. memset(sstr ,0, sizeof(sstr) );
  9256. while (loc[strlen("readonly")+2+c] != ',')
  9257. {
  9258. sstr[c] = loc[strlen("readonly")+2+c];
  9259. c++;
  9260. }
  9261. sstr[c] = '\0';
  9262. strcpy(readonlystr,sstr);
  9263. //*************************value*********************************/
  9264. loc = strstr(str, "value");
  9265. c = 0;
  9266. memset(sstr ,0, sizeof(sstr) );
  9267. while (loc[strlen("value")+3+c] != '\"')
  9268. {
  9269. sstr[c] = loc[strlen("value")+3+c];
  9270. c++;
  9271. }
  9272. sstr[c] = '\0';
  9273. strcpy(valuestr,sstr);
  9274. // DEBUG_INFO("keystr=%s\n",keystr);
  9275. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  9276. // DEBUG_INFO("valuestr=%s\n",valuestr);
  9277. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  9278. {
  9279. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  9280. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  9282. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9283. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  9284. }
  9285. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  9286. {
  9287. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  9288. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  9290. }
  9291. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  9292. {
  9293. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  9295. }
  9296. if(strcmp(keystr, "BlinkRepeat") == 0)
  9297. {
  9298. //Charger.BlinkRepeat = Integer.parseInt(value);
  9299. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9300. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  9301. }
  9302. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  9303. {
  9304. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  9306. }
  9307. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  9308. {
  9309. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9310. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  9311. }
  9312. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  9313. {
  9314. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  9316. }
  9317. if(strcmp(keystr, "HeartbeatInterval") == 0)
  9318. {
  9319. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  9321. HeartBeatWaitTime = atoi(valuestr);
  9322. }
  9323. if(strcmp(keystr, "LightIntensity") == 0)
  9324. {
  9325. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  9327. }
  9328. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  9329. {
  9330. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  9332. }
  9333. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  9334. {
  9335. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  9337. }
  9338. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  9339. {
  9340. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  9342. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  9343. }
  9344. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  9345. {
  9346. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9347. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  9348. }
  9349. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  9350. {
  9351. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9352. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  9353. }
  9354. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  9355. {
  9356. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  9358. }
  9359. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  9360. {
  9361. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  9363. }
  9364. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  9365. {
  9366. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9367. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  9368. }
  9369. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  9370. {
  9371. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9372. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  9373. }
  9374. if(strcmp(keystr, "NumberOfConnectors") == 0)
  9375. {
  9376. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9377. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  9378. }
  9379. if(strcmp(keystr, "ResetRetries") == 0)
  9380. {
  9381. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9382. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  9383. }
  9384. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  9385. {
  9386. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9387. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  9388. }
  9389. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  9390. {
  9391. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9392. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  9393. }
  9394. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  9395. {
  9396. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9397. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  9398. }
  9399. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  9400. {
  9401. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9402. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  9403. }
  9404. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  9405. {
  9406. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  9408. }
  9409. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  9410. {
  9411. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9413. }
  9414. if(strcmp(keystr, "StopTxnSampledData") == 0)
  9415. {
  9416. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  9418. }
  9419. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  9420. {
  9421. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  9423. }
  9424. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  9425. {
  9426. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  9428. }
  9429. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  9430. {
  9431. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  9433. }
  9434. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  9435. {
  9436. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9437. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  9438. TransactionMessageAttemptsValue = atoi(valuestr);
  9439. }
  9440. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  9441. {
  9442. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  9444. TransactionMessageRetryIntervalValue = atoi(valuestr);
  9445. }
  9446. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  9447. {
  9448. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  9450. }
  9451. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  9452. {
  9453. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9454. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  9455. }
  9456. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  9457. {
  9458. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  9460. }
  9461. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  9462. {
  9463. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  9465. }
  9466. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  9467. {
  9468. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  9470. }
  9471. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  9472. {
  9473. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  9475. }
  9476. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  9477. {
  9478. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  9480. }
  9481. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  9482. {
  9483. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  9485. }
  9486. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  9487. {
  9488. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  9490. }
  9491. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  9492. {
  9493. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9494. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  9495. }
  9496. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  9497. {
  9498. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  9499. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  9500. }
  9501. }
  9502. fclose(fp);
  9503. }
  9504. return 0;
  9505. }
  9506. void StoreConfigurationTable(void)
  9507. {
  9508. FILE *outfile;
  9509. outfile = fopen("../Storage/OCPP/OCPPConfiguration" , "w+");
  9510. if(outfile == NULL)
  9511. {
  9512. DEBUG_INFO("Error opening file");
  9513. return ;
  9514. }
  9515. /*Core Profile*/
  9516. //AllowOfflineTxForUnknownId
  9517. /*
  9518. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9519. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  9522. */
  9523. //DEBUG_INFO("data=%s\n",data);
  9524. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9525. //AuthorizationCacheEnabled
  9526. /*
  9527. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9529. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9530. */
  9531. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9532. //AuthorizeRemoteTxRequests
  9533. /*
  9534. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  9537. */
  9538. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9539. //BlinkRepeat
  9540. /*
  9541. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9543. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9544. */
  9545. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9546. //ClockAlignedDataInterval
  9547. /*
  9548. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9551. */
  9552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9553. //ConnectionTimeOut
  9554. /*
  9555. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9557. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9558. */
  9559. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9560. //GetConfigurationMaxKeys
  9561. /*
  9562. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9564. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9565. */
  9566. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9567. // HeartbeatInterval
  9568. /*
  9569. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9572. */
  9573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9574. // LightIntensity
  9575. /*
  9576. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9578. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9579. */
  9580. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9581. // LocalAuthorizeOffline
  9582. /*
  9583. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9585. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9586. */
  9587. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9588. // LocalPreAuthorize
  9589. /*
  9590. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9593. */
  9594. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9595. // MaxEnergyOnInvalidId
  9596. /*
  9597. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9599. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9600. */
  9601. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9602. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9603. // MeterValuesAlignedData
  9604. /*
  9605. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  9606. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9607. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9608. */
  9609. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9610. // MeterValuesAlignedDataMaxLength
  9611. /*
  9612. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9613. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9615. */
  9616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9617. // MeterValuesSampledData
  9618. /*
  9619. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  9620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9621. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  9622. */
  9623. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9624. // MeterValuesSampledDataMaxLength
  9625. /*
  9626. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9627. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9628. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9629. */
  9630. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9631. // MeterValueSampleInterval
  9632. /*
  9633. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9636. */
  9637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9638. // MinimumStatusDuration
  9639. /*
  9640. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  9643. */
  9644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9645. // NumberOfConnectors
  9646. /*
  9647. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9650. {
  9651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9652. }
  9653. else
  9654. {
  9655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9656. }
  9657. */
  9658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9659. // ResetRetries
  9660. /*
  9661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9664. */
  9665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9666. // ConnectorPhaseRotation
  9667. /*
  9668. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9671. */
  9672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9673. // ConnectorPhaseRotationMaxLength
  9674. /*
  9675. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9678. */
  9679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9680. // StopTransactionOnEVSideDisconnect
  9681. /*
  9682. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9685. */
  9686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9687. // StopTransactionOnInvalidId
  9688. /*
  9689. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 1;
  9690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9692. */
  9693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9694. // StopTxnAlignedData
  9695. /*
  9696. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  9697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9699. */
  9700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9701. // StopTxnAlignedDataMaxLength
  9702. /*
  9703. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9706. */
  9707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9708. // StopTxnSampledData
  9709. /*
  9710. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  9711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  9713. */
  9714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9715. // StopTxnSampledDataMaxLength
  9716. /*
  9717. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  9720. */
  9721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9722. // SupportedFeatureProfiles
  9723. /*
  9724. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9727. */
  9728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9729. // SupportedFeatureProfilesMaxLength
  9730. /*
  9731. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9734. */
  9735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9736. // TransactionMessageAttempts
  9737. /*
  9738. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9741. */
  9742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9743. // TransactionMessageRetryInterval
  9744. /*
  9745. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9748. */
  9749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9750. // UnlockConnectorOnEVSideDisconnect
  9751. /*
  9752. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9755. */
  9756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9757. // WebSocketPingInterval
  9758. /*
  9759. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9762. */
  9763. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9764. //* Local Auth List Management Profile*/
  9765. //LocalAuthListEnabled
  9766. /*
  9767. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9770. */
  9771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9772. //LocalAuthListMaxLength
  9773. /*
  9774. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9777. */
  9778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9779. //SendLocalListMaxLength
  9780. /*
  9781. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  9784. */
  9785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9786. //ReserveConnectorZeroSupported
  9787. /*
  9788. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9791. */
  9792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9793. //* Smart Charging Profile */
  9794. //ChargeProfileMaxStackLevel
  9795. /*
  9796. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  9797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  9799. */
  9800. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  9801. // ChargingScheduleAllowedChargingRateUnit
  9802. /*
  9803. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  9806. */
  9807. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  9808. // ChargingScheduleMaxPeriods
  9809. /*
  9810. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  9811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  9812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  9813. */
  9814. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  9815. // ConnectorSwitch3to1PhaseSupported
  9816. /*
  9817. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  9820. */
  9821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  9822. // MaxChargingProfilesInstalled
  9823. /*
  9824. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  9825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  9826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "9" );
  9827. */
  9828. fprintf(outfile,"{\"key\":\"%s\",\"readonly\": %s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  9829. fclose(outfile);
  9830. }
  9831. void getKeyValue(char *keyReq)
  9832. {
  9833. int isEmpty = FALSE;
  9834. int isKnowKey = FALSE;
  9835. //int unKnowIndex = 0;
  9836. DEBUG_INFO("getKeyValue \n");
  9837. DEBUG_INFO("keyReq=%s \n",keyReq);
  9838. if((keyReq == NULL) || (strlen(keyReq) == 0))
  9839. isEmpty = TRUE;
  9840. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  9841. {
  9842. DEBUG_INFO("AllowOfflineTxForUnknownId\n");
  9843. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  9844. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  9845. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  9846. {
  9847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  9848. }
  9849. else
  9850. {
  9851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  9852. }
  9853. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  9854. isKnowKey = TRUE;
  9855. }
  9856. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  9857. {
  9858. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  9859. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  9860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  9861. {
  9862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  9863. }
  9864. else
  9865. {
  9866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  9867. }
  9868. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  9869. isKnowKey = TRUE;
  9870. }
  9871. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  9872. {
  9873. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  9874. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  9875. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  9876. {
  9877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  9878. }
  9879. else
  9880. {
  9881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  9882. }
  9883. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  9884. isKnowKey = TRUE;
  9885. }
  9886. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  9887. {
  9888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  9889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  9890. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  9891. {
  9892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  9893. }
  9894. else
  9895. {
  9896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  9897. }
  9898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  9899. isKnowKey = TRUE;
  9900. }
  9901. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  9902. {
  9903. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  9904. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  9905. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  9906. {
  9907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  9908. }
  9909. else
  9910. {
  9911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  9912. }
  9913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  9914. isKnowKey = TRUE;
  9915. }
  9916. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  9917. {
  9918. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  9919. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  9920. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  9921. {
  9922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  9923. }
  9924. else
  9925. {
  9926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  9927. }
  9928. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  9929. isKnowKey = TRUE;
  9930. }
  9931. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  9932. {
  9933. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  9934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  9935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  9936. {
  9937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  9938. }
  9939. else
  9940. {
  9941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  9942. }
  9943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  9944. isKnowKey = TRUE;
  9945. }
  9946. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  9947. {
  9948. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  9949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  9950. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  9951. {
  9952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  9953. }
  9954. else
  9955. {
  9956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  9957. }
  9958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  9959. isKnowKey = TRUE;
  9960. }
  9961. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  9962. {
  9963. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  9964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  9965. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  9966. {
  9967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  9968. }
  9969. else
  9970. {
  9971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  9972. }
  9973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  9974. isKnowKey = TRUE;
  9975. }
  9976. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  9977. {
  9978. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  9979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  9980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  9981. {
  9982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  9983. }
  9984. else
  9985. {
  9986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  9987. }
  9988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  9989. isKnowKey = TRUE;
  9990. }
  9991. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  9992. {
  9993. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  9994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  9995. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  9996. {
  9997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  9998. }
  9999. else
  10000. {
  10001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10002. }
  10003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10004. isKnowKey = TRUE;
  10005. }
  10006. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10007. {
  10008. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10011. {
  10012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10013. }
  10014. else
  10015. {
  10016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10017. }
  10018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10019. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10020. isKnowKey = TRUE;
  10021. }
  10022. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10023. {
  10024. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10026. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10027. {
  10028. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10029. }
  10030. else
  10031. {
  10032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10033. }
  10034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10035. isKnowKey = TRUE;
  10036. }
  10037. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10038. {
  10039. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10041. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10042. {
  10043. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10044. }
  10045. else
  10046. {
  10047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10048. }
  10049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10050. isKnowKey = TRUE;
  10051. }
  10052. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10053. {
  10054. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10056. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10057. {
  10058. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10059. }
  10060. else
  10061. {
  10062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10063. }
  10064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10065. isKnowKey = TRUE;
  10066. }
  10067. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10068. {
  10069. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10071. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10072. {
  10073. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10074. }
  10075. else
  10076. {
  10077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10078. }
  10079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10080. isKnowKey = TRUE;
  10081. }
  10082. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10083. {
  10084. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10086. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10087. {
  10088. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10089. }
  10090. else
  10091. {
  10092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10093. }
  10094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10095. isKnowKey = TRUE;
  10096. }
  10097. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10098. {
  10099. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10102. {
  10103. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10104. }
  10105. else
  10106. {
  10107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10108. }
  10109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10110. isKnowKey = TRUE;
  10111. }
  10112. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10113. {
  10114. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10116. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10117. {
  10118. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10119. }
  10120. else
  10121. {
  10122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10123. }
  10124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10125. isKnowKey = TRUE;
  10126. }
  10127. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10128. {
  10129. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  10131. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10132. {
  10133. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  10134. }
  10135. else
  10136. {
  10137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  10138. }
  10139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  10140. isKnowKey = TRUE;
  10141. }
  10142. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  10143. {
  10144. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  10145. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  10146. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10147. {
  10148. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  10149. }
  10150. else
  10151. {
  10152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  10153. }
  10154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  10155. isKnowKey = TRUE;
  10156. }
  10157. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  10158. {
  10159. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  10160. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  10161. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10162. {
  10163. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10164. }
  10165. else
  10166. {
  10167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10168. }
  10169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  10170. isKnowKey = TRUE;
  10171. }
  10172. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  10173. {
  10174. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  10175. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  10176. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10177. {
  10178. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10179. }
  10180. else
  10181. {
  10182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10183. }
  10184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  10185. isKnowKey = TRUE;
  10186. }
  10187. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  10188. {
  10189. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  10190. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  10191. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10192. {
  10193. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10194. }
  10195. else
  10196. {
  10197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10198. }
  10199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  10200. isKnowKey = TRUE;
  10201. }
  10202. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  10203. {
  10204. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  10205. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  10206. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10207. {
  10208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10209. }
  10210. else
  10211. {
  10212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10213. }
  10214. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  10215. isKnowKey = TRUE;
  10216. }
  10217. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  10218. {
  10219. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  10220. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  10221. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  10222. {
  10223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10224. }
  10225. else
  10226. {
  10227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10228. }
  10229. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  10230. isKnowKey = TRUE;
  10231. }
  10232. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  10233. {
  10234. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  10235. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  10236. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  10237. {
  10238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  10239. }
  10240. else
  10241. {
  10242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  10243. }
  10244. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  10245. isKnowKey = TRUE;
  10246. }
  10247. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  10248. {
  10249. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  10250. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  10251. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  10252. {
  10253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10254. }
  10255. else
  10256. {
  10257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10258. }
  10259. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  10260. isKnowKey = TRUE;
  10261. }
  10262. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  10263. {
  10264. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  10265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  10266. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  10267. {
  10268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  10269. }
  10270. else
  10271. {
  10272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  10273. }
  10274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  10275. isKnowKey = TRUE;
  10276. }
  10277. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  10278. {
  10279. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  10280. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  10281. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  10282. {
  10283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10284. }
  10285. else
  10286. {
  10287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10288. }
  10289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  10290. isKnowKey = TRUE;
  10291. }
  10292. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  10293. {
  10294. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  10295. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  10296. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  10297. {
  10298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  10299. }
  10300. else
  10301. {
  10302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  10303. }
  10304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  10305. isKnowKey = TRUE;
  10306. }
  10307. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  10308. {
  10309. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  10310. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  10311. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  10312. {
  10313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  10314. }
  10315. else
  10316. {
  10317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  10318. }
  10319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  10320. isKnowKey = TRUE;
  10321. }
  10322. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  10323. {
  10324. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  10325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  10326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  10327. {
  10328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  10329. }
  10330. else
  10331. {
  10332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  10333. }
  10334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  10335. isKnowKey = TRUE;
  10336. }
  10337. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  10338. {
  10339. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  10340. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  10341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  10342. {
  10343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  10344. }
  10345. else
  10346. {
  10347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  10348. }
  10349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  10350. isKnowKey = TRUE;
  10351. }
  10352. #if 0
  10353. //For OCTT Test Case
  10354. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  10355. {
  10356. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  10357. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  10358. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10359. {
  10360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10361. }
  10362. else
  10363. {
  10364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10365. }
  10366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10367. isKnowKey = TRUE;
  10368. }
  10369. #endif
  10370. #if 1
  10371. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  10372. {
  10373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  10374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  10375. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  10376. {
  10377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  10378. }
  10379. else
  10380. {
  10381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  10382. }
  10383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  10384. isKnowKey = TRUE;
  10385. }
  10386. #endif
  10387. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  10388. {
  10389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  10390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  10391. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10394. }
  10395. else
  10396. {
  10397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10398. }
  10399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  10400. isKnowKey = TRUE;
  10401. }
  10402. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  10403. {
  10404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  10405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  10406. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  10407. {
  10408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10409. }
  10410. else
  10411. {
  10412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10413. }
  10414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  10415. isKnowKey = TRUE;
  10416. }
  10417. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  10418. {
  10419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  10420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  10421. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  10422. {
  10423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  10424. }
  10425. else
  10426. {
  10427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  10428. }
  10429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10430. isKnowKey = TRUE;
  10431. }
  10432. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  10433. {
  10434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  10435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  10436. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  10437. {
  10438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  10439. }
  10440. else
  10441. {
  10442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  10443. }
  10444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10445. isKnowKey = TRUE;
  10446. }
  10447. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  10448. {
  10449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  10450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  10451. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  10452. {
  10453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  10454. }
  10455. else
  10456. {
  10457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  10458. }
  10459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10460. isKnowKey = TRUE;
  10461. }
  10462. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  10463. {
  10464. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  10465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  10466. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  10467. {
  10468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  10469. }
  10470. else
  10471. {
  10472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  10473. }
  10474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10475. isKnowKey = TRUE;
  10476. }
  10477. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  10478. {
  10479. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  10480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  10481. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  10482. {
  10483. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  10484. }
  10485. else
  10486. {
  10487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  10488. }
  10489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10490. isKnowKey = TRUE;
  10491. }
  10492. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  10493. {
  10494. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  10495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  10496. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  10497. {
  10498. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  10499. }
  10500. else
  10501. {
  10502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  10503. }
  10504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10505. isKnowKey = TRUE;
  10506. }
  10507. //=========================================================
  10508. if(!isEmpty && !isKnowKey)
  10509. {
  10510. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  10511. strcpy(unknownkey[UnknownKeynum], keyReq);
  10512. UnknownKeynum = UnknownKeynum + 1;
  10513. }
  10514. }
  10515. void processUnkownKey(void)
  10516. {
  10517. DEBUG_INFO("processUnkownKey\n");
  10518. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  10519. for(int index=0; index < UnknownKeynum; index++)
  10520. {
  10521. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  10522. {
  10523. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  10524. }
  10525. }
  10526. }
  10527. int setKeyValue(char *key, char *value)
  10528. {
  10529. int isSuccess = NotSupported;
  10530. int check_ascii=0;
  10531. char str[10]={0};
  10532. #ifdef Debug
  10533. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  10534. #endif
  10535. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  10536. {
  10537. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10538. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10539. {
  10540. strcpy(str, (const char*)value);
  10541. for(int i = 0; str[i]; i++){
  10542. str[i] = tolower(str[i]);
  10543. }
  10544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10545. isSuccess = ConfigurationStatus_Accepted;
  10546. }
  10547. else
  10548. {
  10549. isSuccess = ConfigurationStatus_Rejected;
  10550. }
  10551. }
  10552. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  10553. {
  10554. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10555. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10556. {
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", value/*(strcmp(value, "true")==0) ?TRUE:FALSE*/ );
  10558. isSuccess = ConfigurationStatus_Accepted;
  10559. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  10560. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  10561. }
  10562. else
  10563. {
  10564. isSuccess = ConfigurationStatus_Rejected;
  10565. }
  10566. }
  10567. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  10568. {
  10569. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10570. {
  10571. strcpy(str, (const char*)value);
  10572. for(int i = 0; str[i]; i++)
  10573. {
  10574. str[i] = tolower(str[i]);
  10575. }
  10576. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10578. isSuccess = ConfigurationStatus_Accepted;
  10579. }
  10580. else
  10581. {
  10582. isSuccess = ConfigurationStatus_Rejected;
  10583. }
  10584. }
  10585. if(strcmp(key, "BlinkRepeat") == 0)
  10586. {
  10587. //Charger.BlinkRepeat = Integer.parseInt(value);
  10588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10589. {
  10590. check_ascii = value[0];
  10591. if( (check_ascii < 48) || (check_ascii > 57) )
  10592. {
  10593. isSuccess = ConfigurationStatus_Rejected;
  10594. }
  10595. else
  10596. {
  10597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  10598. isSuccess = ConfigurationStatus_Accepted;
  10599. }
  10600. }
  10601. else
  10602. {
  10603. isSuccess = ConfigurationStatus_Rejected;
  10604. }
  10605. }
  10606. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  10607. {
  10608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10609. {
  10610. check_ascii = value[0];
  10611. if( (check_ascii < 48) || (check_ascii > 57) )
  10612. {
  10613. isSuccess = ConfigurationStatus_Rejected;
  10614. }
  10615. else
  10616. {
  10617. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  10618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  10619. isSuccess = ConfigurationStatus_Accepted;
  10620. }
  10621. }
  10622. else
  10623. {
  10624. isSuccess = ConfigurationStatus_Rejected;
  10625. }
  10626. }
  10627. if(strcmp(key, "ConnectionTimeOut") == 0 )
  10628. {
  10629. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10630. {
  10631. check_ascii = value[0];
  10632. if( (check_ascii < 48) || (check_ascii > 57) )
  10633. {
  10634. isSuccess = ConfigurationStatus_Rejected;
  10635. }
  10636. else
  10637. {
  10638. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  10639. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  10640. isSuccess = ConfigurationStatus_Accepted;
  10641. }
  10642. }
  10643. else
  10644. {
  10645. isSuccess = ConfigurationStatus_Rejected;
  10646. }
  10647. }
  10648. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  10649. {
  10650. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10651. {
  10652. check_ascii = value[0];
  10653. if( (check_ascii < 48) || (check_ascii > 57) )
  10654. {
  10655. isSuccess = ConfigurationStatus_Rejected;
  10656. }
  10657. else
  10658. {
  10659. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  10661. isSuccess = ConfigurationStatus_Accepted;
  10662. }
  10663. }
  10664. else
  10665. {
  10666. isSuccess = ConfigurationStatus_Rejected;
  10667. }
  10668. }
  10669. if(strcmp(key, "HeartbeatInterval") == 0)
  10670. {
  10671. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10672. {
  10673. check_ascii = value[0];
  10674. if( (check_ascii < 48) || (check_ascii > 57) )
  10675. {
  10676. isSuccess = ConfigurationStatus_Rejected;
  10677. }
  10678. else
  10679. {
  10680. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  10681. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  10682. HeartBeatWaitTime = atoi(value);
  10683. isSuccess = ConfigurationStatus_Accepted;
  10684. }
  10685. }
  10686. else
  10687. {
  10688. isSuccess = ConfigurationStatus_Rejected;
  10689. }
  10690. }
  10691. if(strcmp(key, "LightIntensity") == 0)
  10692. {
  10693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10694. {
  10695. check_ascii = value[0];
  10696. if( (check_ascii < 48) || (check_ascii > 57) )
  10697. {
  10698. isSuccess = ConfigurationStatus_Rejected;
  10699. }
  10700. else
  10701. {
  10702. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  10703. isSuccess = ConfigurationStatus_Accepted;
  10704. }
  10705. }
  10706. else
  10707. {
  10708. isSuccess = ConfigurationStatus_Rejected;
  10709. }
  10710. }
  10711. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  10712. {
  10713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10714. {
  10715. strcpy(str, (const char*)value);
  10716. for(int i = 0; str[i]; i++)
  10717. {
  10718. str[i] = tolower(str[i]);
  10719. }
  10720. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10721. isSuccess = ConfigurationStatus_Accepted;
  10722. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10723. }
  10724. else
  10725. {
  10726. isSuccess = ConfigurationStatus_Rejected;
  10727. }
  10728. }
  10729. if(strcmp(key, "LocalPreAuthorize") == 0)
  10730. {
  10731. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10732. {
  10733. strcpy(str, (const char*)value);
  10734. for(int i = 0; str[i]; i++)
  10735. {
  10736. str[i] = tolower(str[i]);
  10737. }
  10738. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10739. isSuccess = ConfigurationStatus_Accepted;
  10740. }
  10741. else
  10742. {
  10743. isSuccess = ConfigurationStatus_Rejected;
  10744. }
  10745. }
  10746. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  10747. {
  10748. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10749. {
  10750. check_ascii = value[0];
  10751. if( (check_ascii < 48) || (check_ascii > 57) )
  10752. {
  10753. isSuccess = ConfigurationStatus_Rejected;
  10754. }
  10755. else
  10756. {
  10757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  10758. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  10759. isSuccess = ConfigurationStatus_Accepted;
  10760. }
  10761. }
  10762. else
  10763. {
  10764. isSuccess = ConfigurationStatus_Rejected;
  10765. }
  10766. }
  10767. if(strcmp(key, "MeterValuesAlignedData") == 0)
  10768. {
  10769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10770. {
  10771. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  10772. isSuccess = ConfigurationStatus_Accepted;
  10773. }
  10774. else
  10775. {
  10776. isSuccess = ConfigurationStatus_Rejected;
  10777. }
  10778. }
  10779. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  10780. {
  10781. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10782. {
  10783. check_ascii = value[0];
  10784. if( (check_ascii < 48) || (check_ascii > 57) )
  10785. {
  10786. isSuccess = ConfigurationStatus_Rejected;
  10787. }
  10788. else
  10789. {
  10790. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10791. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  10792. isSuccess = ConfigurationStatus_Accepted;
  10793. }
  10794. }
  10795. else
  10796. {
  10797. isSuccess = ConfigurationStatus_Rejected;
  10798. }
  10799. }
  10800. if(strcmp(key, "MeterValuesSampledData") == 0 )
  10801. {
  10802. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10803. {
  10804. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  10805. isSuccess = ConfigurationStatus_Accepted;
  10806. }
  10807. else
  10808. {
  10809. isSuccess = ConfigurationStatus_Rejected;
  10810. }
  10811. }
  10812. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  10813. {
  10814. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10815. {
  10816. check_ascii = value[0];
  10817. if( (check_ascii < 48) || (check_ascii > 57) )
  10818. {
  10819. isSuccess = ConfigurationStatus_Rejected;
  10820. }
  10821. else
  10822. {
  10823. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10824. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  10825. isSuccess = ConfigurationStatus_Accepted;
  10826. }
  10827. }
  10828. else
  10829. {
  10830. isSuccess = ConfigurationStatus_Rejected;
  10831. }
  10832. }
  10833. if(strcmp(key, "MeterValueSampleInterval") == 0)
  10834. {
  10835. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10836. {
  10837. check_ascii = value[0];
  10838. if( (check_ascii < 48) || (check_ascii > 57) )
  10839. {
  10840. isSuccess = ConfigurationStatus_Rejected;
  10841. }
  10842. else
  10843. {
  10844. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  10845. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  10846. isSuccess = ConfigurationStatus_Accepted;
  10847. }
  10848. }
  10849. else
  10850. {
  10851. isSuccess = ConfigurationStatus_Rejected;
  10852. }
  10853. }
  10854. if(strcmp(key, "MinimumStatusDuration") == 0)
  10855. {
  10856. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10857. {
  10858. check_ascii = value[0];
  10859. if( (check_ascii < 48) || (check_ascii > 57) )
  10860. {
  10861. isSuccess = ConfigurationStatus_Rejected;
  10862. }
  10863. else
  10864. {
  10865. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  10866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  10867. isSuccess = ConfigurationStatus_Accepted;
  10868. }
  10869. }
  10870. else
  10871. {
  10872. isSuccess = ConfigurationStatus_Rejected;
  10873. }
  10874. }
  10875. if(strcmp(key, "NumberOfConnectors") == 0)
  10876. {
  10877. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10878. {
  10879. check_ascii = value[0];
  10880. if( (check_ascii < 48) || (check_ascii > 57) )
  10881. {
  10882. isSuccess = ConfigurationStatus_Rejected;
  10883. }
  10884. else
  10885. {
  10886. //Charger.ResetRetries = Integer.parseInt(value);
  10887. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  10888. isSuccess = ConfigurationStatus_Accepted;
  10889. }
  10890. }
  10891. else
  10892. {
  10893. isSuccess = ConfigurationStatus_Rejected;
  10894. }
  10895. }
  10896. if(strcmp(key, "ResetRetries") == 0)
  10897. {
  10898. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  10899. {
  10900. check_ascii = value[0];
  10901. if( (check_ascii < 48) || (check_ascii > 57) )
  10902. {
  10903. isSuccess = ConfigurationStatus_Rejected;
  10904. }
  10905. else
  10906. {
  10907. //Charger.ResetRetries = Integer.parseInt(value);
  10908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  10909. isSuccess = ConfigurationStatus_Accepted;
  10910. }
  10911. }
  10912. else
  10913. {
  10914. isSuccess = ConfigurationStatus_Rejected;
  10915. }
  10916. }
  10917. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  10918. {
  10919. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  10920. {
  10921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", value );
  10922. isSuccess = ConfigurationStatus_Accepted;
  10923. }
  10924. else
  10925. {
  10926. isSuccess = ConfigurationStatus_Rejected;
  10927. }
  10928. }
  10929. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  10930. {
  10931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  10932. {
  10933. check_ascii = value[0];
  10934. if( (check_ascii < 48) || (check_ascii > 57) )
  10935. {
  10936. isSuccess = ConfigurationStatus_Rejected;
  10937. }
  10938. else
  10939. {
  10940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  10941. isSuccess = ConfigurationStatus_Accepted;
  10942. }
  10943. }
  10944. else
  10945. {
  10946. isSuccess = ConfigurationStatus_Rejected;
  10947. }
  10948. }
  10949. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  10950. {
  10951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  10952. {
  10953. strcpy(str, (const char*)value);
  10954. for(int i = 0; str[i]; i++)
  10955. {
  10956. str[i] = tolower(str[i]);
  10957. }
  10958. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  10959. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10960. isSuccess = ConfigurationStatus_Accepted;
  10961. }
  10962. else
  10963. {
  10964. isSuccess = ConfigurationStatus_Rejected;
  10965. }
  10966. }
  10967. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  10968. {
  10969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  10970. {
  10971. strcpy(str, (const char*)value);
  10972. for(int i = 0; str[i]; i++)
  10973. {
  10974. str[i] = tolower(str[i]);
  10975. }
  10976. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  10977. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  10978. isSuccess = ConfigurationStatus_Accepted;
  10979. }
  10980. else
  10981. {
  10982. isSuccess = ConfigurationStatus_Rejected;
  10983. }
  10984. }
  10985. if(strcmp(key, "StopTxnAlignedData") == 0)
  10986. {
  10987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  10988. {
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  10990. isSuccess = ConfigurationStatus_Accepted;
  10991. }
  10992. else
  10993. {
  10994. isSuccess = ConfigurationStatus_Rejected;
  10995. }
  10996. }
  10997. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  10998. {
  10999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11000. {
  11001. check_ascii = value[0];
  11002. if( (check_ascii < 48) || (check_ascii > 57) )
  11003. {
  11004. isSuccess = ConfigurationStatus_Rejected;
  11005. }
  11006. else
  11007. {
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11009. isSuccess = ConfigurationStatus_Accepted;
  11010. }
  11011. }
  11012. else
  11013. {
  11014. isSuccess = ConfigurationStatus_Rejected;
  11015. }
  11016. }
  11017. if(strcmp(key, "StopTxnSampledData") == 0)
  11018. {
  11019. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11020. {
  11021. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11022. isSuccess = ConfigurationStatus_Accepted;
  11023. }
  11024. else
  11025. {
  11026. isSuccess = ConfigurationStatus_Rejected;
  11027. }
  11028. }
  11029. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11030. {
  11031. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11032. {
  11033. check_ascii = value[0];
  11034. if( (check_ascii < 48) || (check_ascii > 57) )
  11035. {
  11036. isSuccess = ConfigurationStatus_Rejected;
  11037. }
  11038. else
  11039. {
  11040. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11041. isSuccess = ConfigurationStatus_Accepted;
  11042. }
  11043. }
  11044. else
  11045. {
  11046. isSuccess = ConfigurationStatus_Rejected;
  11047. }
  11048. }
  11049. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11050. {
  11051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11052. {
  11053. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11054. isSuccess = ConfigurationStatus_Accepted;
  11055. }
  11056. else
  11057. {
  11058. isSuccess = ConfigurationStatus_Rejected;
  11059. }
  11060. }
  11061. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  11062. {
  11063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11064. {
  11065. check_ascii = value[0];
  11066. if( (check_ascii < 48) || (check_ascii > 57) )
  11067. {
  11068. isSuccess = ConfigurationStatus_Rejected;
  11069. }
  11070. else
  11071. {
  11072. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  11073. isSuccess = ConfigurationStatus_Accepted;
  11074. }
  11075. }
  11076. else
  11077. {
  11078. isSuccess = ConfigurationStatus_Rejected;
  11079. }
  11080. }
  11081. if(strcmp(key, "TransactionMessageAttempts") == 0)
  11082. {
  11083. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11084. {
  11085. check_ascii = value[0];
  11086. if( (check_ascii < 48) || (check_ascii > 57) )
  11087. {
  11088. isSuccess = ConfigurationStatus_Rejected;
  11089. }
  11090. else
  11091. {
  11092. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  11093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  11094. TransactionMessageAttemptsValue = atoi(value);
  11095. isSuccess = ConfigurationStatus_Accepted;
  11096. }
  11097. }
  11098. else
  11099. {
  11100. isSuccess = ConfigurationStatus_Rejected;
  11101. }
  11102. }
  11103. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  11104. {
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11106. {
  11107. check_ascii = value[0];
  11108. if( (check_ascii < 48) || (check_ascii > 57) )
  11109. {
  11110. isSuccess = ConfigurationStatus_Rejected;
  11111. }
  11112. else
  11113. {
  11114. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  11115. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  11116. TransactionMessageRetryIntervalValue = atoi(value);
  11117. isSuccess = ConfigurationStatus_Accepted;
  11118. }
  11119. }
  11120. else
  11121. {
  11122. isSuccess = ConfigurationStatus_Rejected;
  11123. }
  11124. }
  11125. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  11126. {
  11127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11128. {
  11129. strcpy(str, (const char*)value);
  11130. for(int i = 0; str[i]; i++)
  11131. {
  11132. str[i] = tolower(str[i]);
  11133. }
  11134. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11136. isSuccess = ConfigurationStatus_Accepted;
  11137. }
  11138. else
  11139. {
  11140. isSuccess = ConfigurationStatus_Rejected;
  11141. }
  11142. }
  11143. if(strcmp(key, "WebSocketPingInterval") == 0)
  11144. {
  11145. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11146. {
  11147. check_ascii = value[0];
  11148. if( (check_ascii < 48) || (check_ascii > 57) )
  11149. {
  11150. isSuccess = ConfigurationStatus_Rejected;
  11151. }
  11152. else
  11153. {
  11154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  11155. isSuccess = ConfigurationStatus_Accepted;
  11156. }
  11157. }
  11158. else
  11159. {
  11160. isSuccess = ConfigurationStatus_Rejected;
  11161. }
  11162. }
  11163. #if 0
  11164. //For OCPP Test Case
  11165. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  11166. {
  11167. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11168. {
  11169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  11170. isSuccess = ConfigurationStatus_Accepted;
  11171. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11172. }
  11173. else
  11174. {
  11175. isSuccess = ConfigurationStatus_Rejected;
  11176. }
  11177. }
  11178. #endif
  11179. #if 1
  11180. if(strcmp(key, "LocalAuthListEnabled") == 0)
  11181. {
  11182. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11183. {
  11184. strcpy(str, (const char*)value);
  11185. for(int i = 0; str[i]; i++)
  11186. {
  11187. str[i] = tolower(str[i]);
  11188. }
  11189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11190. isSuccess = ConfigurationStatus_Accepted;
  11191. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11192. }
  11193. else
  11194. {
  11195. isSuccess = ConfigurationStatus_Rejected;
  11196. }
  11197. }
  11198. #endif
  11199. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  11200. {
  11201. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11202. {
  11203. check_ascii = value[0];
  11204. if( (check_ascii < 48) || (check_ascii > 57) )
  11205. {
  11206. isSuccess = ConfigurationStatus_Rejected;
  11207. }
  11208. else
  11209. {
  11210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  11211. isSuccess = ConfigurationStatus_Accepted;
  11212. }
  11213. }
  11214. else
  11215. {
  11216. isSuccess = ConfigurationStatus_Rejected;
  11217. }
  11218. }
  11219. if(strcmp(key, "SendLocalListMaxLength") == 0)
  11220. {
  11221. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11222. {
  11223. check_ascii = value[0];
  11224. if( (check_ascii < 48) || (check_ascii > 57) )
  11225. {
  11226. isSuccess = ConfigurationStatus_Rejected;
  11227. }
  11228. else
  11229. {
  11230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  11231. isSuccess = ConfigurationStatus_Accepted;
  11232. }
  11233. }
  11234. else
  11235. {
  11236. isSuccess = ConfigurationStatus_Rejected;
  11237. }
  11238. }
  11239. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  11240. {
  11241. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11242. {
  11243. strcpy(str, (const char*)value);
  11244. for(int i = 0; str[i]; i++)
  11245. {
  11246. str[i] = tolower(str[i]);
  11247. }
  11248. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11249. isSuccess = ConfigurationStatus_Accepted;
  11250. }
  11251. else
  11252. {
  11253. isSuccess = ConfigurationStatus_Rejected;
  11254. }
  11255. }
  11256. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  11257. {
  11258. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11259. {
  11260. check_ascii = value[0];
  11261. if( (check_ascii < 48) || (check_ascii > 57) )
  11262. {
  11263. isSuccess = ConfigurationStatus_Rejected;
  11264. }
  11265. else
  11266. {
  11267. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  11268. isSuccess = ConfigurationStatus_Accepted;
  11269. }
  11270. }
  11271. else
  11272. {
  11273. isSuccess = ConfigurationStatus_Rejected;
  11274. }
  11275. }
  11276. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11277. {
  11278. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11279. {
  11280. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  11281. isSuccess = ConfigurationStatus_Accepted;
  11282. }
  11283. else
  11284. {
  11285. isSuccess = ConfigurationStatus_Rejected;
  11286. }
  11287. }
  11288. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  11289. {
  11290. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11291. {
  11292. check_ascii = value[0];
  11293. if( (check_ascii < 48) || (check_ascii > 57) )
  11294. {
  11295. isSuccess = ConfigurationStatus_Rejected;
  11296. }
  11297. else
  11298. {
  11299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  11300. isSuccess = ConfigurationStatus_Accepted;
  11301. }
  11302. }
  11303. else
  11304. {
  11305. isSuccess = ConfigurationStatus_Rejected;
  11306. }
  11307. }
  11308. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  11309. {
  11310. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11311. {
  11312. strcpy(str, (const char*)value);
  11313. for(int i = 0; str[i]; i++)
  11314. {
  11315. str[i] = tolower(str[i]);
  11316. }
  11317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11318. isSuccess = ConfigurationStatus_Accepted;
  11319. }
  11320. else
  11321. {
  11322. isSuccess = ConfigurationStatus_Rejected;
  11323. }
  11324. }
  11325. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  11326. {
  11327. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11328. {
  11329. check_ascii = value[0];
  11330. if( (check_ascii < 48) || (check_ascii > 57) )
  11331. {
  11332. isSuccess = ConfigurationStatus_Rejected;
  11333. }
  11334. else
  11335. {
  11336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  11337. isSuccess = ConfigurationStatus_Accepted;
  11338. }
  11339. }
  11340. else
  11341. {
  11342. isSuccess = ConfigurationStatus_Rejected;
  11343. }
  11344. }
  11345. return isSuccess;
  11346. }
  11347. int updateSetting(char *key, char *value)
  11348. {
  11349. mtrace();
  11350. int isSuccess = FALSE;
  11351. char string[1000]={0}, buffer[1000]={0};
  11352. char strtemp[50]={0};
  11353. char sstr[50]={ 0 };//sstr[200]={ 0 };
  11354. int pos, c = 0;
  11355. char *loc;
  11356. int pos1=0;
  11357. FILE *f = fopen("/var/www/settings1", "r");
  11358. if(f == NULL)
  11359. {
  11360. #ifdef Debug
  11361. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  11362. #endif
  11363. return isSuccess;
  11364. }
  11365. fseek(f, 0, SEEK_END);
  11366. long fsize = ftell(f);
  11367. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  11368. fread(string, 1, fsize, f);
  11369. fclose(f);
  11370. string[fsize] = 0;
  11371. loc = strstr(string, key);
  11372. if(loc != NULL)
  11373. {
  11374. DEBUG_INFO("key exist!\n");
  11375. pos = loc - string-1;
  11376. f = fopen("/var/www/settings1", "w");
  11377. strncpy(buffer, string, pos);
  11378. fprintf(f, "%s", buffer);
  11379. memset(sstr ,0, sizeof(sstr) );
  11380. c = 0;
  11381. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  11382. {
  11383. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  11384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11385. c++;
  11386. }
  11387. sstr[c] = '\0';
  11388. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  11389. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  11390. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  11391. memset(buffer ,0, sizeof(buffer) );
  11392. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  11393. //printf("buffer=%s",buffer);
  11394. fprintf(f, "%s", buffer);
  11395. fclose(f);
  11396. }
  11397. else
  11398. {
  11399. printf("key not exist!\n");
  11400. f = fopen("/var/www/settings1", "w+");
  11401. fputs(string, f);
  11402. fseek(f, -1, SEEK_CUR);
  11403. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  11404. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  11405. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  11406. fclose(f);
  11407. }
  11408. isSuccess = TRUE;
  11409. return isSuccess;
  11410. }
  11411. int TransactionMessageAttemptsGet(void)
  11412. {
  11413. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11414. }
  11415. int FirstHeartBeatResponse(void)
  11416. {
  11417. return FirstHeartBeat;
  11418. }
  11419. int TransactionMessageRetryIntervalGet(void)
  11420. {
  11421. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11422. }
  11423. #define SA struct sockaddr
  11424. #define MAXBUF 1024
  11425. //static int m_socket_data;
  11426. //static int sockfd;
  11427. int ReadHttpStatus(int sock){
  11428. //char c;
  11429. char buff[1024]="",*ptr=buff+1;
  11430. int bytes_received, status;
  11431. DEBUG_INFO("Begin Response ..\n");
  11432. while((bytes_received = recv(sock, ptr, 1, 0))){
  11433. if(bytes_received==-1){
  11434. perror("ReadHttpStatus");
  11435. exit(1);
  11436. }
  11437. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  11438. ptr++;
  11439. }
  11440. *ptr=0;
  11441. ptr=buff+1;
  11442. sscanf(ptr,"%*s %d ", &status);
  11443. DEBUG_INFO("%s\n",ptr);
  11444. DEBUG_INFO("status=%d\n",status);
  11445. DEBUG_INFO("End Response ..\n");
  11446. return (bytes_received>0)?status:0;
  11447. }
  11448. //the only filed that it parsed is 'Content-Length'
  11449. int ParseHeader(int sock){
  11450. //char c;
  11451. char buff[1024]="",*ptr=buff+4;
  11452. int bytes_received;
  11453. DEBUG_INFO("Begin HEADER ..\n");
  11454. while((bytes_received = recv(sock, ptr, 1, 0))){
  11455. if(bytes_received==-1){
  11456. perror("Parse Header");
  11457. exit(1);
  11458. }
  11459. if(
  11460. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  11461. (ptr[-1]=='\r') && (*ptr=='\n' )
  11462. ) break;
  11463. ptr++;
  11464. }
  11465. *ptr=0;
  11466. ptr=buff+4;
  11467. //printf("%s",ptr);
  11468. if(bytes_received){
  11469. ptr=strstr(ptr,"Content-Length:");
  11470. if(ptr){
  11471. sscanf(ptr,"%*s %d",&bytes_received);
  11472. }else
  11473. bytes_received=-1; //unknown size
  11474. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  11475. }
  11476. DEBUG_INFO("End HEADER ..\n");
  11477. return bytes_received ;
  11478. }
  11479. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  11480. {
  11481. char rmFileCmd[100]={0};
  11482. char FilePath[100]={0};
  11483. char ftpbuf[200];
  11484. int systemresult;
  11485. //DEBUG_INFO("filename=%s\n",filename);
  11486. //DEBUG_INFO("url=%s\n",url);
  11487. sprintf(FilePath,"../mnt/%s",filename);
  11488. if((access(FilePath,F_OK))!=-1)
  11489. {
  11490. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11491. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11492. system(rmFileCmd);
  11493. }
  11494. memset(ftpbuf, 0, sizeof(ftpbuf));
  11495. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11496. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11497. systemresult = system(ftpbuf);
  11498. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11499. if(systemresult != 0)
  11500. {
  11501. DEBUG_INFO("http DownLoad error!\n");
  11502. return FALSE;
  11503. }
  11504. return TRUE;
  11505. }
  11506. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  11507. {
  11508. char rmFileCmd[100]={0};
  11509. char FilePath[100]={0};
  11510. char ftpbuf[200];
  11511. int systemresult;
  11512. //char temp[100];
  11513. #if 0
  11514. struct hostent* server;
  11515. char *IPbuffer;
  11516. server = gethostbyname(location);
  11517. // To convert an Internet network
  11518. // address into ASCII string
  11519. IPbuffer = inet_ntoa(*((struct in_addr*)
  11520. server->h_addr_list[0]));
  11521. #endif
  11522. sprintf(FilePath,"../mnt/%s",filename);
  11523. if((access(FilePath,F_OK))!=-1)
  11524. {
  11525. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11526. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11527. system(rmFileCmd);
  11528. }
  11529. memset(ftpbuf, 0, sizeof(ftpbuf));
  11530. sprintf(ftpbuf, "wget --tries=3 -O ../mnt/%s -c %s",filename, url);
  11531. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  11532. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11533. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11534. systemresult = system(ftpbuf);
  11535. //DEBUG_INFO("systemresult=%d\n",systemresult);
  11536. if(systemresult != 0)
  11537. {
  11538. printf("wget error!\n");
  11539. return FALSE;
  11540. }
  11541. return TRUE;
  11542. }
  11543. int httpUploadFile(char *location, char *path, char *filename,char *url)
  11544. {
  11545. char rmFileCmd[100]={0};
  11546. char FilePath[100]={0};
  11547. char ftpbuf[200];
  11548. int systemresult;
  11549. DEBUG_INFO("filename=%s\n",filename);
  11550. DEBUG_INFO("url=%s\n",url);
  11551. sprintf(FilePath,"%s","../mnt/upload_file.txt");
  11552. if((access(FilePath,F_OK))!=-1)
  11553. {
  11554. DEBUG_INFO("filename=%s exist.\n",FilePath);
  11555. sprintf(rmFileCmd,"rm -f %s",FilePath);
  11556. system(rmFileCmd);
  11557. }
  11558. FILE *fp = fopen("../mnt/upload_file.txt", "w+");
  11559. if(fp == NULL)
  11560. {
  11561. DEBUG_INFO("log is NULL\n");
  11562. return 0;
  11563. }
  11564. else
  11565. {
  11566. fprintf(fp, "%s\n", url);
  11567. fprintf(fp, "%s\n", filename);
  11568. fclose(fp);
  11569. }
  11570. memset(ftpbuf, 0, sizeof(ftpbuf));
  11571. sprintf(ftpbuf, "%s","../bin/php-cgi /var/www/ocpp_upload.php");
  11572. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11573. systemresult = system(ftpbuf);
  11574. DEBUG_INFO("systemresult=%d\n",systemresult);
  11575. if(systemresult != 0)
  11576. {
  11577. DEBUG_INFO("http DownLoad error!\n");
  11578. return FALSE;
  11579. }
  11580. return TRUE;
  11581. }
  11582. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  11583. {
  11584. struct hostent* server;
  11585. char *IPbuffer;
  11586. char ftpbuf[200];
  11587. int systemresult;
  11588. // To retrieve host information
  11589. server = gethostbyname(location);
  11590. // To convert an Internet network
  11591. // address into ASCII string
  11592. IPbuffer = inet_ntoa(*((struct in_addr*)
  11593. server->h_addr_list[0]));
  11594. memset(ftpbuf, 0, sizeof(ftpbuf));
  11595. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  11596. /* format : ftpput -u username -p passwd IP target source*/
  11597. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  11598. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  11599. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  11600. systemresult = system(ftpbuf);
  11601. DEBUG_INFO("systemresult=%d\n",systemresult);
  11602. if(systemresult != 0)
  11603. {
  11604. DEBUG_INFO("ftpput error!\n");
  11605. return FALSE;
  11606. }
  11607. return TRUE;
  11608. }
  11609. int SettingChargingRecord(int target, int transactionId)
  11610. {
  11611. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11612. {
  11613. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11614. {
  11615. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11616. {
  11617. addBuff(target, transactionId, 0);
  11618. return TRUE;
  11619. }
  11620. }
  11621. for (int index = 0; index < CCS_QUANTITY; index++)
  11622. {
  11623. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11624. {
  11625. addBuff(target, transactionId, 0);
  11626. return TRUE;
  11627. }
  11628. }
  11629. for (int index = 0; index < GB_QUANTITY; index++)
  11630. {
  11631. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11632. {
  11633. addBuff(target, transactionId, 0);
  11634. return TRUE;
  11635. }
  11636. }
  11637. }
  11638. else
  11639. {
  11640. for (int index = 0; index < AC_QUANTITY; index++)
  11641. {
  11642. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  11643. {
  11644. addBuff(target, transactionId, 0);
  11645. return TRUE;
  11646. }
  11647. }
  11648. }
  11649. return FALSE;
  11650. }
  11651. int addBuff(int gun_idx, int user_id, int cmd_sn)
  11652. {
  11653. int isSuccess = FALSE;
  11654. //char *query = NULL;
  11655. sqlite3_stmt *stmt;
  11656. int rc; // return code
  11657. char str[20];
  11658. sprintf(str,"%d",user_id);
  11659. 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 */
  11660. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  11661. rc = sqlite3_step(stmt); /* 3 */
  11662. if (rc != SQLITE_DONE) {
  11663. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  11664. goto out;
  11665. }
  11666. sqlite3_finalize(stmt);
  11667. // free(query);
  11668. out:
  11669. //----------------------
  11670. // close SQLite database
  11671. //----------------------
  11672. sqlite3_close(db);
  11673. printf("database closed.\n");
  11674. return isSuccess;
  11675. }
  11676. /**
  11677. * Place the contents of the specified file into a memory buffer
  11678. *
  11679. * @param[in] filename The path and name of the file to read
  11680. * @param[out] filebuffer A pointer to the contents in memory
  11681. * @return status 0 success, 1 on failure
  11682. */
  11683. int get_file_contents(const char* filename, char** outbuffer) {
  11684. FILE* file = NULL;
  11685. long filesize;
  11686. const int blocksize = 1;
  11687. size_t readsize;
  11688. char* filebuffer;
  11689. // Open the file
  11690. file = fopen(filename, "r");
  11691. if (NULL == file)
  11692. {
  11693. printf("'%s' not opened\n", filename);
  11694. exit(EXIT_FAILURE);
  11695. }
  11696. // Determine the file size
  11697. fseek(file, 0, SEEK_END);
  11698. filesize = ftell(file);
  11699. rewind (file);
  11700. // Allocate memory for the file contents
  11701. filebuffer = (char*) malloc(sizeof(char) * filesize);
  11702. *outbuffer = filebuffer;
  11703. if (filebuffer == NULL)
  11704. {
  11705. fputs ("malloc out-of-memory", stderr);
  11706. exit(EXIT_FAILURE);
  11707. }
  11708. // Read in the file
  11709. readsize = fread(filebuffer, blocksize, filesize, file);
  11710. if (readsize != filesize)
  11711. {
  11712. fputs ("didn't read file completely",stderr);
  11713. exit(EXIT_FAILURE);
  11714. }
  11715. // Clean exit
  11716. fclose(file);
  11717. return EXIT_SUCCESS;
  11718. }
  11719. static int selectSqlCount = 0;
  11720. static int callback(void *data, int argc, char **argv, char **azColName){
  11721. int i;
  11722. printf("%s: ", (const char*)data);
  11723. selectSqlCount = argc;
  11724. for(i = 0; i<argc; i++){
  11725. printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  11726. }
  11727. printf("\n");
  11728. return 0;
  11729. }
  11730. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  11731. //int i;
  11732. //printf("%s:\n", (const char*)data);
  11733. localversion = argv[5] ? atoi(argv[5]) : 0;
  11734. printf("localversion=%d\n", localversion);
  11735. return 0;
  11736. }
  11737. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  11738. //int i;
  11739. //printf("%s:\n", (const char*)data);
  11740. //idTag
  11741. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  11742. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  11743. //parentIdTag
  11744. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  11745. //expir_date
  11746. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  11747. //status
  11748. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  11749. //version
  11750. idTagQuery.listVersionInt = atoi(argv[5]);
  11751. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  11752. return 0;
  11753. }
  11754. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  11755. int i;
  11756. //printf("%s:\n", (const char*)data);
  11757. #if 1
  11758. for(i=0; i<argc; i++){
  11759. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  11760. }
  11761. //printf("");
  11762. #endif
  11763. // localversion = argv[5] ? atoi(argv[5]) : 0;
  11764. // printf("localversion=%d\n", localversion);
  11765. return 0;
  11766. }
  11767. /** sqlite3_exec的回调。
  11768. *
  11769. * 向控制台打印查询的结果。
  11770. *
  11771. * @param in data 传递给回调函数的数据。
  11772. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  11773. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  11774. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  11775. * @return 状态码。
  11776. */
  11777. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  11778. {
  11779. for (int i = 0; i < n_columns; i++)
  11780. {
  11781. DEBUG_INFO("%s/t", col_values[i]);
  11782. }
  11783. DEBUG_INFO("/n");
  11784. return 0;
  11785. }
  11786. void OCPP_getListVerion()
  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. strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  11795. /* Execute SQL statement */
  11796. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  11797. DEBUG_INFO("rc=%d\n",rc);
  11798. if( rc != SQLITE_OK ){
  11799. DEBUG_INFO("SQL error: %s", zErrMsg);
  11800. //sqlite3_free(zErrMsg);
  11801. }else{
  11802. DEBUG_INFO("Operation done successfully");
  11803. }
  11804. }
  11805. void OCPP_getIdTag(char *idTag)
  11806. {
  11807. int rc = 0;
  11808. // const char* data = "Callback function called";
  11809. char sql[100];
  11810. char zErrMsg[100];
  11811. memset(sql, 0, 100);
  11812. memset(zErrMsg, 0, 100);
  11813. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  11814. memset(&idTagQuery, 0, sizeof(idTagQuery));
  11815. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11816. /* Execute SQL statement */
  11817. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  11818. if( rc != SQLITE_OK ){
  11819. DEBUG_INFO("SQL error: %s", zErrMsg);
  11820. //sqlite3_free(zErrMsg);
  11821. }else{
  11822. printf("Operation done successfully");
  11823. }
  11824. //return ver;
  11825. }
  11826. void OCPP_get_TableAuthlocalAllData(void)
  11827. {
  11828. int rc = 0;
  11829. // const char* data = "Callback function called";
  11830. char sql[100];
  11831. char zErrMsg[100];
  11832. memset(sql, 0, 100);
  11833. memset(zErrMsg, 0, 100);
  11834. sprintf(sql,"select * from ocpp_auth_local ");
  11835. /* Execute SQL statement */
  11836. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  11837. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  11838. if( rc != SQLITE_OK ){
  11839. DEBUG_INFO("SQL error: %s", zErrMsg);
  11840. //sqlite3_free(zErrMsg);
  11841. }else{
  11842. DEBUG_INFO("Operation done successfully");
  11843. }
  11844. //return ver;
  11845. }
  11846. int OCPP_cleanLocalList()
  11847. {
  11848. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  11849. char *errMsg = 0;
  11850. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  11851. if (SQLITE_OK != rc)
  11852. {
  11853. DEBUG_INFO("%s\n",errMsg);
  11854. return FALSE;
  11855. }
  11856. else
  11857. {
  11858. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  11859. }
  11860. return TRUE;
  11861. }
  11862. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11863. {
  11864. int isSuccess = FALSE;
  11865. int ret = 0;
  11866. //const char* data = "Callback function called";
  11867. char sql[200];
  11868. char zErrMsg[100];
  11869. memset(sql, 0, 200);
  11870. memset(zErrMsg, 0, 100);
  11871. 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);
  11872. //* Execute SQL statement */
  11873. //zErrMsg = 0;
  11874. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  11875. if( ret != SQLITE_OK ){
  11876. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  11877. // free(zErrMsg);
  11878. // free(sql);
  11879. return isSuccess;
  11880. }
  11881. DEBUG_INFO("successfully Insert records created\n");
  11882. isSuccess = TRUE;
  11883. return isSuccess;
  11884. }
  11885. void OCPP_deleteIdTag(char *idTag)
  11886. {
  11887. //int ver = 0;
  11888. //int isSuccess = FALSE;
  11889. int rc = 0;
  11890. char sql[100];
  11891. char zErrMsg[100];
  11892. memset(sql, 0, 100);
  11893. memset(zErrMsg, 0, 100);
  11894. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  11895. //* Execute SQL statement */
  11896. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  11897. if( rc != SQLITE_OK ){
  11898. DEBUG_INFO("SQL error: %s", zErrMsg);
  11899. //sqlite3_free(zErrMsg);
  11900. }else{
  11901. DEBUG_INFO("Operation done successfully");
  11902. }
  11903. }
  11904. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  11905. {
  11906. int isSuccess = FALSE;
  11907. int ret = 0;
  11908. const char* data = "Callback function called";
  11909. char sql[200];
  11910. char zErrMsg[100];
  11911. memset(sql, 0, 200);
  11912. memset(zErrMsg, 0, 100);
  11913. //* selectFromTable */
  11914. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  11915. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  11916. //* Execute SQL statement */
  11917. selectSqlCount = 0;
  11918. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11919. if( ret != SQLITE_OK ){
  11920. printf("Error SQL: %s\n", zErrMsg);
  11921. }
  11922. printf("successfully select operation done\n");
  11923. memset(sql, 0, 200);
  11924. memset(zErrMsg, 0, 100);
  11925. if(selectSqlCount == 0)
  11926. {
  11927. //Insert
  11928. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  11929. 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);
  11930. DEBUG_INFO("sql:%s\n", sql);
  11931. //* Execute SQL statement */
  11932. //zErrMsg = 0;
  11933. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  11934. if( ret != SQLITE_OK ){
  11935. printf("SQL error: %s\n", zErrMsg);
  11936. return isSuccess;
  11937. }
  11938. DEBUG_INFO("successfully Insert records created\n");
  11939. isSuccess = TRUE;
  11940. }
  11941. else
  11942. {
  11943. //Update
  11944. //* Create merged SQL statement */
  11945. 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);
  11946. /* Execute SQL statement */
  11947. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  11948. if( ret != SQLITE_OK ){
  11949. printf("SQL error: %s\n", zErrMsg);
  11950. //sqlite3_free(zErrMsg);
  11951. //sqlite3_free(sql);
  11952. return isSuccess;
  11953. }
  11954. DEBUG_INFO("Successfully operation done \n");
  11955. isSuccess = TRUE;
  11956. }
  11957. return isSuccess;
  11958. }
  11959. int GetOcppServerURL()
  11960. {
  11961. int result = FALSE;
  11962. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  11963. memset(OcppHost, 0, sizeof(OcppHost));
  11964. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  11965. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  11966. {
  11967. DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  11968. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  11969. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11970. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11971. result = TRUE;
  11972. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11973. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11974. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11975. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11976. goto End;
  11977. }
  11978. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  11979. {
  11980. DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  11981. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  11982. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11983. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  11984. result = TRUE;
  11985. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  11986. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  11987. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  11988. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  11989. goto End;
  11990. }
  11991. else
  11992. {
  11993. strcpy(OcppHost,"");
  11994. }
  11995. End:
  11996. return result;
  11997. }
  11998. int GetOcppPath()
  11999. {
  12000. int result = FALSE;
  12001. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12002. {
  12003. if(OcppTempPath == NULL)
  12004. {
  12005. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12006. }
  12007. else
  12008. {
  12009. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12010. }
  12011. result = TRUE;
  12012. goto End;
  12013. }
  12014. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12015. {
  12016. if(OcppTempPath == NULL)
  12017. {
  12018. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12019. }
  12020. else
  12021. {
  12022. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12023. }
  12024. result = TRUE;
  12025. goto End;
  12026. }
  12027. else
  12028. {
  12029. strcpy(OcppPath,"");
  12030. }
  12031. End:
  12032. DEBUG_INFO("OcppPath=%s\n",OcppPath);
  12033. return result;
  12034. }
  12035. int GetOcppPort()
  12036. {
  12037. return OcppPort;
  12038. }
  12039. int GetOcppConnStatus(void)
  12040. {
  12041. return ShmOCPP16Data->OcppConnStatus;
  12042. }
  12043. void SetOcppConnStatus(uint8_t status)
  12044. {
  12045. ShmOCPP16Data->OcppConnStatus = status;
  12046. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12047. if(status == FALSE)
  12048. {
  12049. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12050. {
  12051. SystemInitial = CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY;
  12052. }
  12053. else
  12054. {
  12055. SystemInitial = AC_QUANTITY;
  12056. }
  12057. }
  12058. }
  12059. int GetHeartBeatWithNOResponse(void)
  12060. {
  12061. return HeartBeatWithNOResponse;
  12062. }
  12063. void SetHeartBeatWithNOResponse(void)
  12064. {
  12065. HeartBeatWithNOResponse = 0;
  12066. }
  12067. int GetTransactionId(int gunindex)
  12068. {
  12069. return TransactionId[gunindex];
  12070. }
  12071. void SetTransactionIdZero(int gunindex)
  12072. {
  12073. TransactionId[gunindex] = 0;
  12074. }
  12075. int InternetDisconnect(void)
  12076. {
  12077. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  12078. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  12079. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  12080. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12081. }
  12082. void GetChargingProfileRequest(int gunindex)
  12083. {
  12084. mtrace();
  12085. //int connectorIdInt, durationInt;
  12086. //char chargingRateUnitStr[4]={0};
  12087. int tempdurationInt = 0;
  12088. int tempchargingProfileId = 0;
  12089. int tempstackLevel = 0;
  12090. int temptransactionId = 0;
  12091. float tempminChargingRateFloat = 0.0;
  12092. char tempchargingProfilePurposeStr[24]={0};
  12093. char tempchargingProfileKindStr[12]={0};
  12094. char temprecurrencyKindStr[8]={0};
  12095. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  12096. char tempvalidToStr[28]={0};
  12097. int tempStartPeriodInt = 0;
  12098. float tempLimitInt = 0.0;//0.1;
  12099. int tempNumberPhasesInt=0;
  12100. char fname[200];
  12101. //char comfirmstr[20];
  12102. float MinChargingRate =0.0;
  12103. double diff_t;
  12104. struct tm tp;
  12105. FILE *fptr1;//, *fptr2;
  12106. int c = 0;
  12107. char * pch;
  12108. char *loc;
  12109. char sstr[200]={ 0 };
  12110. int n_chargingProfile = 0;
  12111. int n_SchedulePeriods = 0;
  12112. char SchedulePeriodList[10][200]={0};
  12113. char sLineWord[800]={0};
  12114. char word[1000]={0};
  12115. int confirmPeriods = 0;
  12116. struct StructProfile ChargePointMaxProfile;
  12117. struct StructProfile TxDefaultProfile;
  12118. struct StructProfile TxProfile;
  12119. struct StructProfile TxDefaultProfiletemp[2]={0};
  12120. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  12121. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  12122. struct StructChargingProfile TxProfile_TEMP={0};
  12123. int TxDefaultProfileFileIsNull=FALSE;
  12124. int ChargePointMaxProfileIsNull=FALSE;
  12125. int TxProfileIsNull=FALSE;
  12126. // int CompositeSceduleIndex = 0;
  12127. char ChargePointMaxProfileScheduleStr[30]={0};
  12128. char TxDefaultProfileScheduleStr[30]={0};
  12129. char TxProfileScheduleStr[30]={0};
  12130. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  12131. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  12132. memset(&TxProfile,0,sizeof(struct StructProfile));
  12133. DEBUG_INFO("GetChargingProfileRequest\n");
  12134. //*****************************ChargePointMaxProfile******************************************/
  12135. strcpy(fname, ChargePointMaxProfile_JSON);
  12136. ChargePointMaxProfileIsNull=TRUE;
  12137. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  12138. {
  12139. fptr1 = fopen(fname, "r");
  12140. int c;
  12141. c = fgetc(fptr1);
  12142. //DEBUG_INFO("c:%d\n",c);
  12143. rewind(fptr1);
  12144. if(c == EOF)
  12145. {
  12146. DEBUG_INFO("\n End of file reached.");
  12147. ChargePointMaxProfileIsNull=TRUE;
  12148. fclose(fptr1);
  12149. }
  12150. else
  12151. {
  12152. ChargePointMaxProfileIsNull=FALSE;
  12153. while(fscanf(fptr1, "%s", word) != EOF)
  12154. {
  12155. if(strcmp(word, "chargingProfileId") == 0)
  12156. {
  12157. n_chargingProfile = n_chargingProfile + 1;
  12158. }
  12159. }
  12160. rewind(fptr1);
  12161. //search Charging Profile Element
  12162. int i = 0;
  12163. int j = 0;
  12164. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12165. //***********chargingProfileId**************/
  12166. c = 0;
  12167. loc = strstr(sLineWord, "chargingProfileId");
  12168. //DEBUG_INFO("loc=%s\n",loc);
  12169. memset(sstr ,0, sizeof(sstr) );
  12170. if(loc != NULL)
  12171. {
  12172. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12173. {
  12174. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12175. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12176. c++;
  12177. }
  12178. sstr[c] = '\0';
  12179. tempchargingProfileId = atoi(sstr);
  12180. }
  12181. else
  12182. {
  12183. tempchargingProfileId = 0;
  12184. }
  12185. //***********stackLevel**************/
  12186. c = 0;
  12187. loc = strstr(sLineWord, "stackLevel");
  12188. //DEBUG_INFO("loc=%s\n",loc);
  12189. memset(sstr ,0, sizeof(sstr) );
  12190. if(loc != NULL)
  12191. {
  12192. while (loc[2+strlen("stackLevel")+c] != '\"')
  12193. {
  12194. sstr[c] = loc[2+strlen("stackLevel")+c];
  12195. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12196. c++;
  12197. }
  12198. sstr[c] = '\0';
  12199. tempstackLevel = atoi(sstr);
  12200. }
  12201. else
  12202. {
  12203. tempstackLevel = 0;
  12204. }
  12205. //***********chargingProfilePurpose **************/
  12206. c = 0;
  12207. loc = strstr(sLineWord, "chargingProfilePurpose");
  12208. //DEBUG_INFO("loc=%s\n",loc);
  12209. memset(sstr ,0, sizeof(sstr) );
  12210. if(loc != NULL)
  12211. {
  12212. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12213. {
  12214. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12215. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12216. c++;
  12217. }
  12218. sstr[c] = '\0';
  12219. strcpy(tempchargingProfilePurposeStr,sstr);
  12220. }
  12221. else
  12222. {
  12223. strcpy(tempchargingProfilePurposeStr,"");
  12224. }
  12225. //***********chargingProfileKind **************/
  12226. c = 0;
  12227. loc = strstr(sLineWord, "chargingProfileKind");
  12228. //DEBUG_INFO("loc=%s\n",loc);
  12229. memset(sstr ,0, sizeof(sstr) );
  12230. if(loc != NULL)
  12231. {
  12232. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12233. {
  12234. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12235. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12236. c++;
  12237. }
  12238. sstr[c] = '\0';
  12239. strcpy(tempchargingProfileKindStr,sstr);
  12240. }
  12241. else
  12242. {
  12243. strcpy(tempchargingProfileKindStr,"");
  12244. }
  12245. //***********recurrencyKind **************/
  12246. c = 0;
  12247. loc = strstr(sLineWord, "recurrencyKind");
  12248. //DEBUG_INFO("loc=%s\n",loc);
  12249. memset(sstr ,0, sizeof(sstr) );
  12250. if(loc != NULL)
  12251. {
  12252. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12253. {
  12254. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12255. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12256. c++;
  12257. }
  12258. sstr[c] = '\0';
  12259. strcpy(temprecurrencyKindStr,sstr);
  12260. }
  12261. else
  12262. {
  12263. strcpy(temprecurrencyKindStr,"");
  12264. }
  12265. //***********validFrom**************/
  12266. c = 0;
  12267. loc = strstr(sLineWord, "validFrom");
  12268. //DEBUG_INFO("loc=%s\n",loc);
  12269. memset(sstr ,0, sizeof(sstr) );
  12270. if(loc != NULL)
  12271. {
  12272. while (loc[3+strlen("validFrom")+c] != '\"')
  12273. {
  12274. sstr[c] = loc[3+strlen("validFrom")+c];
  12275. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12276. c++;
  12277. }
  12278. sstr[c] = '\0';
  12279. strcpy(tempvalidFromStr,sstr);
  12280. }
  12281. else
  12282. {
  12283. strcpy(tempvalidFromStr,"");
  12284. }
  12285. //***********validTo **************/
  12286. c = 0;
  12287. loc = strstr(sLineWord, "validTo");
  12288. //DEBUG_INFO("loc=%s\n",loc);
  12289. memset(sstr ,0, sizeof(sstr) );
  12290. if(loc != NULL)
  12291. {
  12292. while (loc[3+strlen("validTo")+c] != '\"')
  12293. {
  12294. sstr[c] = loc[3+strlen("validTo")+c];
  12295. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12296. c++;
  12297. }
  12298. sstr[c] = '\0';
  12299. strcpy(tempvalidToStr,sstr);
  12300. }
  12301. else
  12302. {
  12303. strcpy(tempvalidToStr,"");
  12304. }
  12305. //***********validFrom**************/
  12306. c = 0;
  12307. loc = strstr(sLineWord, "validFrom");
  12308. if(loc != NULL)
  12309. {
  12310. memset(sstr ,0, sizeof(sstr) );
  12311. while (loc[3+strlen("validFrom")+c] != '\"')
  12312. {
  12313. sstr[c] = loc[3+strlen("validFrom")+c];
  12314. c++;
  12315. }
  12316. sstr[c] = '\0';
  12317. strcpy(tempvalidFromStr,sstr);
  12318. }
  12319. else
  12320. {
  12321. strcpy(tempvalidFromStr,"");
  12322. }
  12323. //***********duration**************/
  12324. c = 0;
  12325. loc = strstr(sLineWord, "duration");
  12326. if(loc != NULL)
  12327. {
  12328. memset(sstr ,0, sizeof(sstr) );
  12329. while (loc[2+strlen("duration")+c] != ',')
  12330. {
  12331. sstr[c] = loc[2+strlen("duration")+c];
  12332. c++;
  12333. }
  12334. sstr[c] = '\0';
  12335. tempdurationInt = atoi(sstr);
  12336. }
  12337. else
  12338. {
  12339. tempdurationInt = 0;
  12340. }
  12341. //**********startSchedule**********/
  12342. c = 0;
  12343. loc = strstr(sLineWord, "startSchedule");
  12344. memset(sstr ,0, sizeof(sstr) );
  12345. while (loc[3+strlen("startSchedule")+c] != '\"')
  12346. {
  12347. sstr[c] = loc[3+strlen("startSchedule")+c];
  12348. c++;
  12349. }
  12350. sstr[c] = '\0';
  12351. strcpy(tempstartScheduleStr, sstr);
  12352. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  12353. //**********chargingRateUnit**********/
  12354. c = 0;
  12355. loc = strstr(sLineWord, "chargingRateUnit");
  12356. memset(sstr ,0, sizeof(sstr) );
  12357. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12358. {
  12359. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12360. c++;
  12361. }
  12362. sstr[c] = '\0';
  12363. strcpy(tempchargingRateUnitStr, sstr);
  12364. //**********minChargingRate*******/
  12365. c = 0;
  12366. loc = strstr(sLineWord, "minChargingRate");
  12367. if(loc != NULL)
  12368. {
  12369. memset(sstr ,0, sizeof(sstr) );
  12370. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12371. {
  12372. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12373. c++;
  12374. }
  12375. sstr[c] = '\0';
  12376. tempminChargingRateFloat = atof(sstr);
  12377. }
  12378. else
  12379. {
  12380. tempminChargingRateFloat = 0.0;
  12381. }
  12382. //
  12383. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12384. tp.tm_isdst = -1;
  12385. time_t utc = mktime(&tp);
  12386. time_t t = time(NULL);
  12387. diff_t = difftime(t, utc);
  12388. //DEBUG_INFO("diff_t=%f\n",diff_t);
  12389. //parsing strings to words
  12390. i = 0;
  12391. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12392. loc = loc+3+strlen("chargingSchedulePeriod");
  12393. pch = strtok(loc ,"{");
  12394. while (pch != NULL)
  12395. {
  12396. strcpy(SchedulePeriodList[i], pch);
  12397. pch = strtok (NULL, "{");
  12398. i = i + 1;
  12399. }
  12400. n_SchedulePeriods = i;
  12401. for(int i=0;i<n_SchedulePeriods;i++)
  12402. {
  12403. //*************startPeriod****************/
  12404. c = 0;
  12405. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12406. memset(sstr ,0, sizeof(sstr) );
  12407. while (loc[strlen("startPeriod")+2+c] != ',')
  12408. {
  12409. sstr[c] = loc[strlen("startPeriod")+2+c];
  12410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12411. c++;
  12412. }
  12413. sstr[c] = '\0';
  12414. tempStartPeriodInt = atoi(sstr);
  12415. //*************limit****************/
  12416. c = 0;
  12417. loc = strstr(SchedulePeriodList[i], "limit");
  12418. memset(sstr ,0, sizeof(sstr) );
  12419. while (loc[strlen("limit")+2+c] != ',')
  12420. {
  12421. sstr[c] = loc[strlen("limit")+2+c];
  12422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12423. c++;
  12424. }
  12425. sstr[c] = '\0';
  12426. tempLimitInt = atof(sstr);
  12427. //*************numberPhases****************/
  12428. c = 0;
  12429. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12430. memset(sstr ,0, sizeof(sstr) );
  12431. while (loc[strlen("numberPhases")+2+c] != '}')
  12432. {
  12433. sstr[c] = loc[strlen("numberPhases")+2+c];
  12434. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12435. c++;
  12436. }
  12437. sstr[c] = '\0';
  12438. tempNumberPhasesInt = atoi(sstr);
  12439. if(j == 0)
  12440. {
  12441. ChargePointMaxProfile.Duration = tempdurationInt;
  12442. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  12443. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  12444. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12445. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12446. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12447. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  12448. ChargePointMaxProfile_TEMP.TransactionId = 0;
  12449. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12450. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12451. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12452. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12453. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12454. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12455. }
  12456. }
  12457. if(MinChargingRate < tempminChargingRateFloat)
  12458. {
  12459. MinChargingRate = tempminChargingRateFloat;
  12460. }
  12461. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12462. if(confirmPeriods < n_SchedulePeriods)
  12463. {
  12464. confirmPeriods = n_SchedulePeriods;
  12465. }
  12466. j = j + 1;
  12467. }
  12468. fclose(fptr1);
  12469. }
  12470. }// the end of access file ChargePointMaxProfile
  12471. //****************************TxDefaultProfile************************************************/
  12472. switch(gunindex + 1)
  12473. {
  12474. case 0:
  12475. break;
  12476. case 1:
  12477. strcpy(fname, TxDefaultProfile_1_JSON );
  12478. break;
  12479. case 2:
  12480. strcpy(fname, TxDefaultProfile_2_JSON );
  12481. break;
  12482. default:
  12483. strcpy(fname, TxDefaultProfile_1_JSON );
  12484. break;
  12485. }
  12486. TxDefaultProfileFileIsNull=TRUE;
  12487. if((access(fname,F_OK))!=-1)
  12488. {
  12489. fptr1 = fopen(fname, "r");
  12490. c = 0;
  12491. c = fgetc(fptr1);
  12492. //DEBUG_INFO("c:%d\n",c);
  12493. rewind(fptr1);
  12494. if(c == EOF)
  12495. {
  12496. DEBUG_INFO("\n End of file reached.");
  12497. TxDefaultProfileFileIsNull=TRUE;
  12498. fclose(fptr1);
  12499. }
  12500. else
  12501. {
  12502. TxDefaultProfileFileIsNull=FALSE;
  12503. while(fscanf(fptr1, "%s", word) != EOF)
  12504. {
  12505. if(strcmp(word, "chargingProfileId") == 0)
  12506. {
  12507. n_chargingProfile = n_chargingProfile + 1;
  12508. }
  12509. }
  12510. rewind(fptr1);
  12511. //search Charging Profile Element
  12512. int i = 0;
  12513. int j = 0;
  12514. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12515. #if 0
  12516. /***********connectorId****************/
  12517. c = 0;
  12518. loc = strstr(sLineWord, "connectorId");
  12519. memset(sstr ,0, sizeof(sstr) );
  12520. while (loc[strlen("connectorId")+2+c] != ',')
  12521. {
  12522. sstr[c] = loc[strlen("connectorId")+2+c];
  12523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12524. c++;
  12525. }
  12526. sstr[c] = '\0';
  12527. tempconnectorIdInt = atoi(sstr);
  12528. #endif
  12529. //***********chargingProfileId**************/
  12530. c = 0;
  12531. loc = strstr(sLineWord, "chargingProfileId");
  12532. //DEBUG_INFO("loc=%s\n",loc);
  12533. memset(sstr ,0, sizeof(sstr) );
  12534. if(loc != NULL)
  12535. {
  12536. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12537. {
  12538. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12539. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12540. c++;
  12541. }
  12542. sstr[c] = '\0';
  12543. tempchargingProfileId = atoi(sstr);
  12544. }
  12545. else
  12546. {
  12547. tempchargingProfileId = 0;
  12548. }
  12549. //***********stackLevel**************/
  12550. c = 0;
  12551. loc = strstr(sLineWord, "stackLevel");
  12552. //DEBUG_INFO("loc=%s\n",loc);
  12553. memset(sstr ,0, sizeof(sstr) );
  12554. if(loc != NULL)
  12555. {
  12556. while (loc[2+strlen("stackLevel")+c] != '\"')
  12557. {
  12558. sstr[c] = loc[2+strlen("stackLevel")+c];
  12559. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12560. c++;
  12561. }
  12562. sstr[c] = '\0';
  12563. tempstackLevel = atoi(sstr);
  12564. }
  12565. else
  12566. {
  12567. tempstackLevel = 0;
  12568. }
  12569. //***********chargingProfilePurpose **************/
  12570. c = 0;
  12571. loc = strstr(sLineWord, "chargingProfilePurpose");
  12572. //DEBUG_INFO("loc=%s\n",loc);
  12573. memset(sstr ,0, sizeof(sstr) );
  12574. if(loc != NULL)
  12575. {
  12576. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12577. {
  12578. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12579. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12580. c++;
  12581. }
  12582. sstr[c] = '\0';
  12583. strcpy(tempchargingProfilePurposeStr,sstr);
  12584. }
  12585. else
  12586. {
  12587. strcpy(tempchargingProfilePurposeStr,"");
  12588. }
  12589. //***********chargingProfileKind **************/
  12590. c = 0;
  12591. loc = strstr(sLineWord, "chargingProfileKind");
  12592. //DEBUG_INFO("loc=%s\n",loc);
  12593. memset(sstr ,0, sizeof(sstr) );
  12594. if(loc != NULL)
  12595. {
  12596. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12597. {
  12598. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12599. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12600. c++;
  12601. }
  12602. sstr[c] = '\0';
  12603. strcpy(tempchargingProfileKindStr,sstr);
  12604. }
  12605. else
  12606. {
  12607. strcpy(tempchargingProfileKindStr,"");
  12608. }
  12609. //***********recurrencyKind **************/
  12610. c = 0;
  12611. loc = strstr(sLineWord, "recurrencyKind");
  12612. //DEBUG_INFO("loc=%s\n",loc);
  12613. memset(sstr ,0, sizeof(sstr) );
  12614. if(loc != NULL)
  12615. {
  12616. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  12617. {
  12618. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  12619. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12620. c++;
  12621. }
  12622. sstr[c] = '\0';
  12623. strcpy(temprecurrencyKindStr,sstr);
  12624. }
  12625. else
  12626. {
  12627. strcpy(temprecurrencyKindStr,"");
  12628. }
  12629. //***********validFrom**************/
  12630. c = 0;
  12631. loc = strstr(sLineWord, "validFrom");
  12632. if(loc != NULL)
  12633. {
  12634. memset(sstr ,0, sizeof(sstr) );
  12635. while (loc[3+strlen("validFrom")+c] != '\"')
  12636. {
  12637. sstr[c] = loc[3+strlen("validFrom")+c];
  12638. c++;
  12639. }
  12640. sstr[c] = '\0';
  12641. strcpy(tempvalidFromStr,sstr);
  12642. }
  12643. else
  12644. {
  12645. strcpy(tempvalidFromStr,"");
  12646. }
  12647. //***********validFrom**************/
  12648. c = 0;
  12649. loc = strstr(sLineWord, "duration");
  12650. if(loc != NULL)
  12651. {
  12652. memset(sstr ,0, sizeof(sstr) );
  12653. while (loc[2+strlen("duration")+c] != ',')
  12654. {
  12655. sstr[c] = loc[2+strlen("duration")+c];
  12656. c++;
  12657. }
  12658. sstr[c] = '\0';
  12659. tempdurationInt = atoi(sstr);
  12660. }
  12661. else
  12662. {
  12663. tempdurationInt = 0;
  12664. }
  12665. //**********startSchedule**********/
  12666. c = 0;
  12667. loc = strstr(sLineWord, "startSchedule");
  12668. memset(sstr ,0, sizeof(sstr) );
  12669. while (loc[3+strlen("startSchedule")+c] != '\"')
  12670. {
  12671. sstr[c] = loc[3+strlen("startSchedule")+c];
  12672. c++;
  12673. }
  12674. sstr[c] = '\0';
  12675. strcpy(tempstartScheduleStr, sstr);
  12676. strcpy(TxDefaultProfileScheduleStr, sstr);
  12677. //**********chargingRateUnit**********/
  12678. c = 0;
  12679. loc = strstr(sLineWord, "chargingRateUnit");
  12680. memset(sstr ,0, sizeof(sstr) );
  12681. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  12682. {
  12683. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  12684. c++;
  12685. }
  12686. sstr[c] = '\0';
  12687. strcpy(tempchargingRateUnitStr, sstr);
  12688. //**********minChargingRate*******/
  12689. c = 0;
  12690. loc = strstr(sLineWord, "minChargingRate");
  12691. if(loc != NULL)
  12692. {
  12693. memset(sstr ,0, sizeof(sstr) );
  12694. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  12695. {
  12696. sstr[c] = loc[2+strlen("minChargingRate")+c];
  12697. c++;
  12698. }
  12699. sstr[c] = '\0';
  12700. tempminChargingRateFloat = atof(sstr);
  12701. }
  12702. else
  12703. {
  12704. tempminChargingRateFloat = 0.0;
  12705. }
  12706. //
  12707. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  12708. tp.tm_isdst = -1;
  12709. time_t utc = mktime(&tp);
  12710. time_t t = time(NULL);
  12711. diff_t = difftime(t, utc);
  12712. printf("diff between startScheduleStr and now =%f\n",diff_t);
  12713. //parsing strings to words
  12714. i = 0;
  12715. loc = strstr(sLineWord, "chargingSchedulePeriod");
  12716. loc = loc+3+strlen("chargingSchedulePeriod");
  12717. pch = strtok(loc ,"{");
  12718. while (pch != NULL)
  12719. {
  12720. strcpy(SchedulePeriodList[i], pch);
  12721. pch = strtok (NULL, "{");
  12722. i = i + 1;
  12723. }
  12724. n_SchedulePeriods = i;
  12725. for(int i=0;i<n_SchedulePeriods;i++)
  12726. {
  12727. //*************startPeriod****************/
  12728. c = 0;
  12729. loc = strstr(SchedulePeriodList[i], "startPeriod");
  12730. memset(sstr ,0, sizeof(sstr) );
  12731. while (loc[strlen("startPeriod")+2+c] != ',')
  12732. {
  12733. sstr[c] = loc[strlen("startPeriod")+2+c];
  12734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12735. c++;
  12736. }
  12737. sstr[c] = '\0';
  12738. tempStartPeriodInt = atoi(sstr);
  12739. //*************limit****************/
  12740. c = 0;
  12741. loc = strstr(SchedulePeriodList[i], "limit");
  12742. memset(sstr ,0, sizeof(sstr) );
  12743. while (loc[strlen("limit")+2+c] != ',')
  12744. {
  12745. sstr[c] = loc[strlen("limit")+2+c];
  12746. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12747. c++;
  12748. }
  12749. sstr[c] = '\0';
  12750. tempLimitInt = atof(sstr);
  12751. //*************numberPhases****************/
  12752. c = 0;
  12753. loc = strstr(SchedulePeriodList[i], "numberPhases");
  12754. memset(sstr ,0, sizeof(sstr) );
  12755. while (loc[strlen("numberPhases")+2+c] != '}')
  12756. {
  12757. sstr[c] = loc[strlen("numberPhases")+2+c];
  12758. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12759. c++;
  12760. }
  12761. sstr[c] = '\0';
  12762. tempNumberPhasesInt = atoi(sstr);
  12763. if(j == 0)
  12764. {
  12765. TxDefaultProfile.Duration = tempdurationInt;
  12766. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  12767. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  12768. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  12769. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  12770. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  12771. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  12772. TxDefaultProfile_TEMP.TransactionId = 0;
  12773. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  12774. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  12775. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  12776. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  12777. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  12778. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  12779. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  12780. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  12781. }
  12782. else
  12783. {
  12784. //other stack level charging Profile
  12785. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  12786. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  12787. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  12788. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  12789. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  12790. }
  12791. }
  12792. if(MinChargingRate < tempminChargingRateFloat)
  12793. {
  12794. MinChargingRate = tempminChargingRateFloat;
  12795. }
  12796. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  12797. if(confirmPeriods < n_SchedulePeriods)
  12798. confirmPeriods = n_SchedulePeriods;
  12799. j = j + 1;
  12800. }
  12801. fclose(fptr1);
  12802. //Stacking Charging Profiles
  12803. for(int l=0; l <(j-1) ;l++)
  12804. {
  12805. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  12806. {
  12807. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  12808. {
  12809. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  12810. {
  12811. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  12812. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  12813. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  12814. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12815. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12816. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12817. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12818. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12819. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12820. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12821. }
  12822. else
  12823. {
  12824. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  12825. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  12826. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  12827. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  12828. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  12829. }
  12830. }
  12831. }
  12832. }
  12833. //end of Stacking Charging Profiles
  12834. }
  12835. }// the end of ACCESS TxDefaultProfile
  12836. //****************************TxProfile************************************************/
  12837. switch(gunindex + 1)
  12838. {
  12839. case 0:
  12840. break;
  12841. case 1:
  12842. strcpy(fname, TxProfile_1_JSON );
  12843. break;
  12844. case 2:
  12845. strcpy(fname, TxProfile_2_JSON );
  12846. break;
  12847. default:
  12848. strcpy(fname, TxProfile_1_JSON );
  12849. break;
  12850. }
  12851. TxProfileIsNull=TRUE;
  12852. if((access(fname,F_OK))!=-1)
  12853. {
  12854. fptr1 = fopen(fname, "r");
  12855. c = 0;
  12856. c = fgetc(fptr1);
  12857. //DEBUG_INFO("c:%d\n",c);
  12858. rewind(fptr1);
  12859. if(c == EOF)
  12860. {
  12861. DEBUG_INFO("\n End of file reached.");
  12862. TxProfileIsNull=TRUE;
  12863. fclose(fptr1);
  12864. }
  12865. else
  12866. {
  12867. TxProfileIsNull=FALSE;
  12868. while(fscanf(fptr1, "%s", word) != EOF)
  12869. {
  12870. if(strcmp(word, "chargingProfileId") == 0)
  12871. {
  12872. n_chargingProfile = n_chargingProfile + 1;
  12873. }
  12874. }
  12875. rewind(fptr1);
  12876. //search Charging Profile Element
  12877. int i= 0;
  12878. int j= 0;
  12879. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  12880. #if 0
  12881. /***********connectorId****************/
  12882. c = 0;
  12883. loc = strstr(sLineWord, "connectorId");
  12884. memset(sstr ,0, sizeof(sstr) );
  12885. while (loc[strlen("connectorId")+2+c] != ',')
  12886. {
  12887. sstr[c] = loc[strlen("connectorId")+2+c];
  12888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12889. c++;
  12890. }
  12891. sstr[c] = '\0';
  12892. tempconnectorIdInt = atoi(sstr);
  12893. #endif
  12894. //***********chargingProfileId**************/
  12895. c = 0;
  12896. loc = strstr(sLineWord, "chargingProfileId");
  12897. memset(sstr ,0, sizeof(sstr) );
  12898. if(loc != NULL)
  12899. {
  12900. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  12901. {
  12902. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  12903. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12904. c++;
  12905. }
  12906. sstr[c] = '\0';
  12907. tempchargingProfileId = atoi(sstr);
  12908. }
  12909. else
  12910. {
  12911. tempchargingProfileId = 0;
  12912. }
  12913. //***********transactionId **************/
  12914. c = 0;
  12915. loc = strstr(sLineWord, "transactionId");
  12916. //DEBUG_INFO("loc=%s\n",loc);
  12917. memset(sstr ,0, sizeof(sstr) );
  12918. if(loc != NULL)
  12919. {
  12920. while (loc[2+strlen("transactionId")+c] != '\"')
  12921. {
  12922. sstr[c] = loc[2+strlen("transactionId")+c];
  12923. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12924. c++;
  12925. }
  12926. sstr[c] = '\0';
  12927. temptransactionId = atoi(sstr);
  12928. }
  12929. else
  12930. {
  12931. temptransactionId = 0;
  12932. }
  12933. //***********stackLevel**************/
  12934. c = 0;
  12935. loc = strstr(sLineWord, "stackLevel");
  12936. //DEBUG_INFO("loc=%s\n",loc);
  12937. memset(sstr ,0, sizeof(sstr) );
  12938. if(loc != NULL)
  12939. {
  12940. while (loc[2+strlen("stackLevel")+c] != '\"')
  12941. {
  12942. sstr[c] = loc[2+strlen("stackLevel")+c];
  12943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12944. c++;
  12945. }
  12946. sstr[c] = '\0';
  12947. tempstackLevel = atoi(sstr);
  12948. }
  12949. else
  12950. {
  12951. tempstackLevel = 0;
  12952. }
  12953. //***********chargingProfilePurpose **************/
  12954. c = 0;
  12955. loc = strstr(sLineWord, "chargingProfilePurpose");
  12956. //DEBUG_INFO("loc=%s\n",loc);
  12957. memset(sstr ,0, sizeof(sstr) );
  12958. if(loc != NULL)
  12959. {
  12960. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12961. {
  12962. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12963. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12964. c++;
  12965. }
  12966. sstr[c] = '\0';
  12967. strcpy(tempchargingProfilePurposeStr,sstr);
  12968. }
  12969. else
  12970. {
  12971. strcpy(tempchargingProfilePurposeStr,"");
  12972. }
  12973. //***********chargingProfileKind **************/
  12974. c = 0;
  12975. loc = strstr(sLineWord, "chargingProfileKind");
  12976. //DEBUG_INFO("loc=%s\n",loc);
  12977. memset(sstr ,0, sizeof(sstr) );
  12978. if(loc != NULL)
  12979. {
  12980. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  12981. {
  12982. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  12983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12984. c++;
  12985. }
  12986. sstr[c] = '\0';
  12987. strcpy(tempchargingProfileKindStr,sstr);
  12988. }
  12989. else
  12990. {
  12991. strcpy(tempchargingProfileKindStr,"");
  12992. }
  12993. //***********recurrencyKind **************/
  12994. c = 0;
  12995. loc = strstr(sLineWord, "recurrencyKind");
  12996. //DEBUG_INFO("loc=%s\n",loc);
  12997. memset(sstr ,0, sizeof(sstr) );
  12998. if(loc != NULL)
  12999. {
  13000. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13001. {
  13002. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13003. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13004. c++;
  13005. }
  13006. sstr[c] = '\0';
  13007. strcpy(temprecurrencyKindStr,sstr);
  13008. }
  13009. else
  13010. {
  13011. strcpy(temprecurrencyKindStr,"");
  13012. }
  13013. //***********validFrom**************/
  13014. c = 0;
  13015. loc = strstr(sLineWord, "validFrom");
  13016. if(loc != NULL)
  13017. {
  13018. memset(sstr ,0, sizeof(sstr) );
  13019. while (loc[3+strlen("validFrom")+c] != '\"')
  13020. {
  13021. sstr[c] = loc[3+strlen("validFrom")+c];
  13022. c++;
  13023. }
  13024. sstr[c] = '\0';
  13025. strcpy(tempvalidFromStr,sstr);
  13026. }
  13027. else
  13028. {
  13029. strcpy(tempvalidFromStr,"");
  13030. }
  13031. //***********duration**************/
  13032. c = 0;
  13033. loc = strstr(sLineWord, "duration");
  13034. //DEBUG_INFO("loc=%s\n",loc);
  13035. memset(sstr ,0, sizeof(sstr) );
  13036. if(loc != NULL)
  13037. {
  13038. while (loc[2+strlen("duration")+c] != '\"')
  13039. {
  13040. sstr[c] = loc[2+strlen("duration")+c];
  13041. c++;
  13042. }
  13043. sstr[c] = '\0';
  13044. tempdurationInt = atoi(sstr);
  13045. }
  13046. else
  13047. {
  13048. tempdurationInt = 0;
  13049. }
  13050. //**********startSchedule**********/
  13051. c = 0;
  13052. loc = strstr(sLineWord, "startSchedule");
  13053. memset(sstr ,0, sizeof(sstr) );
  13054. while (loc[3+strlen("startSchedule")+c] != '\"')
  13055. {
  13056. sstr[c] = loc[3+strlen("startSchedule")+c];
  13057. c++;
  13058. }
  13059. sstr[c] = '\0';
  13060. strcpy(tempstartScheduleStr, sstr);
  13061. strcpy(TxProfileScheduleStr, sstr);
  13062. //**********chargingRateUnit**********/
  13063. c = 0;
  13064. loc = strstr(sLineWord, "chargingRateUnit");
  13065. memset(sstr ,0, sizeof(sstr) );
  13066. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  13067. {
  13068. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  13069. c++;
  13070. }
  13071. sstr[c] = '\0';
  13072. strcpy(tempchargingRateUnitStr, sstr);
  13073. //**********minChargingRate*******/
  13074. c = 0;
  13075. loc = strstr(sLineWord, "minChargingRate");
  13076. if(loc != NULL)
  13077. {
  13078. memset(sstr ,0, sizeof(sstr) );
  13079. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  13080. {
  13081. sstr[c] = loc[2+strlen("minChargingRate")+c];
  13082. c++;
  13083. }
  13084. sstr[c] = '\0';
  13085. tempminChargingRateFloat = atof(sstr);
  13086. }
  13087. else
  13088. {
  13089. tempminChargingRateFloat = 0.0;
  13090. }
  13091. //
  13092. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  13093. tp.tm_isdst = -1;
  13094. time_t utc = mktime(&tp);
  13095. time_t t = time(NULL);
  13096. diff_t = difftime(t, utc);
  13097. //DEBUG_INFO("diff_t=%f\n",diff_t);
  13098. //parsing strings to words
  13099. i = 0;
  13100. loc = strstr(sLineWord, "chargingSchedulePeriod");
  13101. loc = loc+3+strlen("chargingSchedulePeriod");
  13102. pch = strtok(loc ,"{");
  13103. while (pch != NULL)
  13104. {
  13105. strcpy(SchedulePeriodList[i], pch);
  13106. pch = strtok (NULL, "{");
  13107. i = i + 1;
  13108. }
  13109. n_SchedulePeriods = i;
  13110. for(int i=0;i<n_SchedulePeriods;i++)
  13111. {
  13112. //*************startPeriod****************/
  13113. c = 0;
  13114. loc = strstr(SchedulePeriodList[i], "startPeriod");
  13115. memset(sstr ,0, sizeof(sstr) );
  13116. while (loc[strlen("startPeriod")+2+c] != ',')
  13117. {
  13118. sstr[c] = loc[strlen("startPeriod")+2+c];
  13119. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13120. c++;
  13121. }
  13122. sstr[c] = '\0';
  13123. tempStartPeriodInt = atoi(sstr);
  13124. //*************limit****************/
  13125. c = 0;
  13126. loc = strstr(SchedulePeriodList[i], "limit");
  13127. memset(sstr ,0, sizeof(sstr) );
  13128. while (loc[strlen("limit")+2+c] != ',')
  13129. {
  13130. sstr[c] = loc[strlen("limit")+2+c];
  13131. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13132. c++;
  13133. }
  13134. sstr[c] = '\0';
  13135. tempLimitInt = atof(sstr);
  13136. //*************numberPhases****************/
  13137. c = 0;
  13138. loc = strstr(SchedulePeriodList[i], "numberPhases");
  13139. memset(sstr ,0, sizeof(sstr) );
  13140. while (loc[strlen("numberPhases")+2+c] != '}')
  13141. {
  13142. sstr[c] = loc[strlen("numberPhases")+2+c];
  13143. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13144. c++;
  13145. }
  13146. sstr[c] = '\0';
  13147. tempNumberPhasesInt = atoi(sstr);
  13148. //TxProfile.Duration = durationInt;
  13149. TxProfile.TotalPeriod = n_SchedulePeriods;
  13150. TxProfile.Period[i].Limit = tempLimitInt;
  13151. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  13152. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  13153. }
  13154. if(MinChargingRate < tempminChargingRateFloat)
  13155. {
  13156. MinChargingRate = tempminChargingRateFloat;
  13157. }
  13158. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  13159. if(confirmPeriods < n_SchedulePeriods)
  13160. confirmPeriods = n_SchedulePeriods;
  13161. if(j == 0)
  13162. {
  13163. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  13164. TxProfile_TEMP.StackLevel = tempstackLevel;
  13165. TxProfile_TEMP.TransactionId = 0;
  13166. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  13167. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  13168. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  13169. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  13170. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  13171. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  13172. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  13173. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  13174. }
  13175. }
  13176. fclose(fptr1);
  13177. }
  13178. }// the end of ACCESS TxProfile
  13179. //CompositeSchedule
  13180. int period=0;
  13181. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  13182. {
  13183. //TxProfile
  13184. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13185. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13186. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13187. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13190. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13191. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13192. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13193. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13194. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13195. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13196. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13197. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13198. {
  13199. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  13200. {
  13201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13203. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13204. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  13205. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13206. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13207. period = period + 1;
  13208. }
  13209. else
  13210. {
  13211. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  13212. {
  13213. }
  13214. else
  13215. {
  13216. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13217. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13218. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13219. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13220. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  13221. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  13222. period = period + 1;
  13223. }
  13224. }
  13225. }
  13226. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13227. {
  13228. if((TxDefaultProfile.Period[l].StartPeriod < 86400)&&(TxDefaultProfile.Period[l].StartPeriod > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  13229. {
  13230. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13231. {
  13232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13233. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  13234. }
  13235. else
  13236. {
  13237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13238. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  13239. }
  13240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13242. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13243. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13244. period = period + 1;
  13245. }
  13246. }
  13247. }
  13248. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13249. {
  13250. //TxDefaultProfile
  13251. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13253. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13254. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  13256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13257. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  13258. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13259. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13260. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13261. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13262. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13263. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13264. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13265. {
  13266. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  13267. {
  13268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13271. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13272. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13273. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13274. period = period + 1;
  13275. }
  13276. else
  13277. {
  13278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13280. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13281. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  13282. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13283. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13284. period = period + 1;
  13285. }
  13286. }
  13287. }
  13288. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  13289. {
  13290. //TxDefaultProfile
  13291. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  13292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  13293. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13294. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  13295. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  13296. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  13297. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  13298. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  13299. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  13300. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  13301. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  13302. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  13303. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  13304. {
  13305. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13306. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13308. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  13309. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  13310. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  13311. period = period + 1;
  13312. }
  13313. }
  13314. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  13315. {
  13316. //ChargePointMaxProfile
  13317. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  13318. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  13319. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  13320. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  13321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  13322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13323. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  13324. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  13325. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  13326. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  13327. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  13328. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  13329. for(int l=0; l < ChargePointMaxProfile.TotalPeriod;l++)
  13330. {
  13331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  13332. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  13333. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  13334. period = period + 1;
  13335. }
  13336. }
  13337. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  13338. {
  13339. //TxProfile
  13340. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  13341. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  13342. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  13343. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  13344. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  13345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  13346. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  13347. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  13348. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  13349. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  13350. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  13351. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  13352. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  13353. for(int k=0; k < TxProfile.TotalPeriod;k++)
  13354. {
  13355. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].Limit = TxProfile.Period[k].Limit;
  13356. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].NumberPhases = TxProfile.Period[k].NumberPhases;
  13357. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[k].StartPeriod = TxProfile.Period[k].StartPeriod;
  13358. }
  13359. }
  13360. confirmPeriods = period;
  13361. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  13362. 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,"
  13363. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  13364. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  13365. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  13366. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  13367. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  13368. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  13369. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  13370. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  13371. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  13372. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  13373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  13374. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  13375. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  13376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  13377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  13378. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  13379. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  13380. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  13381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  13382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  13383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  13384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  13385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  13386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  13387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  13388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  13389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  13390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  13391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  13392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  13393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  13394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  13395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  13396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  13397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  13398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  13399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  13400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  13401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  13402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  13403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  13404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  13405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  13406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  13407. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  13408. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  13409. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  13410. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  13411. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  13412. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  13413. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  13414. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  13415. }
  13416. void LWS_Send(char * str)
  13417. {
  13418. //=====================================================
  13419. // Check InternetConn 0: disconnected, 1: connected
  13420. //====================================================
  13421. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13422. {
  13423. DEBUG_INFO("\n offline now !!!\n");
  13424. return;
  13425. }
  13426. pthread_mutex_lock(&lock);
  13427. memset(SendBuffer,0,SendBufLen);
  13428. sprintf((char *)SendBuffer, "%s", str);
  13429. pthread_mutex_unlock(&lock);
  13430. lws_callback_on_writable(wsi_client);
  13431. lws_service(context, 10000);//timeout_ms
  13432. }