MessageHandler.c 670 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668
  1. #define _XOPEN_SOURCE 700
  2. #include <sys/types.h>
  3. #include <sys/ipc.h>
  4. #include <sys/shm.h>
  5. #include <sys/stat.h>
  6. #include <sys/time.h> // gettimeofday sleep usleep
  7. #include <fcntl.h>
  8. #include <stddef.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #ifdef _WIN32
  12. #include <Windows.h>
  13. #else
  14. #include <unistd.h>
  15. #endif
  16. #include <stdarg.h>
  17. #include <ctype.h>
  18. #include "libwebsockets.h"
  19. #include <lws_config.h>
  20. #include "define.h"
  21. #include <sys/socket.h>
  22. #include <netinet/in.h>
  23. #include <stdlib.h>
  24. /*for sendfile()*/
  25. #include <sys/sendfile.h>
  26. /*for O_RDONLY*/
  27. #include <fcntl.h>
  28. #include "sqlite3.h"
  29. #include <arpa/inet.h>
  30. #include <time.h>
  31. #include <assert.h>
  32. #include <pthread.h>
  33. #include <mcheck.h>
  34. #include "MessageHandler.h"
  35. #include "SystemLogMessage.h"
  36. #include "hashmap.h"
  37. #include "ShareMemory.h"
  38. #include "TransactionQueue.h"
  39. #define PASS 1
  40. #define FAIL -1
  41. #define FALSE 0
  42. #define TRUE 1 // Option 1
  43. //ChargePointMaxProfile
  44. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  45. //TxDefaultProfile
  46. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  47. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  48. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  49. //TxProfile
  50. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  51. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  52. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  53. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  54. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  55. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  56. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  57. //===================================
  58. // Define CP State constant
  59. //===================================
  60. #define CP_STATE_UNKNOWN 0
  61. #define CP_STATE_A 1
  62. #define CP_STATE_B 2
  63. #define CP_STATE_C 3
  64. #define CP_STATE_D 4
  65. #define CP_STATE_E 5
  66. #define CP_STATE_F 6
  67. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  68. struct StatusCodeData *ShmStatusCodeData;
  69. struct PsuData *ShmPsuData ;
  70. struct OCPP16Data *ShmOCPP16Data;
  71. // define Macro
  72. #define SystemLogMessage
  73. // OCPP Message Type
  74. #define MESSAGE_TYPE_CALL 2
  75. #define MESSAGE_TYPE_CALLRESULT 3
  76. #define MESSAGE_TYPE_CALLERROR 4
  77. //
  78. //#define server_cycle_Status 120
  79. #define MACROSTR(k) #k
  80. //ConfigurationMaxKeys
  81. #define GetConfigurationMaxKeysNUM 43
  82. //char guid[37];
  83. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  84. char queuedata[2600]={0};
  85. //=================================
  86. // StatusNotification cycle
  87. //=================================
  88. static int server_cycle_Status = 120;
  89. //===============================
  90. // Configuration: unknownkey
  91. //===============================
  92. static char unknownkey[10][20]={0};
  93. static int UnknownKeynum = 0;
  94. //===============================
  95. // Gun Total Numbers
  96. //===============================
  97. //#define gunTotalNumber (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') ? (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY): AC_QUANTITY
  98. static int gunTotalNumber=0;
  99. static unsigned char gunType[4]={0};
  100. //===============================
  101. // Local List Version
  102. //===============================
  103. static int localversion=0;
  104. static char idTagAuthorization[32]={0};
  105. //===============================
  106. // OCPP Path
  107. //===============================
  108. extern char OcppPath[160];
  109. extern char OcppProtocol[10];
  110. extern char OcppHost[50];
  111. extern char OcppTempPath[50];
  112. static int OcppPort=0;
  113. //===============================
  114. // OCPP sign variable
  115. //===============================
  116. static int server_sign = FALSE;
  117. int server_pending = FALSE;
  118. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  119. static int BootNotificationInterval = 0;
  120. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  121. //===============================
  122. // OCPP auth variable
  123. //===============================
  124. static int authorizeRetryTimes = 0; //number of Retry times
  125. //===============================
  126. // OCPP StartTransaction transactionId variables
  127. //===============================
  128. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  129. //===============================
  130. // OCPP other variables
  131. //===============================
  132. //int isUpdateRequest = FALSE;
  133. static int HeartBeatWaitTime = 10;
  134. static int FirstHeartBeat = 0;
  135. static int FirmwareStatusNotificationStatus = 3; // Idle
  136. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  137. static char CurrentChargingProfileScheduleStr[30]={0};
  138. //========================================
  139. // OCPP status/previous related variables
  140. //========================================
  141. static int GunStatusInterval = 10;
  142. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  143. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  144. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  145. static int GbPreviousSystemStatus[GB_QUANTITY];
  146. static int AcPreviousSystemStatus[AC_QUANTITY];
  147. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  148. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  149. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  150. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  151. static int TransactionMessageAttemptsValue = 0;
  152. static int TransactionMessageRetryIntervalValue = 0;
  153. static struct OCPPAuthLocalElemet
  154. {
  155. int listVersionInt;
  156. char idTagstr[20];
  157. char parentIdTag[20];
  158. char expiryDate[30];
  159. char idTagstatus[16];
  160. }idTagQuery;
  161. //=============================================
  162. // OCPP HeartBeat Response Not Receive Counts
  163. //============================================
  164. static int HeartBeatWithNOResponse = 0;
  165. static int HeartBeatCountPerHour = 0;
  166. extern struct lws *wsi_client;
  167. extern struct lws_context *context;
  168. extern unsigned char SendBuffer[4096];
  169. extern int SendBufLen;
  170. extern char *random_uuid( char buf[37] );
  171. extern void split(char **arr, char *str, const char *del);
  172. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  173. extern int GetTransactionQueueNum(void);
  174. extern pthread_mutex_t mutex1;
  175. extern struct Charger_Info Charger;
  176. extern sqlite3 *db;
  177. int TransactionMessageAttemptsGet(void);
  178. int TransactionMessageRetryIntervalGet(void);
  179. int GetOcppConnStatus(void);
  180. void SetOcppConnStatus(uint8_t status);
  181. int updateSetting(char *key, char *value);
  182. int setKeyValue(char *key, char *value);
  183. void OCPP_get_TableAuthlocalAllData(void);
  184. void processUnkownKey(void);
  185. struct StructOCPPMeterValue
  186. {
  187. unsigned char TimeStamp[28];
  188. struct StructSampledValue SampledValue[10];
  189. };
  190. struct ClientTime
  191. {
  192. unsigned int Heartbeat;
  193. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  194. unsigned int StartTransaction;
  195. unsigned int StopTransaction;
  196. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  197. }clientTime;
  198. typedef union
  199. {
  200. //Operations Initiated by Central System
  201. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  202. struct
  203. {
  204. //CsMsgValue[0]
  205. unsigned char StatusNotificationReq :1; //bit 0,
  206. unsigned char StatusNotificationConf :1; //bit 0,
  207. unsigned char :6; //bit 2~7
  208. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  209. }CpinitiateMsg;
  210. CpinitiateMsg cpinitateMsg;
  211. //==========================================
  212. // Init all Enumeration & Mapping String
  213. //==========================================
  214. /*ChargePointErrorCode*/
  215. typedef enum {
  216. ConnectorLockFailure,
  217. EVCommunicationError,
  218. GroundFailure,
  219. HighTemperature,
  220. InternalError,
  221. LocalListConflict,
  222. NoError,
  223. OtherError,
  224. OverCurrentFailure,
  225. OverVoltage,
  226. PowerMeterFailure,
  227. PowerSwitchFailure,
  228. ReaderFailure,
  229. ResetFailure,
  230. UnderVoltage,
  231. WeakSignal
  232. } ChargePointErrorCode;
  233. #if 0
  234. static char *ChargePointErrorCodeStr[] = {
  235. MACROSTR(ConnectorLockFailure),
  236. MACROSTR(EVCommunicationError),
  237. MACROSTR(GroundFailure),
  238. MACROSTR(HighTemperature),
  239. MACROSTR(InternalError),
  240. MACROSTR(LocalListConflict),
  241. MACROSTR(NoError),
  242. MACROSTR(OtherError),
  243. MACROSTR(OverCurrentFailure),
  244. MACROSTR(OverVoltage),
  245. MACROSTR(PowerMeterFailure),
  246. MACROSTR(PowerSwitchFailure),
  247. MACROSTR(ReaderFailure),
  248. MACROSTR(ResetFailure),
  249. MACROSTR(UnderVoltage),
  250. MACROSTR(WeakSignal)
  251. };
  252. #endif
  253. /*ChargePointStatus*/
  254. typedef enum {
  255. Available =0,
  256. Preparing,
  257. Charging,
  258. SuspendedEVSE,
  259. SuspendedEV,
  260. Finishing,
  261. Reserved,
  262. Unavailable,
  263. Faulted
  264. } ChargePointStatus;
  265. static char * ChargePointStatusStr[] = {
  266. MACROSTR(Available),
  267. MACROSTR(Preparing),
  268. MACROSTR(Charging),
  269. MACROSTR(SuspendedEVSE),
  270. MACROSTR(SuspendedEV),
  271. MACROSTR(Finishing),
  272. MACROSTR(Reserved),
  273. MACROSTR(Unavailable),
  274. MACROSTR(Faulted)
  275. };
  276. /*AvailabilityType*/
  277. typedef enum {
  278. RegistrationStatus_Accepted,
  279. RegistrationStatus_Pending,
  280. RegistrationStatus_Rejected
  281. } RegistrationStatus;
  282. static char *RegistrationStatusStr[] = {
  283. MACROSTR(Accepted),
  284. MACROSTR(Pending),
  285. MACROSTR(Rejected)
  286. };
  287. /*AvailabilityType*/
  288. typedef enum {
  289. Inoperative,
  290. Operative
  291. } AvailabilityType;
  292. static char *AvailabilityTypeStr[] = {
  293. MACROSTR(Inoperative),
  294. MACROSTR(Operative)
  295. };
  296. /*AvailabilityStatus*/
  297. typedef enum {
  298. Accepted,
  299. Rejected,
  300. Scheduled
  301. } AvailabilityStatus;
  302. static char *AvailabilityStatusStr[] = {
  303. MACROSTR(Accepted),
  304. MACROSTR(Rejected),
  305. MACROSTR(Scheduled)
  306. };
  307. /*ConfigurationStatus*/
  308. typedef enum {
  309. ConfigurationStatus_Accepted,
  310. ConfigurationStatus_Rejected,
  311. RebootRequired,
  312. NotSupported
  313. } ConfigurationStatus;
  314. static char *ConfigurationStatusStr[] = {
  315. MACROSTR(Accepted),
  316. MACROSTR(Rejected),
  317. MACROSTR(RebootRequired),
  318. MACROSTR(NotSupported)
  319. };
  320. /*ClearCacheStatus*/
  321. typedef enum {
  322. ClearCacheStatus_Accepted,
  323. ClearCacheStatus_Rejected
  324. } ClearCacheStatus;
  325. static char *ClearCacheStatusStr[] = {
  326. MACROSTR(Accepted),
  327. MACROSTR(Rejected)
  328. };
  329. /*ChargingProfilePurposeType*/
  330. typedef enum {
  331. ChargePointMaxProfile,
  332. TxDefaultProfile,
  333. TxProfile
  334. } ChargingProfilePurposeType;
  335. static char *ChargingProfilePurposeTypeStr[] = {
  336. MACROSTR(ChargePointMaxProfile),
  337. MACROSTR(TxDefaultProfile),
  338. MACROSTR(TxProfile)
  339. };
  340. /*ChargingProfileStatus*/
  341. typedef enum {
  342. ChargingProfileStatus_Accepted,
  343. ChargingProfileStatus_Rejected,
  344. ChargingProfileStatus_NotSupported
  345. } ChargingProfileStatus;
  346. static char *ChargingProfileStatusStr[] = {
  347. MACROSTR(Accepted),
  348. MACROSTR(Rejected),
  349. MACROSTR(NotSupported)
  350. };
  351. /*ClearChargingProfileStatus*/
  352. typedef enum {
  353. ClearChargingProfileStatus_Accepted,
  354. ClearChargingProfileStatus_Unknown
  355. } ClearChargingProfileStatus;
  356. static char *ClearChargingProfileStatusStr[] = {
  357. MACROSTR(Accepted),
  358. MACROSTR(Unknown)
  359. };
  360. /*GetCompositeScheduleStatus*/
  361. typedef enum {
  362. GetCompositeScheduleStatus_Accepted,
  363. GetCompositeScheduleStatus_Rejected
  364. } GetCompositeScheduleStatus;
  365. static char *GetCompositeScheduleStatusStr[] = {
  366. MACROSTR(Accepted),
  367. MACROSTR(Rejected)
  368. };
  369. /*ChargingRateUnitType*/
  370. typedef enum {
  371. ChargingRateUnitType_W,
  372. ChargingRateUnitType_A
  373. } ChargingRateUnitType;
  374. /*AuthorizationStatus*/
  375. typedef enum {
  376. AuthorizationStatus_Accepted ,
  377. AuthorizationStatus_Blocked ,
  378. AuthorizationStatus_Expired ,
  379. AuthorizationStatus_Invalid ,
  380. AuthorizationStatus_ConcurrentTx
  381. } AuthorizationStatus;
  382. /*UpdateType*/
  383. typedef enum {
  384. Differential ,
  385. Full
  386. } UpdateType;
  387. static char *UpdateTypeStr[] = {
  388. MACROSTR(Differential),
  389. MACROSTR(Full)
  390. };
  391. /*UpdateStatus*/
  392. typedef enum {
  393. UpdateStatus_Accepted ,
  394. UpdateStatus_Failed ,
  395. UpdateStatus_NotSupported ,
  396. UpdateStatus_VersionMismatch
  397. } UpdateStatus;
  398. static char *UpdateStatusStr[] = {
  399. MACROSTR(Accepted),
  400. MACROSTR(Failed),
  401. MACROSTR(NotSupported),
  402. MACROSTR(VersionMismatch)
  403. };
  404. /*RemoteStartStopStatus*/
  405. typedef enum {
  406. RemoteStartStopStatus_Accepted,
  407. RemoteStartStopStatus_Rejected
  408. } RemoteStartStopStatus;
  409. static char *RemoteStartStopStatusStr[] = {
  410. MACROSTR(Accepted),
  411. MACROSTR(Rejected)
  412. };
  413. /*ReservationStatus*/
  414. typedef enum {
  415. ReservationStatus_Accepted,
  416. ReservationStatus_Faulted,
  417. ReservationStatus_Occupied,
  418. ReservationStatus_Rejected,
  419. ReservationStatus_Unavailable
  420. } ReservationStatus;
  421. static char *ReservationStatusStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Faulted),
  424. MACROSTR(Occupied),
  425. MACROSTR(Rejected),
  426. MACROSTR(Unavailable)
  427. };
  428. /*ResetType*/
  429. typedef enum {
  430. Hard,
  431. Soft
  432. } ResetType;
  433. static char *ResetTypeStr[] = {
  434. MACROSTR(Hard),
  435. MACROSTR(Soft)
  436. };
  437. /*ResetStatus*/
  438. typedef enum {
  439. ResetStatus_Accepted,
  440. ResetStatus_Rejected
  441. } ResetStatus;
  442. static char *ResetStatusStr[] = {
  443. MACROSTR(Accepted),
  444. MACROSTR(Rejected)
  445. };
  446. /*DiagnosticsStatus*/
  447. typedef enum {
  448. DiagnosticsStatus_Idle,
  449. DiagnosticsStatus_Uploaded,
  450. DiagnosticsStatus_UploadFailed,
  451. DiagnosticsStatus_Uploading
  452. } DiagnosticsStatus;
  453. static char * DiagnosticsStatusStr[] = {
  454. MACROSTR(Idle),
  455. MACROSTR(Uploaded),
  456. MACROSTR(UploadFailed),
  457. MACROSTR(Uploading)
  458. };
  459. /*FirmwareStatus*/
  460. typedef enum {
  461. FirmwareStatus_Downloaded,
  462. FirmwareStatus_DownloadFailed,
  463. FirmwareStatus_Downloading,
  464. FirmwareStatus_Idle,
  465. FirmwareStatus_InstallationFailed,
  466. FirmwareStatus_Installing,
  467. FirmwareStatus_Installed
  468. } FirmwareStatus;
  469. static char * FirmwareStatusStr[] = {
  470. MACROSTR(Downloaded),
  471. MACROSTR(DownloadFailed),
  472. MACROSTR(Downloading),
  473. MACROSTR(Idle),
  474. MACROSTR(InstallationFailed),
  475. MACROSTR(Installing),
  476. MACROSTR(Installed)
  477. };
  478. /*MessageTrigger*/
  479. typedef enum {
  480. BootNotification,
  481. DiagnosticsStatusNotification,
  482. FirmwareStatusNotification,
  483. Heartbeat,
  484. MeterValues,
  485. StatusNotification
  486. } MessageTrigger;
  487. static char * MessageTriggerStr[] = {
  488. MACROSTR(BootNotification),
  489. MACROSTR(DiagnosticsStatusNotification),
  490. MACROSTR(FirmwareStatusNotification),
  491. MACROSTR(Heartbeat),
  492. MACROSTR(MeterValues),
  493. MACROSTR(StatusNotification)
  494. };
  495. /*TriggerMessageStatus*/
  496. typedef enum {
  497. TriggerMessageStatus_Accepted ,
  498. TriggerMessageStatus_Rejected ,
  499. TriggerMessageStatus_NotImplemented
  500. } TriggerMessageStatus;
  501. static char * TriggerMessageStatusStr[] = {
  502. MACROSTR(Accepted),
  503. MACROSTR(Rejected),
  504. MACROSTR(NotImplemented)
  505. };
  506. /*UnlockStatus*/
  507. typedef enum {
  508. Unlocked,
  509. UnlockFailed,
  510. UnlockStatus_NotSupported
  511. } UnlockStatus;
  512. static char * UnlockStatusStr[] = {
  513. MACROSTR(Unlocked),
  514. MACROSTR(UnlockFailed),
  515. MACROSTR(NotSupported)
  516. };
  517. /*StopTransactionReason*/
  518. typedef enum {
  519. EmergencyStop,
  520. EVDisconnected,
  521. HardReset,
  522. Local,
  523. Other,
  524. PowerLoss,
  525. Reboot,
  526. Remote,
  527. SoftReset,
  528. UnlockCommand,
  529. DeAuthorized
  530. } StopTransactionReason;
  531. #if 0
  532. static char * StopTransactionReasonStr[] = {
  533. MACROSTR(EmergencyStop),
  534. MACROSTR(EVDisconnected),
  535. MACROSTR(HardReset),
  536. MACROSTR(Local),
  537. MACROSTR(Other),
  538. MACROSTR(PowerLoss),
  539. MACROSTR(Reboot),
  540. MACROSTR(Remote),
  541. MACROSTR(SoftReset),
  542. MACROSTR(UnlockCommand),
  543. MACROSTR(DeAuthorized)
  544. };
  545. #endif
  546. /*CancelReservationStatus*/
  547. typedef enum {
  548. CancelReservationStatus_Accepted,
  549. CancelReservationStatus_Rejected
  550. } CancelReservationStatus;
  551. static char * CancelReservationStatusStr[] = {
  552. MACROSTR(Accepted),
  553. MACROSTR(Rejected)
  554. };
  555. /*ReadingContext*/
  556. typedef enum {
  557. ReadingContext_Interruption_Begin,
  558. ReadingContext_Interruption_End,
  559. ReadingContext_Other,
  560. ReadingContext_Sample_Clock,
  561. ReadingContext_Sample_Periodic ,
  562. ReadingContext_Transaction_Begin ,
  563. ReadingContext_Transaction_End,
  564. ReadingContext_Trigger
  565. } ReadingContext;
  566. static char * ReadingContextStr[] = {
  567. MACROSTR(Interruption.Begin),
  568. MACROSTR(Interruption.End),
  569. MACROSTR(Other),
  570. MACROSTR(Sample.Clock),
  571. MACROSTR(Sample.Periodic),
  572. MACROSTR(Transaction.Begin),
  573. MACROSTR(Transaction.End),
  574. MACROSTR(Trigger)
  575. };
  576. /*ValueFormat*/
  577. typedef enum {
  578. Raw,
  579. SignedData
  580. } ValueFormat;
  581. static char * ValueFormatStr[] = {
  582. MACROSTR(Raw),
  583. MACROSTR(SignedData)
  584. };
  585. /*Measurand*/
  586. typedef enum {
  587. Current_Export ,
  588. Current_Import,
  589. Current_Offered,
  590. Energy_Active_Export_Register,
  591. Energy_Active_Import_Register,
  592. Energy_Reactive_Export_Register,
  593. Energy_Reactive_Import_Register,
  594. Energy_Active_Export_Interval,
  595. Energy_Active_Import_Interval,
  596. Energy_Reactive_Export_Interval,
  597. Energy_Reactive_Import_Interval,
  598. Frequency,
  599. Power_Active_Export ,
  600. Power_Active_Import,
  601. Power_Factor,
  602. Power_Offered,
  603. Power_Reactive_Export,
  604. Power_Reactive_Import,
  605. RPM,
  606. SoC,
  607. Temperature ,
  608. Voltage
  609. } Measurand;
  610. static char * MeasurandStr[] = {
  611. MACROSTR(Current.Export),
  612. MACROSTR(Current.Import),
  613. MACROSTR(Current.Offered),
  614. MACROSTR(Energy.Active.Export.Register),
  615. MACROSTR(Energy.Active.Import.Register),
  616. MACROSTR(Energy.Reactive.Export.Register),
  617. MACROSTR(Energy.Reactive.Import.Register),
  618. MACROSTR(Energy.Active.Export.Interval),
  619. MACROSTR(Energy.Active.Import.Interval),
  620. MACROSTR(Energy.Reactive.Export.Interval),
  621. MACROSTR(Energy.Reactive.Import.Interval),
  622. MACROSTR(Frequency),
  623. MACROSTR(Power.Active.Export),
  624. MACROSTR(Power.Active.Import),
  625. MACROSTR(Power.Factor),
  626. MACROSTR(Power.Offered),
  627. MACROSTR(Power.Reactive.ExportMACROSTR),
  628. MACROSTR(Power.Reactive.Import),
  629. MACROSTR(RPM),
  630. MACROSTR(SoC),
  631. MACROSTR(Temperature),
  632. MACROSTR(Voltage)
  633. };
  634. /*Location*/
  635. typedef enum {
  636. Location_Body,
  637. Location_Cable,
  638. Location_EV,
  639. Location_Inlet ,
  640. Location_Outlet
  641. } Location;
  642. static char * LocationStr[] = {
  643. MACROSTR(Body),
  644. MACROSTR(Cable),
  645. MACROSTR(EV),
  646. MACROSTR(Inlet),
  647. MACROSTR(Outlet)
  648. };
  649. /*Phase*/
  650. typedef enum {
  651. L1,
  652. L2,
  653. L3,
  654. N,
  655. L1_N,
  656. L2_N,
  657. L3_N,
  658. L1_L2,
  659. L2_L3,
  660. L3_L1
  661. } Phase;
  662. static char * PhaseStr[] = {
  663. MACROSTR(L1),
  664. MACROSTR(L2),
  665. MACROSTR(L3),
  666. MACROSTR(N),
  667. MACROSTR(L1-N),
  668. MACROSTR(L2-N),
  669. MACROSTR(L3-N),
  670. MACROSTR(L1-L2),
  671. MACROSTR(L2-L3),
  672. MACROSTR(L3-L1)
  673. };
  674. /*UnitOfMeasure*/
  675. typedef enum {
  676. UnitOfMeasure_Wh,
  677. UnitOfMeasure_kWh ,
  678. UnitOfMeasure_varh ,
  679. UnitOfMeasure_kvarh ,
  680. UnitOfMeasure_W ,
  681. UnitOfMeasure_kW ,
  682. UnitOfMeasure_VA ,
  683. UnitOfMeasure_kVA ,
  684. UnitOfMeasure_var ,
  685. UnitOfMeasure_kvar ,
  686. UnitOfMeasure_A ,
  687. UnitOfMeasure_V ,
  688. UnitOfMeasure_Celsius ,
  689. UnitOfMeasure_Fahrenheit ,
  690. UnitOfMeasure_K ,
  691. UnitOfMeasure_Percent
  692. } UnitOfMeasure;
  693. static char * UnitOfMeasureStr[] = {
  694. MACROSTR(Wh),
  695. MACROSTR(kWh),
  696. MACROSTR(varh),
  697. MACROSTR(kvarh),
  698. MACROSTR(W),
  699. MACROSTR(kW),
  700. MACROSTR(VA),
  701. MACROSTR(kVA),
  702. MACROSTR(var),
  703. MACROSTR(kvar),
  704. MACROSTR(A),
  705. MACROSTR(V),
  706. MACROSTR(Celsius),
  707. MACROSTR(Fahrenheit),
  708. MACROSTR(K),
  709. MACROSTR(Percent)
  710. };
  711. #if 0
  712. /*Configuration enum*/
  713. enum CoreProfile {
  714. AllowOfflineTxForUnknownId=0,
  715. AuthorizationCacheEnabled,
  716. AuthorizeRemoteTxRequests,
  717. BlinkRepeat,
  718. ClockAlignedDataInterval,
  719. ConnectionTimeOut,
  720. GetConfigurationMaxKeys,
  721. HeartbeatInterval,
  722. LightIntensity,
  723. LocalAuthorizeOffline,
  724. LocalPreAuthorize,
  725. MaxEnergyOnInvalidId,
  726. MeterValuesAlignedData,
  727. MeterValuesAlignedDataMaxLength,
  728. MeterValuesSampledData,
  729. MeterValuesSampledDataMaxLength,
  730. MeterValueSampleInterval,
  731. MinimumStatusDuration,
  732. NumberOfConnectors,
  733. ResetRetries,
  734. ConnectorPhaseRotation,
  735. ConnectorPhaseRotationMaxLength,
  736. StopTransactionOnEVSideDisconnect,
  737. StopTransactionOnInvalidId,
  738. StopTxnAlignedData,
  739. StopTxnAlignedDataMaxLength,
  740. StopTxnSampledData,
  741. StopTxnSampledDataMaxLength,
  742. SupportedFeatureProfiles,
  743. SupportedFeatureProfilesMaxLength,
  744. TransactionMessageAttempts,
  745. TransactionMessageRetryInterval,
  746. UnlockConnectorOnEVSideDisconnect,
  747. WebSocketPingInterval,
  748. _CoreProfile_CNT
  749. };
  750. #endif
  751. enum LocalAuthListManagementProfile{
  752. LocalAuthListEnabled=0,
  753. LocalAuthListMaxLength,
  754. SendLocalListMaxLength,
  755. _LocalAuthListManagementProfile_CNT
  756. };
  757. enum ReservationProfile{
  758. ReserveConnectorZeroSupported
  759. };
  760. enum SmartChargingProfile{
  761. ChargeProfileMaxStackLevel,
  762. ChargingScheduleAllowedChargingRateUnit,
  763. ChargingScheduleMaxPeriods,
  764. ConnectorSwitch3to1PhaseSupported,
  765. MaxChargingProfilesInstalled
  766. };
  767. enum ChargerSystemStatus{
  768. ChargerSystemStatus_Booting,
  769. ChargerSystemStatus_Idle,
  770. ChargerSystemStatus_Authorizing,
  771. ChargerSystemStatus_Preparing,
  772. ChargerSystemStatus_Charging,
  773. ChargerSystemStatus_Terminating,
  774. ChargerSystemStatus_Alarm,
  775. ChargerSystemStatus_Fault
  776. };
  777. enum GetConfigurationKey {
  778. GetConfiguration_AllowOfflineTxForUnknownId=0,
  779. GetConfiguration_AuthorizationCacheEnabled,
  780. GetConfiguration_AuthorizeRemoteTxRequests,
  781. GetConfiguration_BlinkRepeat,
  782. GetConfiguration_ClockAlignedDataInterval,
  783. GetConfiguration_ConnectionTimeOut,
  784. GetConfiguration_GetConfigurationMaxKeys,
  785. GetConfiguration_HeartbeatInterval,
  786. GetConfiguration_LightIntensity,
  787. GetConfiguration_LocalAuthorizeOffline,
  788. GetConfiguration_LocalPreAuthorize,
  789. GetConfiguration_MaxEnergyOnInvalidId,
  790. GetConfiguration_MeterValuesAlignedData,
  791. GetConfiguration_MeterValuesAlignedDataMaxLength,
  792. GetConfiguration_MeterValuesSampledData,
  793. GetConfiguration_MeterValuesSampledDataMaxLength,
  794. GetConfiguration_MeterValueSampleInterval,
  795. GetConfiguration_MinimumStatusDuration,
  796. GetConfiguration_NumberOfConnectors,
  797. GetConfiguration_ResetRetries,
  798. GetConfiguration_ConnectorPhaseRotation,
  799. GetConfiguration_ConnectorPhaseRotationMaxLength,
  800. GetConfiguration_StopTransactionOnEVSideDisconnect,
  801. GetConfiguration_StopTransactionOnInvalidId,
  802. GetConfiguration_StopTxnAlignedData,
  803. GetConfiguration_StopTxnAlignedDataMaxLength,
  804. GetConfiguration_StopTxnSampledData,
  805. GetConfiguration_StopTxnSampledDataMaxLength,
  806. GetConfiguration_SupportedFeatureProfiles,
  807. GetConfiguration_SupportedFeatureProfilesMaxLength,
  808. GetConfiguration_TransactionMessageAttempts,
  809. GetConfiguration_TransactionMessageRetryInterval,
  810. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  811. GetConfiguration_WebSocketPingInterval,
  812. GetConfiguration_LocalAuthListEnabled,
  813. GetConfiguration_LocalAuthListMaxLength,
  814. GetConfiguration_SendLocalListMaxLength,
  815. GetConfiguration_ReserveConnectorZeroSupported,
  816. GetConfiguration_ChargeProfileMaxStackLevel,
  817. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  818. GetConfiguration_ChargingScheduleMaxPeriods,
  819. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  820. GetConfiguration_MaxChargingProfilesInstalled,
  821. };
  822. //GetConfiguration Array
  823. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  824. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  825. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  826. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  827. //==========================================
  828. // Init all share memory
  829. //==========================================
  830. int InitShareMemory()
  831. {
  832. int result = PASS;
  833. int MeterSMId;
  834. //creat ShmSysConfigAndInfo
  835. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  836. {
  837. #ifdef SystemLogMessage
  838. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  839. #endif
  840. result = FAIL;
  841. }
  842. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  843. {
  844. #ifdef SystemLogMessage
  845. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  846. #endif
  847. result = FAIL;
  848. }
  849. else
  850. {}
  851. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  852. {
  853. #ifdef SystemLogMessage
  854. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  855. #endif
  856. result = FAIL;
  857. }
  858. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  859. {
  860. #ifdef SystemLogMessage
  861. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  862. #endif
  863. result = FAIL;
  864. }
  865. else
  866. {}
  867. //creat ShmPsuData
  868. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  869. {
  870. #ifdef SystemLogMessage
  871. DEBUG_ERROR("shmget ShmPsuData NG\n");
  872. #endif
  873. result = FAIL;
  874. }
  875. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  876. {
  877. #ifdef SystemLogMessage
  878. DEBUG_ERROR("shmat ShmPsuData NG\n");
  879. #endif
  880. result = FAIL;
  881. }
  882. else
  883. {}
  884. //creat ShmOCPP16Data
  885. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  886. {
  887. #ifdef SystemLogMessage
  888. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  889. #endif
  890. result = FAIL;
  891. }
  892. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  893. {
  894. #ifdef SystemLogMessage
  895. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  896. #endif
  897. result = FAIL;
  898. }
  899. else
  900. {}
  901. /****************************** For Initial Settings************************************************/
  902. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  903. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  904. // allocate Configuration memory address
  905. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  906. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  907. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  908. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  909. return result;
  910. }
  911. int ProcessShareMemory()
  912. {
  913. if(InitShareMemory() == FAIL)
  914. {
  915. #ifdef SystemLogMessage
  916. DEBUG_ERROR("InitShareMemory NG\n");
  917. #endif
  918. if(ShmStatusCodeData!=NULL)
  919. {
  920. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  921. }
  922. sleep(5);
  923. return FAIL;
  924. }
  925. return PASS;
  926. }
  927. //---------------------common routine---------------------------//
  928. char * stringtrim( char * s )
  929. {
  930. char * p1 = s;
  931. char * p2 = s;
  932. while(*p1 != '\0')
  933. {
  934. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  935. {
  936. if(*p1 != ',')
  937. {
  938. p1 ++;
  939. }
  940. else
  941. {
  942. break;
  943. }
  944. }
  945. if(*p1 != ',')
  946. {
  947. * p2 ++ = *p1 ++;
  948. //printf("p2=%s\n",p2);
  949. }
  950. else
  951. {
  952. break;
  953. }
  954. }
  955. *p2 = '\0';
  956. return (s);
  957. }
  958. char * stringtrimspace( char * s )
  959. {
  960. char * p1 = s;
  961. char * p2 = s;
  962. while(*p1 != '\0')
  963. {
  964. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  965. {
  966. p1 ++;
  967. }
  968. * p2 ++ = *p1 ++;
  969. //printf("p2=%s\n",p2);
  970. }
  971. *p2 = '\0';
  972. return (s);
  973. }
  974. //---------------------------------------------
  975. // new:
  976. // enum SYSTEM_STATUS
  977. // {
  978. // SYS_MODE_BOOTING = 0,
  979. // SYS_MODE_IDLE = 1,
  980. // SYS_MODE_AUTHORIZING = 2,
  981. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  982. // SYS_MODE_REASSIGN = 4,
  983. // SYS_MODE_PREPARING = 5,
  984. // SYS_MODE_PREPARE_FOR_EV = 6,
  985. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  986. // SYS_MODE_CHARGING = 8,
  987. // SYS_MODE_TERMINATING = 9,
  988. // SYS_MODE_COMPLETE = 10,
  989. // SYS_MODE_ALARM = 11,
  990. // SYS_MODE_FAULT = 12,
  991. // SYS_MODE_RESERVATION = 13,
  992. // SYS_MODE_BOOKING = 14,
  993. // SYS_MODE_MAINTAIN = 15,
  994. // SYS_MODE_DEBUG = 16,
  995. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  996. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  997. // SYS_MODE_UPDATE = 19
  998. // };
  999. //
  1000. //
  1001. //-----------------------------------------
  1002. void CheckSystemValue(void)
  1003. {
  1004. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1005. //int IdleModeCnt = 0;
  1006. char filenmae[100]={0};
  1007. char str[100]={0};
  1008. //===============================
  1009. // send Heartbeat
  1010. //===============================
  1011. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1012. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1013. {
  1014. clientTime.Heartbeat=time((time_t*)NULL);
  1015. if(server_sign == TRUE)
  1016. {
  1017. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1018. }
  1019. else
  1020. {
  1021. HeartBeatWaitTime = 10;
  1022. }
  1023. }
  1024. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1025. {
  1026. DEBUG_INFO("Heartbeat !!!\n");
  1027. //parameter for test
  1028. sendHeartbeatRequest(0);
  1029. //==============================================
  1030. // Reset Waiting Time
  1031. //==============================================
  1032. clientTime.Heartbeat=time((time_t*)NULL);
  1033. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1034. }
  1035. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1036. {
  1037. //===============================
  1038. // CSU Trigger Reset Conf
  1039. //===============================
  1040. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1041. {
  1042. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1043. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1044. {
  1045. server_sign = FALSE;
  1046. }
  1047. }
  1048. //===============================
  1049. // CSU Trigger Authorize Request
  1050. //===============================
  1051. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1052. {
  1053. sendAuthorizeRequest(0);
  1054. authorizeRetryTimes = authorizeRetryTimes + 1;
  1055. if(authorizeRetryTimes < 3)
  1056. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1057. }
  1058. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1059. {
  1060. authorizeRetryTimes = 0;
  1061. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1062. server_sign = FALSE;
  1063. }
  1064. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  1065. {
  1066. sendAuthorizeRequest(0);
  1067. }
  1068. //===============================
  1069. // CSU Trigger Smart Charging Profilw
  1070. //===============================
  1071. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1072. {
  1073. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1074. GetChargingProfileRequest(gun_index);
  1075. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1076. }
  1077. //==============================================
  1078. // Charger start transaction
  1079. //==============================================
  1080. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1081. {
  1082. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1083. sendStartTransactionRequest(gun_index);
  1084. clientTime.StartTransaction = time((time_t*)NULL);
  1085. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1086. }
  1087. //==============================================
  1088. // Charger stop transaction
  1089. //==============================================
  1090. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1091. {
  1092. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1093. sendStopTransactionRequest(gun_index);
  1094. clientTime.StopTransaction = time((time_t*)NULL);
  1095. }
  1096. //==============================================
  1097. // Charger status report
  1098. //==============================================
  1099. //--- Check Mode Change ---//
  1100. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1101. if(gunType[gun_index] == 'J')
  1102. {
  1103. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1104. {
  1105. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1106. {
  1107. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1108. {
  1109. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1110. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1111. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1112. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1113. statusModeChage[gun_index] = TRUE;
  1114. }
  1115. #if 1 // for TempStopTransaction
  1116. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1117. {
  1118. checkTempStopTransaction(gun_index);
  1119. }
  1120. #endif
  1121. }
  1122. }
  1123. }
  1124. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1125. {
  1126. for (int index = 0; index < CCS_QUANTITY; index++)
  1127. {
  1128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1129. {
  1130. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1131. {
  1132. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1133. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1134. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1135. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1136. statusModeChage[gun_index] = TRUE;
  1137. }
  1138. #if 1 // for TempStopTransaction
  1139. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1140. {
  1141. checkTempStopTransaction(gun_index);
  1142. }
  1143. #endif
  1144. }
  1145. }
  1146. }
  1147. else if(gunType[gun_index] == 'G')
  1148. {
  1149. for (int index = 0; index < GB_QUANTITY; index++)
  1150. {
  1151. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1152. {
  1153. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1154. {
  1155. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1156. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1157. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1158. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1159. statusModeChage[gun_index] = TRUE;
  1160. }
  1161. #if 1 // for TempStopTransaction
  1162. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1163. {
  1164. checkTempStopTransaction(gun_index);
  1165. }
  1166. #endif
  1167. }
  1168. }
  1169. }
  1170. else
  1171. {
  1172. for (int index = 0; index < AC_QUANTITY; index++)
  1173. {
  1174. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1175. {
  1176. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  1177. {
  1178. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1179. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1180. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1181. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1182. statusModeChage[gun_index] = TRUE;
  1183. }
  1184. #if 1 // for TempStopTransaction
  1185. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1186. {
  1187. checkTempStopTransaction(gun_index);
  1188. }
  1189. #endif
  1190. }
  1191. }// END
  1192. }
  1193. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1194. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1195. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1196. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1197. {
  1198. if(SystemInitial > 0)
  1199. SystemInitial = SystemInitial -1;
  1200. sendStatusNotificationRequest(gun_index);
  1201. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1202. statusModeChage[gun_index] = FALSE;
  1203. DEBUG_INFO("SystemInitial=%d !!!\n",SystemInitial);
  1204. DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1205. DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1206. DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1207. }
  1208. //==============================================
  1209. // Meter report
  1210. //==============================================
  1211. if(/*(server_sign == TRUE) &&*/ ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1212. {
  1213. //check Transaction active
  1214. if(gunType[gun_index] == 'J')
  1215. {
  1216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1217. {
  1218. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1219. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1220. {
  1221. meterValueSend[gun_index] =1;
  1222. }
  1223. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1224. {
  1225. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1226. if((access(filenmae,F_OK))!=-1)
  1227. {
  1228. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1229. sprintf(str,"rm -f %s",filenmae);
  1230. system(str);
  1231. }
  1232. }
  1233. }// End for CHAdeMO
  1234. }
  1235. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1236. {
  1237. for (int index = 0; index < CCS_QUANTITY; index++)
  1238. {
  1239. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1240. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1241. {
  1242. meterValueSend[gun_index] =1;
  1243. }
  1244. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1245. {
  1246. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1247. if((access(filenmae,F_OK))!=-1)
  1248. {
  1249. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1250. sprintf(str,"rm -f %s",filenmae);
  1251. system(str);
  1252. }
  1253. }
  1254. } // End for CCS
  1255. }
  1256. else if(gunType[gun_index] == 'G')
  1257. {
  1258. for (int index = 0; index < GB_QUANTITY; index++)
  1259. {
  1260. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1261. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1262. {
  1263. meterValueSend[gun_index] =1;
  1264. }
  1265. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1266. {
  1267. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1268. if((access(filenmae,F_OK))!=-1)
  1269. {
  1270. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1271. sprintf(str,"rm -f %s",filenmae);
  1272. system(str);
  1273. }
  1274. }
  1275. }// End for GB
  1276. }
  1277. else
  1278. {
  1279. for (int index = 0; index < AC_QUANTITY; index++)
  1280. {
  1281. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1282. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1283. {
  1284. meterValueSend[gun_index] =1;
  1285. }
  1286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1287. {
  1288. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1289. if((access(filenmae,F_OK))!=-1)
  1290. {
  1291. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1292. sprintf(str,"rm -f %s",filenmae);
  1293. system(str);
  1294. }
  1295. }
  1296. }//End for AC
  1297. }
  1298. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1299. if(meterValueSend[gun_index] == 1)
  1300. {
  1301. sendMeterValuesRequest(gun_index);
  1302. #if 1 // for TempStopTransaction
  1303. storeTempStopTransaction(gun_index);
  1304. #endif
  1305. }
  1306. }
  1307. //==============================================
  1308. // Check Connector reserved
  1309. //==============================================
  1310. //===============================
  1311. // Check if Reserve is expired
  1312. //===============================
  1313. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1314. {
  1315. double diff_t;
  1316. struct tm tp;
  1317. // current time
  1318. time_t t = time(NULL);
  1319. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1320. tp.tm_isdst = -1;
  1321. time_t utc = mktime(&tp);
  1322. diff_t = difftime(utc, t);
  1323. if(diff_t <= 0)
  1324. {
  1325. DEBUG_INFO("reserve expired !!! \n");
  1326. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1327. }
  1328. }//END OF Check if Reserve is expired
  1329. //==========================================
  1330. // csu trigger FirmwareStatusNotificationReq
  1331. //==========================================
  1332. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1333. {
  1334. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1335. }
  1336. //==========================================
  1337. // csu trigger CancelReservationConf
  1338. //==========================================
  1339. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1340. {
  1341. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1342. }
  1343. //==========================================
  1344. // csu trigger ChangeAvailabilityConf
  1345. //==========================================
  1346. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1347. {
  1348. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1349. }
  1350. //==========================================
  1351. // csu trigger UnlockConnectorConf
  1352. //==========================================
  1353. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1354. {
  1355. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1356. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1357. }
  1358. //==========================================
  1359. // csu trigger ReserveNowConf
  1360. //==========================================
  1361. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1362. {
  1363. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1364. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1365. }
  1366. //==========================================
  1367. // csu trigger DataTransferReq
  1368. //==========================================
  1369. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1370. {
  1371. sendDataTransferRequest(gun_index);
  1372. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1373. }
  1374. }
  1375. }
  1376. //==========================================
  1377. // send request routine
  1378. //==========================================
  1379. int sendAuthorizeRequest(int gun_index)
  1380. {
  1381. mtrace();
  1382. int result = FAIL;
  1383. char message[100]={0};
  1384. char guid[37];
  1385. char tempdata[65]={0};
  1386. DEBUG_INFO("sendAuthorizeRequest \n");
  1387. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1388. //Local Authorize
  1389. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1390. {
  1391. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1392. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1393. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1394. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1395. result = PASS;
  1396. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1397. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1398. authorizeRetryTimes = 0;
  1399. return result;
  1400. }
  1401. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  1402. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1403. {
  1404. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1405. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1406. {
  1407. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1408. {
  1409. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1410. }
  1411. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1412. {
  1413. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1414. }
  1415. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1416. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1419. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1420. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1421. authorizeRetryTimes = 0;
  1422. return result;
  1423. }
  1424. else
  1425. {
  1426. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1427. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1428. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1429. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1430. result = PASS;
  1431. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1432. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1433. authorizeRetryTimes = 0;
  1434. return result;
  1435. }
  1436. }
  1437. //initailize struct Authorize
  1438. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1439. //get data from shared memory
  1440. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1441. random_uuid(guid);
  1442. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1443. LWS_Send(message);
  1444. sprintf(tempdata, "Authorize,%d", gun_index);
  1445. if(hashmap_operation(0, guid, tempdata) == 1)
  1446. {
  1447. result = PASS;
  1448. DEBUG_ERROR("Authorize mapItem pass\n");
  1449. }
  1450. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1451. return result;
  1452. }
  1453. int sendBootNotificationRequest(void)
  1454. {
  1455. mtrace();
  1456. int result = FAIL;
  1457. char message[500]={0}, payload[700]={0};
  1458. char guid[37]={0};
  1459. char tempdata[65]={0};
  1460. int IsGunCharging = FALSE;
  1461. //check Transaction active
  1462. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1463. {
  1464. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1465. {
  1466. IsGunCharging = TRUE;
  1467. }
  1468. }
  1469. for (int index = 0; index < CCS_QUANTITY; index++)
  1470. {
  1471. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1472. {
  1473. IsGunCharging = TRUE;
  1474. }
  1475. }
  1476. for (int index = 0; index < GB_QUANTITY; index++)
  1477. {
  1478. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1479. {
  1480. IsGunCharging = TRUE;
  1481. }
  1482. }
  1483. for (int index = 0; index < AC_QUANTITY; index++)
  1484. {
  1485. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1486. {
  1487. IsGunCharging = TRUE;
  1488. }
  1489. }
  1490. if(IsGunCharging == TRUE)
  1491. {
  1492. server_sign = TRUE;
  1493. return result;
  1494. }
  1495. // Fill BootNotification fields
  1496. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1497. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1498. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1499. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1500. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1501. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1502. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1503. #if 0
  1504. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1505. ShmOCPP16Data->ChargeBoxId
  1506. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1507. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1508. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1509. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1510. ,ShmOCPP16Data->BootNotification.CpIccid
  1511. ,ShmOCPP16Data->BootNotification.CpImsi
  1512. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1513. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1514. #endif
  1515. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1516. ShmOCPP16Data->ChargeBoxId
  1517. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1518. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1519. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1520. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1521. ,ShmOCPP16Data->BootNotification.CpIccid
  1522. ,ShmOCPP16Data->BootNotification.CpImsi);
  1523. random_uuid(guid);
  1524. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1525. LWS_Send(message);
  1526. sprintf(tempdata, "BootNotification,0");
  1527. 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*/)
  1528. {
  1529. result = PASS;
  1530. }
  1531. memset(queuedata, 0, sizeof(queuedata));
  1532. strcpy(queuedata,message);
  1533. return result;
  1534. }
  1535. int sendDataTransferRequest(int gun_index)
  1536. {
  1537. mtrace();
  1538. char message[1000]={0};
  1539. char guid[37]={0};
  1540. char tempdata[65]={0};
  1541. int result = FAIL;
  1542. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1543. random_uuid(guid);
  1544. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1545. MESSAGE_TYPE_CALL,
  1546. guid,
  1547. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1548. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1549. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1550. LWS_Send(message);
  1551. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1552. 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*/)
  1553. {
  1554. result = PASS;
  1555. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1556. }
  1557. return result;
  1558. }
  1559. int sendDiagnosticsStatusNotificationRequest(char *status)
  1560. {
  1561. mtrace();
  1562. int result = FAIL;
  1563. char message[110]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1567. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1568. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1569. random_uuid(guid);
  1570. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1571. LWS_Send(message);
  1572. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1573. if(hashmap_operation(0, guid, tempdata) == 1)
  1574. {
  1575. result = PASS;
  1576. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1577. }
  1578. //#ifdef SystemLogMessage
  1579. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1580. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1581. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1582. //#endif
  1583. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1584. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1585. //record status
  1586. if(strcmp(status,"Idle")==0)
  1587. {
  1588. DiagnosticsStatusNotificationStatus = 0;
  1589. }
  1590. else if(strcmp(status,"Uploaded")==0)
  1591. {
  1592. DiagnosticsStatusNotificationStatus = 1;
  1593. }
  1594. else if(strcmp(status,"UploadFailed")==0)
  1595. {
  1596. DiagnosticsStatusNotificationStatus = 2;
  1597. }
  1598. else if(strcmp(status,"Uploading")==0)
  1599. {
  1600. DiagnosticsStatusNotificationStatus = 3;
  1601. }
  1602. return result;
  1603. }
  1604. int sendFirmwareStatusNotificationRequest(char *status)
  1605. {
  1606. mtrace();
  1607. int result = FAIL;
  1608. char message[110]={0};
  1609. char guid[37]={0};
  1610. char tempdata[65]={0};
  1611. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1612. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1613. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1614. random_uuid(guid);
  1615. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1616. LWS_Send(message);
  1617. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1618. 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*/)
  1619. {
  1620. result = PASS;
  1621. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1622. }
  1623. //#ifdef SystemLogMessage
  1624. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1625. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1626. //#endif
  1627. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1628. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1629. //record status
  1630. if(strcmp(status,"Downloaded")==0)
  1631. {
  1632. FirmwareStatusNotificationStatus = 0;
  1633. }
  1634. else if(strcmp(status,"DownloadFailed")==0)
  1635. {
  1636. FirmwareStatusNotificationStatus = 1;
  1637. }
  1638. else if(strcmp(status,"Downloading")==0)
  1639. {
  1640. FirmwareStatusNotificationStatus = 2;
  1641. }
  1642. else if(strcmp(status,"Idle")==0)
  1643. {
  1644. FirmwareStatusNotificationStatus = 3;
  1645. }
  1646. else if(strcmp(status,"InstallationFailed")==0)
  1647. {
  1648. FirmwareStatusNotificationStatus = 4;
  1649. }
  1650. else if(strcmp(status,"Installing")==0)
  1651. {
  1652. FirmwareStatusNotificationStatus = 5;
  1653. }
  1654. else if(strcmp(status,"Installed")==0)
  1655. {
  1656. FirmwareStatusNotificationStatus = 6;
  1657. }
  1658. return result;
  1659. }
  1660. int sendHeartbeatRequest(int gun_index)
  1661. {
  1662. mtrace();
  1663. int result = FAIL;
  1664. char message[80]={0};
  1665. char guid[37]={0};
  1666. char tempdata[65]={0};
  1667. random_uuid(guid);
  1668. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1669. , MESSAGE_TYPE_CALL
  1670. , guid );
  1671. LWS_Send(message);
  1672. sprintf(tempdata, "Heartbeat,%d", 0);
  1673. 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*/)
  1674. {
  1675. result = PASS;
  1676. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1677. }
  1678. return result;
  1679. }
  1680. int sendStartTransactionRequest(int gun_index)
  1681. {
  1682. mtrace();
  1683. int result = FAIL;
  1684. char message[250]={0};
  1685. char guid[37]={0};
  1686. struct timeval tmnow;
  1687. struct tm *tm;
  1688. char buf[28];//, usec_buf[6];
  1689. char tempdata[65]={0};
  1690. int tempIndex = 0;
  1691. DEBUG_INFO("sendStartTransactionRequest...");
  1692. gettimeofday(&tmnow, NULL);
  1693. time_t t;
  1694. t = time(NULL);
  1695. /*UTC time and date*/
  1696. tm = gmtime(&t);
  1697. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1698. #if 0 // remove temporally
  1699. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1700. strcat(buf,".");
  1701. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1702. strcat(buf,usec_buf);
  1703. #endif
  1704. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1705. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1706. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1707. // clear StartTransaction Response
  1708. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1709. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1710. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1711. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1712. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1713. if(gunType[gun_index] == 'J')
  1714. {
  1715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1716. {
  1717. tempIndex = ((gun_index==2) ? 1: 0);
  1718. }
  1719. else
  1720. {
  1721. tempIndex = gun_index;
  1722. }
  1723. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1724. {
  1725. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1726. {
  1727. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1728. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1729. }
  1730. }
  1731. }
  1732. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1733. {
  1734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1735. {
  1736. tempIndex = ((gun_index==2) ? 1: 0);
  1737. }
  1738. else
  1739. {
  1740. tempIndex = gun_index;
  1741. }
  1742. for (int index = 0; index < CCS_QUANTITY; index++)
  1743. {
  1744. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1745. {
  1746. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1747. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1748. }
  1749. }
  1750. }
  1751. else if(gunType[gun_index] == 'G')
  1752. {
  1753. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1754. {
  1755. tempIndex = ((gun_index==2) ? 1: 0);
  1756. }
  1757. else
  1758. {
  1759. tempIndex = gun_index;
  1760. }
  1761. for (int index = 0; index < GB_QUANTITY; index++)
  1762. {
  1763. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1764. {
  1765. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1766. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1767. }
  1768. }
  1769. }
  1770. else
  1771. {
  1772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1773. {
  1774. tempIndex = 2;
  1775. }
  1776. else
  1777. {
  1778. tempIndex = gun_index;
  1779. }
  1780. for (int index = 0; index < AC_QUANTITY; index++)
  1781. {
  1782. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1783. {
  1784. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1785. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1786. }
  1787. }
  1788. }
  1789. random_uuid(guid);
  1790. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1791. , MESSAGE_TYPE_CALL
  1792. , guid
  1793. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1794. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1795. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1796. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1797. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1798. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1799. 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*/)
  1800. {
  1801. result = PASS;
  1802. }
  1803. strcpy(queuedata, message);
  1804. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1805. if(GetTransactionQueueNum() == 1)
  1806. {
  1807. LWS_Send(message);
  1808. }
  1809. return result;
  1810. }
  1811. int sendStatusNotificationRequest(int gun_index)
  1812. {
  1813. mtrace();
  1814. int result = FAIL;
  1815. char message[600]={0};
  1816. char guid[37];
  1817. int currentStatus = 0;
  1818. struct timeval tmnow;
  1819. struct tm *tm;
  1820. char buf[28];//, usec_buf[6];
  1821. char tempdata[65]={0};
  1822. int tempIndex = 0;
  1823. gettimeofday(&tmnow, NULL);
  1824. time_t t;
  1825. t = time(NULL);
  1826. /*UTC time and date*/
  1827. tm = gmtime(&t);
  1828. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1829. #if 0 // remove temporally
  1830. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1831. strcat(buf,".");
  1832. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1833. strcat(buf,usec_buf);
  1834. #endif
  1835. printf("%s",buf);
  1836. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1837. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1838. // it's option
  1839. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1840. /*
  1841. enum _SYSTEM_STATUS
  1842. {
  1843. S_BOOTING = 0,
  1844. S_IDLE, = 1
  1845. S_AUTHORIZING, =2
  1846. S_REASSIGN_CHECK, =3
  1847. S_REASSIGN, =4
  1848. S_PRECHARGE, =5
  1849. S_PREPARING_FOR_EV, =6
  1850. S_PREPARING_FOR_EVSE, =7
  1851. S_CHARGING, =8
  1852. S_TERMINATING, =9
  1853. S_COMPLETE, =10
  1854. S_ALARM, =11
  1855. S_FAULT =12
  1856. }
  1857. */
  1858. //check Transaction active
  1859. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1860. if(gunType[gun_index] == 'J')
  1861. {
  1862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1863. {
  1864. tempIndex = ((gun_index==2) ? 1: 0);
  1865. }
  1866. else
  1867. {
  1868. tempIndex = gun_index;
  1869. }
  1870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1871. {
  1872. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1873. {
  1874. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1875. {
  1876. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1877. {
  1878. currentStatus = 1; //OCPP Status: Preparing
  1879. }
  1880. else
  1881. {
  1882. currentStatus = 0; //OCPP Status: Available
  1883. }
  1884. }
  1885. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1886. {
  1887. currentStatus = 1; //OCPP Status: Preparing
  1888. }
  1889. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1890. {
  1891. currentStatus = 2; //OCPP Status: Charging
  1892. }
  1893. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1894. {
  1895. currentStatus = 5; //OCPP Status: Finishing
  1896. }
  1897. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1898. {
  1899. currentStatus = 4; //OCPP Status: SuspendedEV
  1900. }
  1901. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  1902. {
  1903. currentStatus = 7; //OCPP Status: Unavailable
  1904. }
  1905. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1906. {
  1907. currentStatus = 8; //OCPP Status: Faulted
  1908. }
  1909. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1910. {
  1911. currentStatus = 6; //OCPP Status: Reserved
  1912. }
  1913. } //end of the same index
  1914. }//end of for CHAdeMO_QUANTITY
  1915. }
  1916. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1917. {
  1918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1919. {
  1920. tempIndex = ((gun_index==2) ? 1: 0);
  1921. }
  1922. else
  1923. {
  1924. tempIndex = gun_index;
  1925. }
  1926. for (int index = 0; index < CCS_QUANTITY; index++)
  1927. {
  1928. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1929. {
  1930. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1931. {
  1932. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1933. {
  1934. currentStatus = 1; //OCPP Status: Preparing
  1935. }
  1936. else
  1937. {
  1938. currentStatus = 0; //OCPP Status: Available
  1939. }
  1940. }
  1941. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1942. {
  1943. currentStatus = 1; //OCPP Status: Preparing
  1944. }
  1945. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1946. {
  1947. currentStatus = 2; //OCPP Status: Charging
  1948. }
  1949. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1950. {
  1951. currentStatus = 5; //OCPP Status: Finishing
  1952. }
  1953. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1954. {
  1955. currentStatus = 4; //OCPP Status: SuspendedEV
  1956. }
  1957. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  1958. {
  1959. currentStatus = 7; //OCPP Status : Unavailable
  1960. }
  1961. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1962. {
  1963. currentStatus = 8; //OCPP Status: Faulted
  1964. }
  1965. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1966. {
  1967. currentStatus = 6; //OCPP Status: Reserved
  1968. }
  1969. } //end of the same index
  1970. } // end of for CCS_QUANTITY
  1971. }
  1972. else if(gunType[gun_index] == 'G')
  1973. {
  1974. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1975. {
  1976. tempIndex = ((gun_index==2) ? 1: 0);
  1977. }
  1978. else
  1979. {
  1980. tempIndex = gun_index;
  1981. }
  1982. for (int index = 0; index < GB_QUANTITY; index++)
  1983. {
  1984. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1985. {
  1986. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1987. {
  1988. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1989. {
  1990. currentStatus = 1; //OCPP Status: Preparing
  1991. }
  1992. else
  1993. {
  1994. currentStatus = 0; //OCPP Status: Available
  1995. }
  1996. }
  1997. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1998. {
  1999. currentStatus = 1; //OCPP Status: Preparing
  2000. }
  2001. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2002. {
  2003. currentStatus = 2; //OCPP Status: Charging
  2004. }
  2005. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2006. {
  2007. currentStatus = 5; //OCPP Status: Finishing
  2008. }
  2009. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2010. {
  2011. currentStatus = 4; //OCPP Status: SuspendedEV
  2012. }
  2013. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  2014. {
  2015. currentStatus = 7; //OCPP Status: Unavailable
  2016. }
  2017. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2018. {
  2019. currentStatus = 8; //OCPP Status: Faulted
  2020. }
  2021. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2022. {
  2023. currentStatus = 6; //OCPP Status: Reserved
  2024. }
  2025. } //end of the same index
  2026. } // end of for GB_QUANTITY
  2027. }
  2028. else
  2029. {
  2030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2031. {
  2032. tempIndex = 2;
  2033. }
  2034. else
  2035. {
  2036. tempIndex = gun_index;
  2037. }
  2038. for (int index = 0; index < AC_QUANTITY; index++)
  2039. {
  2040. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2041. {
  2042. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2043. {
  2044. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  2045. {
  2046. currentStatus = 1; //OCPP Status: Preparing
  2047. }
  2048. else
  2049. {
  2050. currentStatus = 0; //OCPP Status: Available
  2051. }
  2052. }
  2053. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2054. {
  2055. currentStatus = 1; //OCPP Status: Preparing
  2056. }
  2057. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2058. {
  2059. currentStatus = 2; //OCPP Status: Charging
  2060. }
  2061. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2062. {
  2063. currentStatus = 5; //OCPP Status: Finishing
  2064. }
  2065. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2066. {
  2067. currentStatus = 4; //OCPP Status: SuspendedEV
  2068. }
  2069. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  2070. {
  2071. currentStatus = 7; //OCPP Status: Unavailable
  2072. }
  2073. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2074. {
  2075. currentStatus = 8; //OCPP Status: Faulted
  2076. }
  2077. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2078. {
  2079. currentStatus = 6; //OCPP Status: Reserved
  2080. }
  2081. }//end of the same index
  2082. }//end of for AC_QUANTITY
  2083. }
  2084. //it's option
  2085. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2086. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2087. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2088. random_uuid(guid);
  2089. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2090. , MESSAGE_TYPE_CALL
  2091. , guid
  2092. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2093. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2094. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2095. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2096. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2097. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2098. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2099. LWS_Send(message);
  2100. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2101. 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*/)
  2102. {
  2103. //DEBUG_ERROR("statusNotification mapitem pass");
  2104. result = PASS;
  2105. }
  2106. return result;
  2107. }
  2108. int sendStopTransactionRequest(int gun_index)
  2109. {
  2110. mtrace();
  2111. int result = FAIL;
  2112. //char message[1500]={0};
  2113. char guid[37]={0};
  2114. char tempdata[65]={0};
  2115. int tempIndex = 0;
  2116. //int idx_sample=0;
  2117. DEBUG_ERROR("sendStopTransactionRequest \n");
  2118. memset(queuedata, 0, sizeof(queuedata));
  2119. //ENERGY_ACTIVE_IMPORT_REGISTER
  2120. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2121. if(gunType[gun_index] == 'J')
  2122. {
  2123. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2124. {
  2125. tempIndex = ((gun_index==2) ? 1: 0);
  2126. }
  2127. else
  2128. {
  2129. tempIndex = gun_index;
  2130. }
  2131. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2132. {
  2133. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2134. {
  2135. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2136. }
  2137. }// END OF CHAdeMO_QUANTITY
  2138. }
  2139. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2140. {
  2141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2142. {
  2143. tempIndex = ((gun_index==2) ? 1: 0);
  2144. }
  2145. else
  2146. {
  2147. tempIndex = gun_index;
  2148. }
  2149. for (int index = 0; index < CCS_QUANTITY; index++)
  2150. {
  2151. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2152. {
  2153. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2154. }
  2155. }// END OF CCS_QUANTITY
  2156. }
  2157. else if(gunType[gun_index] == 'G')
  2158. {
  2159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2160. {
  2161. tempIndex = ((gun_index==2) ? 1: 0);
  2162. }
  2163. else
  2164. {
  2165. tempIndex = gun_index;
  2166. }
  2167. for (int index = 0; index < GB_QUANTITY; index++)
  2168. {
  2169. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2170. {
  2171. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2172. }
  2173. }// END OF GB_QUANTITY
  2174. }
  2175. else
  2176. {
  2177. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2178. {
  2179. tempIndex = 2;
  2180. }
  2181. else
  2182. {
  2183. tempIndex = gun_index;
  2184. }
  2185. for (int index = 0; index < AC_QUANTITY; index++)
  2186. {
  2187. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2188. {
  2189. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2190. }
  2191. }// END OF AC_QUANTITY
  2192. }
  2193. //Stop Transaction Time
  2194. struct timeval tmnow;
  2195. struct tm *tm;
  2196. char buf[28];//, usec_buf[6];
  2197. gettimeofday(&tmnow, NULL);
  2198. time_t t;
  2199. t = time(NULL);
  2200. /*UTC time and date*/
  2201. tm = gmtime(&t);
  2202. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2204. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2205. random_uuid(guid);
  2206. /***********************************transactionData******************************************************/
  2207. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2208. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2209. //=================================
  2210. // Transaction_Begin
  2211. //=================================
  2212. // Energy.Active.Export.Interval
  2213. //idx_sample=0;
  2214. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2215. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2217. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  2218. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2219. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2220. {
  2221. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2222. }
  2223. else
  2224. {
  2225. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2226. }
  2227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2229. //=================================
  2230. // Transaction_End
  2231. //=================================
  2232. //Current.Export
  2233. //idx_sample=1;
  2234. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2235. if(gunType[gun_index] == 'J')
  2236. {
  2237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2238. {
  2239. tempIndex = ((gun_index==2) ? 1: 0);
  2240. }
  2241. else
  2242. {
  2243. tempIndex = gun_index;
  2244. }
  2245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2246. {
  2247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2248. {
  2249. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2250. }
  2251. }// End of for CHAdeMO_QUANTITY
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2253. }
  2254. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2255. {
  2256. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2257. {
  2258. tempIndex = ((gun_index==2) ? 1: 0);
  2259. }
  2260. else
  2261. {
  2262. tempIndex = gun_index;
  2263. }
  2264. for (int index = 0; index < CCS_QUANTITY; index++)
  2265. {
  2266. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2267. {
  2268. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2269. }
  2270. }// End of for CCS_QUANTITY
  2271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2272. }
  2273. else if(gunType[gun_index] == 'G')
  2274. {
  2275. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2276. {
  2277. tempIndex = ((gun_index==2) ? 1: 0);
  2278. }
  2279. else
  2280. {
  2281. tempIndex = gun_index;
  2282. }
  2283. for (int index = 0; index < GB_QUANTITY; index++)
  2284. {
  2285. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2286. {
  2287. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2288. }
  2289. }// End of for GB_QUANTITY
  2290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2291. }
  2292. else
  2293. {
  2294. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2295. {
  2296. tempIndex = 2;
  2297. }
  2298. else
  2299. {
  2300. tempIndex = gun_index;
  2301. }
  2302. for (int index = 0; index < AC_QUANTITY; index++)
  2303. {
  2304. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2305. {
  2306. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2307. }
  2308. }// End of for AC_QUANTITY
  2309. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2310. }
  2311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2312. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2314. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2316. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2317. //Energy.Active.Export.Interval
  2318. //idx_sample=2;
  2319. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2320. if(gunType[gun_index] == 'J')
  2321. {
  2322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2323. {
  2324. tempIndex = ((gun_index==2) ? 1: 0);
  2325. }
  2326. else
  2327. {
  2328. tempIndex = gun_index;
  2329. }
  2330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2331. {
  2332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2333. {
  2334. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2335. }
  2336. }// END OF CHAdeMO_QUANTITY
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2338. }
  2339. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2340. {
  2341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2342. {
  2343. tempIndex = ((gun_index==2) ? 1: 0);
  2344. }
  2345. else
  2346. {
  2347. tempIndex = gun_index;
  2348. }
  2349. for (int index = 0; index < CCS_QUANTITY; index++)
  2350. {
  2351. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2352. {
  2353. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2354. }
  2355. }// END OF CCS_QUANTITY
  2356. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2357. }
  2358. else if(gunType[gun_index] == 'G')
  2359. {
  2360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2361. {
  2362. tempIndex = ((gun_index==2) ? 1: 0);
  2363. }
  2364. else
  2365. {
  2366. tempIndex = gun_index;
  2367. }
  2368. for (int index = 0; index < GB_QUANTITY; index++)
  2369. {
  2370. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2371. {
  2372. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2373. }
  2374. }// END OF GB_QUANTITY
  2375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2376. }
  2377. else
  2378. {
  2379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2380. {
  2381. tempIndex = 2;
  2382. }
  2383. else
  2384. {
  2385. tempIndex = gun_index;
  2386. }
  2387. for (int index = 0; index < AC_QUANTITY; index++)
  2388. {
  2389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2390. {
  2391. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2392. }
  2393. }// END OF AC_QUANTITY
  2394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2395. }
  2396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2397. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2399. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2402. //Power.Active.Export
  2403. //idx_sample=3;
  2404. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2405. if(gunType[gun_index] == 'J')
  2406. {
  2407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2408. {
  2409. tempIndex = ((gun_index==2) ? 1: 0);
  2410. }
  2411. else
  2412. {
  2413. tempIndex = gun_index;
  2414. }
  2415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2416. {
  2417. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2418. {
  2419. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2420. }
  2421. } // End for CHAdeMO_QUANTITY
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2423. }
  2424. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2425. {
  2426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2427. {
  2428. tempIndex = ((gun_index==2) ? 1: 0);
  2429. }
  2430. else
  2431. {
  2432. tempIndex = gun_index;
  2433. }
  2434. for (int index = 0; index < CCS_QUANTITY; index++)
  2435. {
  2436. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2437. {
  2438. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2439. }
  2440. } // END for CCS_QUANTITY
  2441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2442. }
  2443. else if(gunType[gun_index] == 'G')
  2444. {
  2445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2446. {
  2447. tempIndex = ((gun_index==2) ? 1: 0);
  2448. }
  2449. else
  2450. {
  2451. tempIndex = gun_index;
  2452. }
  2453. for (int index = 0; index < GB_QUANTITY; index++)
  2454. {
  2455. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2456. {
  2457. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2458. }
  2459. }// END for GB_QUANTITY
  2460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2461. }
  2462. else
  2463. {
  2464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2465. {
  2466. tempIndex = 2;
  2467. }
  2468. else
  2469. {
  2470. tempIndex = gun_index;
  2471. }
  2472. for (int index = 0; index < AC_QUANTITY; index++)
  2473. {
  2474. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2475. {
  2476. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2477. }
  2478. } // END for AC_QUANTITY
  2479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2480. }
  2481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2484. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2487. //Voltage
  2488. //idx_sample=4;
  2489. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2490. if(gunType[gun_index] == 'J')
  2491. {
  2492. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2493. {
  2494. tempIndex = ((gun_index==2) ? 1: 0);
  2495. }
  2496. else
  2497. {
  2498. tempIndex = gun_index;
  2499. }
  2500. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2501. {
  2502. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2503. {
  2504. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2505. }
  2506. } // END OF FOR CHAdeMO_QUANTITY
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2508. }
  2509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2510. {
  2511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2512. {
  2513. tempIndex = ((gun_index==2) ? 1: 0);
  2514. }
  2515. else
  2516. {
  2517. tempIndex = gun_index;
  2518. }
  2519. for (int index = 0; index < CCS_QUANTITY; index++)
  2520. {
  2521. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2522. {
  2523. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2524. }
  2525. } // END OF FOR CCS_QUANTITY
  2526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2527. }
  2528. else if(gunType[gun_index] == 'G')
  2529. {
  2530. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2531. {
  2532. tempIndex = ((gun_index==2) ? 1: 0);
  2533. }
  2534. else
  2535. {
  2536. tempIndex = gun_index;
  2537. }
  2538. for (int index = 0; index < GB_QUANTITY; index++)
  2539. {
  2540. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2541. {
  2542. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2543. }
  2544. } // END OF FOR GB_QUANTITY
  2545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2546. }
  2547. else
  2548. {
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. {
  2551. tempIndex = 2;
  2552. }
  2553. else
  2554. {
  2555. tempIndex = gun_index;
  2556. }
  2557. for (int index = 0; index < AC_QUANTITY; index++)
  2558. {
  2559. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2560. {
  2561. 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
  2562. }
  2563. } // END OF FOR AC_QUANTITY
  2564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2565. }
  2566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2569. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2572. //SoC
  2573. //idx_sample=5;
  2574. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2575. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2576. {
  2577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2578. {
  2579. tempIndex = ((gun_index==2) ? 1: 0);
  2580. }
  2581. else
  2582. {
  2583. tempIndex = gun_index;
  2584. }
  2585. if(gunType[gun_index] == 'J')
  2586. {
  2587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2588. {
  2589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2590. {
  2591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2592. }
  2593. }
  2594. }
  2595. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2596. {
  2597. for (int index = 0; index < CCS_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2600. {
  2601. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2602. }
  2603. }
  2604. }
  2605. else if(gunType[gun_index] == 'G')
  2606. {
  2607. for (int index = 0; index < GB_QUANTITY; index++)
  2608. {
  2609. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2610. {
  2611. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2612. }
  2613. }
  2614. }
  2615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2620. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2621. } // END FOR DC CASE
  2622. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2623. {
  2624. 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\"}]}]}]"
  2625. ,MESSAGE_TYPE_CALL
  2626. ,guid
  2627. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2628. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2629. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2630. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2631. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2632. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2633. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2634. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2635. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2636. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2637. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2638. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2639. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2640. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2641. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2642. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2643. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2644. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2645. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2646. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2647. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2648. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2649. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2650. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2651. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2657. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2675. );
  2676. }
  2677. else
  2678. {
  2679. 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\"}]}]}]"
  2680. ,MESSAGE_TYPE_CALL
  2681. ,guid
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2687. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2701. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2702. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2703. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2704. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2705. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2706. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2723. );
  2724. }
  2725. #if 0 // for TempStopTransaction
  2726. //Delete TempStopTransaction
  2727. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2728. {
  2729. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2730. }
  2731. #endif
  2732. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2733. if(hashmap_operation(0, guid, tempdata) == 1)
  2734. {
  2735. result = PASS;
  2736. DEBUG_INFO("StopTransaction mapitem pass\n");
  2737. }
  2738. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2739. if(GetTransactionQueueNum() == 1)
  2740. {
  2741. LWS_Send(queuedata);
  2742. }
  2743. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2744. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2745. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2746. {
  2747. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2748. }
  2749. //for test
  2750. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2751. return result;
  2752. }
  2753. int sendMeterValuesRequest(int gun_index)
  2754. {
  2755. mtrace();
  2756. int result = FAIL;
  2757. // char message[1500]={0};
  2758. char guid[37]={0};
  2759. //int idx_sample=0;
  2760. //int length = 0;
  2761. char tempdata[65]={0};
  2762. int tempIndex = 0;
  2763. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2764. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2765. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2766. {
  2767. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2768. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2769. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2770. return result;
  2771. }
  2772. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2773. {
  2774. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2775. }
  2776. memset(queuedata, 0, sizeof(queuedata));
  2777. //set value
  2778. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2779. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2780. random_uuid(guid);
  2781. //UTC Date time
  2782. struct timeval tmnow;
  2783. struct tm *tm;
  2784. char buf[28];//, usec_buf[6];
  2785. gettimeofday(&tmnow, NULL);
  2786. time_t t;
  2787. t = time(NULL);
  2788. /*UTC time and date*/
  2789. tm = gmtime(&t);
  2790. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2791. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2792. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2793. //idx_sample=0;
  2794. //********************************(1)Current.Export************************************************/
  2795. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2796. if(gunType[gun_index] == 'J')
  2797. {
  2798. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2799. {
  2800. tempIndex = ((gun_index==2) ? 1: 0);
  2801. }
  2802. else
  2803. {
  2804. tempIndex = gun_index;
  2805. }
  2806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2807. {
  2808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2809. {
  2810. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2811. }
  2812. }
  2813. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2814. }
  2815. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2816. {
  2817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2818. {
  2819. tempIndex = ((gun_index==2) ? 1: 0);
  2820. }
  2821. else
  2822. {
  2823. tempIndex = gun_index;
  2824. }
  2825. for (int index = 0; index < CCS_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2828. {
  2829. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2830. }
  2831. }
  2832. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2833. }
  2834. else if(gunType[gun_index] == 'G')
  2835. {
  2836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2837. {
  2838. tempIndex = ((gun_index==2) ? 1: 0);
  2839. }
  2840. else
  2841. {
  2842. tempIndex = gun_index;
  2843. }
  2844. for (int index = 0; index < GB_QUANTITY; index++)
  2845. {
  2846. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2847. {
  2848. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2849. }
  2850. }
  2851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2852. }
  2853. else
  2854. {
  2855. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2856. {
  2857. tempIndex = 2;
  2858. }
  2859. else
  2860. {
  2861. tempIndex = gun_index;
  2862. }
  2863. for (int index = 0; index < AC_QUANTITY; index++)
  2864. {
  2865. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2866. {
  2867. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2868. }
  2869. }
  2870. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2871. }
  2872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2873. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2875. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2878. //idx_sample=1;
  2879. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2880. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2881. if(gunType[gun_index] == 'J')
  2882. {
  2883. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2884. {
  2885. tempIndex = ((gun_index==2) ? 1: 0);
  2886. }
  2887. else
  2888. {
  2889. tempIndex = gun_index;
  2890. }
  2891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2892. {
  2893. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2894. {
  2895. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  2896. }
  2897. } // END OF FOR CHAdeMO_QUANTITY
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2899. }
  2900. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2901. {
  2902. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2903. {
  2904. tempIndex = ((gun_index==2) ? 1: 0);
  2905. }
  2906. else
  2907. {
  2908. tempIndex = gun_index;
  2909. }
  2910. for (int index = 0; index < CCS_QUANTITY; index++)
  2911. {
  2912. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  2913. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2914. {
  2915. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  2916. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  2917. }
  2918. } // END OF CCS_QUANTITY
  2919. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2920. }
  2921. else if(gunType[gun_index] == 'G')
  2922. {
  2923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2924. {
  2925. tempIndex = ((gun_index==2) ? 1: 0);
  2926. }
  2927. else
  2928. {
  2929. tempIndex = gun_index;
  2930. }
  2931. for (int index = 0; index < GB_QUANTITY; index++)
  2932. {
  2933. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2934. {
  2935. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  2936. }
  2937. } // END OF GB_QUANTITY
  2938. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2939. }
  2940. else
  2941. {
  2942. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2943. {
  2944. tempIndex = 2;
  2945. }
  2946. else
  2947. {
  2948. tempIndex = gun_index;
  2949. }
  2950. for (int index = 0; index < AC_QUANTITY; index++)
  2951. {
  2952. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2953. {
  2954. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  2955. }
  2956. }
  2957. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2958. }
  2959. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2960. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2961. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  2962. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2963. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2964. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2965. //idx_sample=2;
  2966. //********************************(4)Power.Active.Export************************************************/
  2967. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2968. if(gunType[gun_index] == 'J')
  2969. {
  2970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2971. {
  2972. tempIndex = ((gun_index==2) ? 1: 0);
  2973. }
  2974. else
  2975. {
  2976. tempIndex = gun_index;
  2977. }
  2978. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2979. {
  2980. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2981. {
  2982. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  2983. }
  2984. } // END OF FOR
  2985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  2986. }
  2987. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2988. {
  2989. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2990. {
  2991. tempIndex = ((gun_index==2) ? 1: 0);
  2992. }
  2993. else
  2994. {
  2995. tempIndex = gun_index;
  2996. }
  2997. for (int index = 0; index < CCS_QUANTITY; index++)
  2998. {
  2999. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3000. {
  3001. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3002. }
  3003. }
  3004. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3005. }
  3006. else if(gunType[gun_index] == 'G')
  3007. {
  3008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3009. {
  3010. tempIndex = ((gun_index==2) ? 1: 0);
  3011. }
  3012. else
  3013. {
  3014. tempIndex = gun_index;
  3015. }
  3016. for (int index = 0; index < GB_QUANTITY; index++)
  3017. {
  3018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3019. {
  3020. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3021. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3022. }
  3023. }
  3024. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3025. }
  3026. else
  3027. {
  3028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3029. {
  3030. tempIndex = 2;
  3031. }
  3032. else
  3033. {
  3034. tempIndex = gun_index;
  3035. }
  3036. for (int index = 0; index < AC_QUANTITY; index++)
  3037. {
  3038. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3039. {
  3040. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3041. }
  3042. }
  3043. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3044. }
  3045. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3046. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3047. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Power_Active_Import]);
  3048. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3050. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3051. //idx_sample=3;
  3052. //***********************************************(5)VOLTAGE******************************************************/
  3053. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3054. if(gunType[gun_index] == 'J')
  3055. {
  3056. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3057. {
  3058. tempIndex = ((gun_index==2) ? 1: 0);
  3059. }
  3060. else
  3061. {
  3062. tempIndex = gun_index;
  3063. }
  3064. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3065. {
  3066. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3067. {
  3068. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3069. }
  3070. }
  3071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3072. }
  3073. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3074. {
  3075. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3076. {
  3077. tempIndex = ((gun_index==2) ? 1: 0);
  3078. }
  3079. else
  3080. {
  3081. tempIndex = gun_index;
  3082. }
  3083. for (int index = 0; index < CCS_QUANTITY; index++)
  3084. {
  3085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3086. {
  3087. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3088. }
  3089. }
  3090. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3091. }
  3092. else if(gunType[gun_index] == 'G')
  3093. {
  3094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3095. {
  3096. tempIndex = ((gun_index==2) ? 1: 0);
  3097. }
  3098. else
  3099. {
  3100. tempIndex = gun_index;
  3101. }
  3102. for (int index = 0; index < GB_QUANTITY; index++)
  3103. {
  3104. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3105. {
  3106. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3107. }
  3108. }
  3109. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3110. }
  3111. else
  3112. {
  3113. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3114. {
  3115. tempIndex = 2;
  3116. }
  3117. else
  3118. {
  3119. tempIndex = gun_index;
  3120. }
  3121. for (int index = 0; index < AC_QUANTITY; index++)
  3122. {
  3123. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3124. {
  3125. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3126. }
  3127. }
  3128. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3129. }
  3130. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3131. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Voltage]);
  3133. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3136. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3137. {
  3138. //idx_sample=4;
  3139. //sampledValue = NULL;
  3140. //***********************************************(6)SOC******************************************************/
  3141. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3142. {
  3143. tempIndex = ((gun_index==2) ? 1: 0);
  3144. }
  3145. else
  3146. {
  3147. tempIndex = gun_index;
  3148. }
  3149. if(gunType[gun_index] == 'J')
  3150. {
  3151. //tempIndex = ((gun_index==2) ? 1: 0);
  3152. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3153. {
  3154. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3155. {
  3156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3157. }
  3158. }
  3159. }
  3160. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3161. {
  3162. //tempIndex = ((gun_index==2) ? 1: 0);
  3163. for (int index = 0; index < CCS_QUANTITY; index++)
  3164. {
  3165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3166. {
  3167. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3168. }
  3169. }
  3170. }
  3171. else if(gunType[gun_index] == 'G')
  3172. {
  3173. //tempIndex = ((gun_index==2) ? 1: 0);
  3174. for (int index = 0; index < GB_QUANTITY; index++)
  3175. {
  3176. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3177. {
  3178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3179. }
  3180. }
  3181. }
  3182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3183. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3184. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[SoC]);
  3185. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3188. }
  3189. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3190. {
  3191. 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\"}]}]}]"
  3192. ,MESSAGE_TYPE_CALL
  3193. ,guid
  3194. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3195. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3196. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3197. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3198. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3199. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3200. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3201. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3202. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3203. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3204. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3205. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3206. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3207. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3208. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3209. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3210. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3211. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3212. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3213. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3214. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3215. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3216. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3217. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3218. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3219. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3220. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3221. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3222. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3223. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3224. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3225. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3226. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3227. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3228. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3229. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3230. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3231. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3232. );
  3233. }
  3234. else
  3235. {
  3236. 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\"}]}]}]"
  3237. ,MESSAGE_TYPE_CALL
  3238. ,guid
  3239. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3240. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3241. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3242. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3243. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3244. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3245. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3246. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3247. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3248. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3249. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3250. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3251. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3252. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3253. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3254. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3255. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3256. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3257. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3258. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3259. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3260. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3261. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3262. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3263. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3264. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3265. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3266. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3267. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3268. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3269. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3270. );
  3271. }
  3272. // Put request guid to hash map
  3273. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3274. 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*/)
  3275. {
  3276. result = PASS;
  3277. DEBUG_INFO("MeterValues mapitem pass\n");
  3278. }
  3279. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3280. if(GetTransactionQueueNum() == 1)
  3281. {
  3282. LWS_Send(queuedata);
  3283. }
  3284. return result;
  3285. }
  3286. //==========================================
  3287. // send confirm routine
  3288. //==========================================
  3289. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3290. {
  3291. mtrace();
  3292. int result = FAIL;
  3293. char message[100]={0};
  3294. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3295. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3296. LWS_Send(message);
  3297. result = TRUE;
  3298. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3299. return result;
  3300. }
  3301. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3302. {
  3303. mtrace();
  3304. int result = FAIL;
  3305. char message[100]={0};
  3306. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3307. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3308. LWS_Send(message);
  3309. result = TRUE;
  3310. return result;
  3311. }
  3312. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3313. {
  3314. mtrace();
  3315. int result = FAIL;
  3316. char message[100]={0};
  3317. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3318. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3319. LWS_Send(message);
  3320. result = TRUE;
  3321. return result;
  3322. }
  3323. int sendClearCacheConfirmation(char *uuid,char *payload)
  3324. {
  3325. mtrace();
  3326. int result = FAIL;
  3327. char message[500]={0};
  3328. // int count = 0;
  3329. // int gun_index = 0;
  3330. // char guid[37];
  3331. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3332. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3333. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3334. LWS_Send(message);
  3335. return result;
  3336. }
  3337. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3338. {
  3339. mtrace();
  3340. int result = FAIL;
  3341. char message[500]={0};
  3342. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3343. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3344. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3345. LWS_Send(message);
  3346. return result;
  3347. }
  3348. int sendDataTransferConfirmation(char *uuid,char *payload)
  3349. {
  3350. mtrace();
  3351. char statusStr[20]={0};
  3352. char dataStr[10]={0};
  3353. char sstr[20]={0};
  3354. int c = 0;
  3355. char *loc;
  3356. int result = FAIL;
  3357. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3358. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3359. /**********************status**************************/
  3360. loc = strstr(payload, "status");
  3361. memset(sstr ,0, sizeof(sstr) );
  3362. c = 0;
  3363. while (loc[3+strlen("status")+c] != '\"')
  3364. {
  3365. sstr[c] = loc[3+strlen("status")+c];
  3366. c++;
  3367. }
  3368. sstr[c] = '\0';
  3369. strcpy(statusStr, sstr);
  3370. /**********************data**************************/
  3371. loc = strstr(payload, "data");
  3372. memset(sstr ,0, sizeof(sstr) );
  3373. c = 0;
  3374. while (loc[3+strlen("data")+c] != '\"')
  3375. {
  3376. sstr[c] = loc[3+strlen("data")+c];
  3377. c++;
  3378. }
  3379. sstr[c] = '\0';
  3380. strcpy(dataStr, sstr);
  3381. return result;
  3382. }
  3383. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3384. {
  3385. mtrace();
  3386. int result = FAIL;
  3387. char message[1000]={0};
  3388. double diff_f = 0.0;
  3389. int diff_i = 0;
  3390. int diffSeconds = 0;
  3391. struct tm tp;
  3392. int TimeZero = FALSE;
  3393. int CompositeScheduleIndex = 0;
  3394. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3395. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3396. {
  3397. TimeZero = TRUE;
  3398. }
  3399. else
  3400. {
  3401. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3402. }
  3403. if(TimeZero == FALSE)
  3404. {
  3405. tp.tm_isdst = -1;
  3406. time_t utc = mktime(&tp);
  3407. time_t t = time(NULL);
  3408. diff_f = difftime(t, utc);
  3409. diff_i = (int)diff_f;
  3410. diffSeconds = diff_i % 86400;//86400 seconds/day
  3411. }
  3412. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3413. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3414. #if 0 //remove temporally
  3415. 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}"
  3416. ,MESSAGE_TYPE_CALLRESULT
  3417. ,uuid
  3418. ,payload
  3419. ,connectorIdInt
  3420. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3421. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3422. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3423. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3424. #endif
  3425. if(nPeriod == 0)
  3426. {
  3427. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3428. {
  3429. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3430. ,MESSAGE_TYPE_CALLRESULT
  3431. ,uuid
  3432. ,payload
  3433. ,connectorIdInt);
  3434. }
  3435. else
  3436. {
  3437. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3438. ,MESSAGE_TYPE_CALLRESULT
  3439. ,uuid
  3440. ,payload
  3441. ,connectorIdInt
  3442. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3443. }
  3444. }
  3445. else
  3446. {
  3447. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3448. ,MESSAGE_TYPE_CALLRESULT
  3449. ,uuid
  3450. ,payload
  3451. ,connectorIdInt
  3452. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3453. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3454. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3455. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3456. int len = nPeriod;
  3457. //Last Period StartPriod is less than diffSeconds
  3458. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3459. {
  3460. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3461. , 0
  3462. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3463. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3464. }
  3465. else
  3466. {
  3467. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3468. {
  3469. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) < diffSeconds) && ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample + 1].StartPeriod % 86400) > diffSeconds))//if (idx_sample == 0)
  3470. {
  3471. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3472. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3473. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3474. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3475. }
  3476. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3477. {
  3478. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3479. , ((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod % 86400) - diffSeconds /*-1*/)//(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds ) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/)) //(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/) <= 0)?(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod):(ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod - diffSeconds /*-1*/))
  3480. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3481. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3482. }
  3483. }
  3484. }
  3485. sprintf(message + strlen(message), "]}}]");
  3486. }
  3487. LWS_Send(message);
  3488. result = TRUE;
  3489. return result;
  3490. }
  3491. int sendGetConfigurationConfirmation(char *uuid)
  3492. {
  3493. mtrace();
  3494. int result = FAIL;
  3495. int MaxKeySupported = 0;
  3496. int sentConfigurationNumber= 0;
  3497. int sentunConfigurationNumber= 0;
  3498. char message[4000]={0};
  3499. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3500. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3501. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3502. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3503. ,MESSAGE_TYPE_CALLRESULT
  3504. ,uuid );
  3505. //configuration key
  3506. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3507. {
  3508. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3509. {
  3510. if (sentConfigurationNumber == 0)
  3511. {
  3512. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3513. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3514. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3515. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3516. }
  3517. else
  3518. {
  3519. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3520. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3521. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3522. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3523. }
  3524. sentConfigurationNumber = sentConfigurationNumber + 1;
  3525. }
  3526. }
  3527. sprintf(message + strlen(message), "]");
  3528. if(UnknownKeynum != 0)
  3529. {
  3530. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3531. //unkown key
  3532. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3533. {
  3534. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3535. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3536. if(sentunConfigurationNumber == 0)
  3537. {
  3538. sprintf(message + strlen(message), "\"%s\""
  3539. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3540. }
  3541. else
  3542. {
  3543. sprintf(message + strlen(message), ",\"%s\""
  3544. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3545. }
  3546. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3547. }
  3548. sprintf(message + strlen(message), "]");
  3549. }
  3550. sprintf(message + strlen(message), "}]");
  3551. LWS_Send(message);
  3552. return result;
  3553. }
  3554. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3555. {
  3556. mtrace();
  3557. int result = FAIL;
  3558. char message[400]={0};
  3559. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3560. if(strcmp(payload,"")==0)
  3561. {
  3562. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3563. }
  3564. else
  3565. {
  3566. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3567. }
  3568. LWS_Send(message);
  3569. result = TRUE;
  3570. return result;
  3571. }
  3572. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3573. {
  3574. mtrace();
  3575. int result = FAIL;
  3576. char message[80]={0};
  3577. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3578. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3579. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3580. LWS_Send(message);
  3581. result = TRUE;
  3582. return result;
  3583. }
  3584. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3585. {
  3586. mtrace();
  3587. int result = FAIL;
  3588. char message[80]={0};
  3589. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3590. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3591. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3592. LWS_Send(message);
  3593. result = TRUE;
  3594. return result;
  3595. }
  3596. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3597. {
  3598. mtrace();
  3599. int result = FAIL;
  3600. char message[80]={0};
  3601. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3602. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3603. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3604. LWS_Send(message);
  3605. result = TRUE;
  3606. return result;
  3607. }
  3608. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3609. {
  3610. mtrace();
  3611. int result = FAIL;
  3612. char message[80]={0};
  3613. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3614. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3615. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3616. LWS_Send(message);
  3617. result = TRUE;
  3618. return result;
  3619. }
  3620. int sendResetConfirmation(char *uuid,char *payload)
  3621. {
  3622. mtrace();
  3623. int result = FAIL;
  3624. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3625. char message[80]={0};
  3626. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3627. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3628. LWS_Send(message);
  3629. result = TRUE;
  3630. return result;
  3631. }
  3632. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3633. {
  3634. mtrace();
  3635. int result = FAIL;
  3636. char message[500]={0};
  3637. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3638. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3639. LWS_Send(message);
  3640. result = TRUE;
  3641. return result;
  3642. }
  3643. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3644. {
  3645. mtrace();
  3646. int result = FAIL;
  3647. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3648. char message[80]={0};
  3649. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3650. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3651. LWS_Send(message);
  3652. result = TRUE;
  3653. return result;
  3654. }
  3655. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3656. {
  3657. mtrace();
  3658. int result = FAIL;
  3659. char message[80]={0};
  3660. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3661. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3662. LWS_Send(message);
  3663. result = TRUE;
  3664. return result;
  3665. }
  3666. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3667. {
  3668. mtrace();
  3669. int result = FAIL;
  3670. char message[80]={0};
  3671. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3672. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3673. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3674. LWS_Send(message);
  3675. result = TRUE;
  3676. return result;
  3677. }
  3678. int sendUpdateFirmwareConfirmation(char *uuid)
  3679. {
  3680. mtrace();
  3681. int result = FAIL;
  3682. char message[60]={0};
  3683. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3684. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3685. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3686. LWS_Send(message);
  3687. result = TRUE;
  3688. return result;
  3689. }
  3690. //==========================================
  3691. // send CallError routine
  3692. //==========================================
  3693. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3694. {
  3695. mtrace();
  3696. //int result = FAIL;
  3697. char message[220]={0};
  3698. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3699. #ifdef SystemLogMessage
  3700. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3701. uniqueId, action, errorCode, errorDescription);
  3702. #endif
  3703. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3704. LWS_Send(message);
  3705. //result = TRUE;
  3706. }
  3707. //==========================================
  3708. // Handle server request routine Start
  3709. //==========================================
  3710. #define GUN_NUM 1
  3711. int handleCancelReservationRequest(char *uuid, char *payload)
  3712. {
  3713. mtrace();
  3714. int result = FAIL;
  3715. int gunNO = 0;
  3716. int reservationIdInt =0;
  3717. char comfirmstr[20];
  3718. int c = 0;
  3719. int copyTo = 0;
  3720. char *loc;
  3721. char sstr[100]={0};
  3722. DEBUG_INFO("handle CancelReservationRequest\n");
  3723. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3724. c = 0;
  3725. copyTo = 0;
  3726. loc = strstr(payload, "reservationId");
  3727. memset(sstr ,0, sizeof(sstr) );
  3728. while (loc[strlen("reservationId")+2+c] != '}')
  3729. {
  3730. if(loc[strlen("interval")+2+c] != ' ')
  3731. {
  3732. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3733. copyTo = copyTo + 1;
  3734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3735. }
  3736. c++;
  3737. }
  3738. sstr[copyTo] = '\0';
  3739. reservationIdInt = atoi(sstr);
  3740. memset(comfirmstr, 0, sizeof comfirmstr);
  3741. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3742. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3743. //check Transaction active
  3744. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3745. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3748. {
  3749. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3750. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3751. if(gunType[2] == 'J')
  3752. {
  3753. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3754. }
  3755. else
  3756. {
  3757. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3758. }
  3759. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3760. goto end;
  3761. }
  3762. }
  3763. for (int index = 0; index < CCS_QUANTITY; index++)
  3764. {
  3765. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3766. {
  3767. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3768. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3769. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3770. {
  3771. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3772. }
  3773. else
  3774. {
  3775. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3776. }
  3777. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3778. goto end;
  3779. }
  3780. }
  3781. for (int index = 0; index < GB_QUANTITY; index++)
  3782. {
  3783. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3784. {
  3785. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3786. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3787. if(gunType[2] == 'G')
  3788. {
  3789. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3790. }
  3791. else
  3792. {
  3793. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3794. }
  3795. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3796. goto end;
  3797. }
  3798. }
  3799. for (int index = 0; index < AC_QUANTITY; index++)
  3800. {
  3801. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3802. {
  3803. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3804. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3805. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3806. {
  3807. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3808. }
  3809. else
  3810. {
  3811. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3812. }
  3813. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3814. goto end;
  3815. }
  3816. }
  3817. //The reservationId does NOT match the reservationId
  3818. sendCancelReservationConfirmation(uuid, comfirmstr);
  3819. end:
  3820. // Fill in ocpp packet uuid
  3821. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3822. return result;
  3823. }
  3824. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3825. {
  3826. mtrace();
  3827. int result = FAIL;
  3828. int gunIndex = 0;
  3829. char sstr[90]={0},sstrtemp[50]={ 0 };
  3830. char typeStr[16]={0};
  3831. char comfirmstr[20];
  3832. int specificId = FALSE;
  3833. char *loc;
  3834. //int intervalInt = 0;
  3835. int c = 0;
  3836. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3837. strcpy(sstrtemp, stringtrimspace(payload));
  3838. /*** connectorId ****/
  3839. loc = strstr(sstrtemp, "connectorId");
  3840. memset(sstr ,0, sizeof(sstr) );
  3841. c = 0;
  3842. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3843. {
  3844. sstr[c] = loc[strlen("connectorId")+2+c];
  3845. c++;
  3846. }
  3847. sstr[c] = '\0';
  3848. gunIndex = atoi(sstr);
  3849. /***type ****/
  3850. loc = strstr(sstrtemp, "type");
  3851. memset(sstr ,0, sizeof(sstr) );
  3852. c = 0;
  3853. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3854. {
  3855. sstr[c] = loc[3+strlen("type")+c];
  3856. c++;
  3857. }
  3858. sstr[c] = '\0';
  3859. strcpy(typeStr, sstr);
  3860. if(gunIndex != 0)
  3861. {
  3862. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3863. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3864. }
  3865. else
  3866. {
  3867. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3868. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3869. }
  3870. memset(comfirmstr, 0, sizeof comfirmstr);
  3871. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3872. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3873. {
  3874. specificId = TRUE;
  3875. }
  3876. if(specificId == FALSE)
  3877. goto end;
  3878. if(gunIndex != 0)
  3879. {
  3880. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  3881. }
  3882. else
  3883. {
  3884. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  3885. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  3886. }
  3887. /*
  3888. enum SYSTEM_STATUS
  3889. {
  3890. SYS_MODE_BOOTING = 0,
  3891. SYS_MODE_IDLE = 1,
  3892. SYS_MODE_AUTHORIZING = 2,
  3893. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  3894. SYS_MODE_REASSIGN = 4,
  3895. SYS_MODE_PREPARING = 5,
  3896. SYS_MODE_PREPARE_FOR_EV = 6,
  3897. SYS_MODE_PREPARE_FOR_EVSE = 7,
  3898. SYS_MODE_CHARGING = 8,
  3899. SYS_MODE_TERMINATING = 9,
  3900. SYS_MODE_COMPLETE = 10,
  3901. SYS_MODE_ALARM = 11,
  3902. SYS_MODE_FAULT = 12,
  3903. SYS_MODE_RESERVATION = 13,
  3904. SYS_MODE_BOOKING = 14,
  3905. SYS_MODE_MAINTAIN = 15,
  3906. SYS_MODE_DEBUG = 16,
  3907. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  3908. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  3909. SYS_MODE_UPDATE = 19
  3910. };
  3911. */
  3912. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  3913. {
  3914. //check Transaction active
  3915. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3916. {
  3917. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  3918. {
  3919. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3920. {
  3921. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3922. }
  3923. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3924. {
  3925. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3926. }
  3927. else
  3928. {
  3929. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3930. }
  3931. goto end;
  3932. }
  3933. }//END FOR CHAdeMO_QUANTITY
  3934. for (int index = 0; index < CCS_QUANTITY; index++)
  3935. {
  3936. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  3937. {
  3938. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  3939. {
  3940. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3941. }
  3942. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3943. {
  3944. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3945. }
  3946. else
  3947. {
  3948. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3949. }
  3950. goto end;
  3951. }
  3952. }//END FOR CCS_QUANTITY
  3953. for (int index = 0; index < GB_QUANTITY; index++)
  3954. {
  3955. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  3956. {
  3957. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3958. {
  3959. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3960. }
  3961. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3962. {
  3963. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3964. }
  3965. else
  3966. {
  3967. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3968. }
  3969. goto end;
  3970. }
  3971. }// END FOR GB_QUANTITY
  3972. for (int index = 0; index < AC_QUANTITY; index++)
  3973. {
  3974. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  3975. {
  3976. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  3977. {
  3978. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3979. }
  3980. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  3981. {
  3982. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  3983. }
  3984. else
  3985. {
  3986. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  3987. }
  3988. goto end;
  3989. }
  3990. }//END FOR AC_QUANTITY
  3991. }//END FOR AvailabilityTypeStr[Inoperative]
  3992. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  3993. {
  3994. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3995. //check Transaction active
  3996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3997. {
  3998. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  3999. {
  4000. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4001. goto end;
  4002. }
  4003. }//END FOR CHAdeMO_QUANTITY
  4004. for (int index = 0; index < CCS_QUANTITY; index++)
  4005. {
  4006. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4007. {
  4008. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4009. goto end;
  4010. }
  4011. }//END FOR CCS_QUANTITY
  4012. for (int index = 0; index < GB_QUANTITY; index++)
  4013. {
  4014. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4015. {
  4016. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4017. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4018. goto end;
  4019. }
  4020. }// END FOR GB_QUANTITY
  4021. for (int index = 0; index < AC_QUANTITY; index++)
  4022. {
  4023. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4024. {
  4025. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4026. goto end;
  4027. }
  4028. }//END FOR CHAdeMO_QUANTITY
  4029. }//END FOR AvailabilityTypeStr[Operative]
  4030. end:
  4031. if(gunIndex != 0)
  4032. {
  4033. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4034. }
  4035. else
  4036. {
  4037. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4038. }
  4039. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4040. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4041. return result;
  4042. }
  4043. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4044. {
  4045. mtrace();
  4046. int result = FAIL;
  4047. char sstr[100]={0},sstrtemp[160]={ 0 };
  4048. char keystr[40]={0};
  4049. char valuestr[100]={0};
  4050. char *loc;
  4051. int c = 0;
  4052. char comfirmstr[20]={0};
  4053. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4054. strcpy(sstrtemp, stringtrimspace(payload));
  4055. /***key ****/
  4056. loc = strstr(sstrtemp, "key");
  4057. memset(sstr ,0, sizeof(sstr) );
  4058. c = 0;
  4059. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4060. {
  4061. sstr[c] = loc[3+strlen("key")+c];
  4062. c++;
  4063. }
  4064. sstr[c] = '\0';
  4065. strcpy(keystr, sstr);
  4066. //DEBUG_INFO( "keystr=%s\n",keystr);
  4067. /***value ****/
  4068. loc = strstr(sstrtemp, "value");
  4069. memset(sstr ,0, sizeof(sstr) );
  4070. c = 0;
  4071. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4072. {
  4073. sstr[c] = loc[3+strlen("value")+c];
  4074. c++;
  4075. }
  4076. sstr[c] = '\0';
  4077. strcpy(valuestr, sstr);
  4078. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4079. if((uuid==NULL) || (payload ==NULL) )
  4080. {
  4081. #ifdef Debug
  4082. DEBUG_INFO("payload is null\n");
  4083. #endif
  4084. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4085. }
  4086. else
  4087. {
  4088. int status = setKeyValue(keystr, valuestr);
  4089. switch(status)
  4090. {
  4091. case ConfigurationStatus_Accepted:
  4092. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4093. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4094. StoreConfigurationTable();
  4095. break;
  4096. case ConfigurationStatus_Rejected:
  4097. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4098. break;
  4099. case RebootRequired:
  4100. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4101. StoreConfigurationTable();
  4102. break;
  4103. case NotSupported:
  4104. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4105. break;
  4106. default:
  4107. break;
  4108. }
  4109. }
  4110. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4111. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4112. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4113. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4114. {
  4115. ChageWebSocketPingInterval(atoi(valuestr));
  4116. }
  4117. return result;
  4118. }
  4119. int handleClearCacheRequest(char *uuid, char *payload)
  4120. {
  4121. mtrace();
  4122. int result = FAIL;
  4123. char comfirmstr[20];
  4124. int fd;
  4125. char rmFileCmd[100]={0};
  4126. struct stat stats;
  4127. DEBUG_INFO("handle ClearCacheRequest\n");
  4128. stat("/Storage/OCPP", &stats);
  4129. // Check for directory existence
  4130. if (S_ISDIR(stats.st_mode) == 1)
  4131. {
  4132. //DEBUG_ERROR("\n OCPP directory exist \n");
  4133. }
  4134. else
  4135. {
  4136. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4137. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4138. system(rmFileCmd);
  4139. }
  4140. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4141. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4142. {
  4143. DEBUG_INFO("AuthorizationCache file exist.\n");
  4144. }
  4145. else
  4146. {
  4147. DEBUG_INFO("AuthorizationCache file not exist\n");
  4148. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4149. if(log == NULL)
  4150. {
  4151. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4152. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4153. goto end;
  4154. }
  4155. else
  4156. {
  4157. fclose(log);
  4158. }
  4159. }
  4160. fd = open(AuthorizationCache_JSON,O_RDWR);
  4161. if(fd < 0)
  4162. {
  4163. DEBUG_INFO("open AuthorizationCache file failed\n");
  4164. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4165. }
  4166. else
  4167. {
  4168. DEBUG_INFO("open AuthorizationCache file successful\n");
  4169. //* 清空? 件 */
  4170. ftruncate(fd,0);
  4171. //* ? 新设置? 件? 移??*/
  4172. lseek(fd,0,SEEK_SET);
  4173. close(fd);
  4174. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4175. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4176. }
  4177. end:
  4178. sendClearCacheConfirmation(uuid, comfirmstr);
  4179. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4180. return result;
  4181. }
  4182. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4183. {
  4184. mtrace();
  4185. int result = FAIL;
  4186. int resultRename;
  4187. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4188. char chargingProfilePurposeStr[26]={0};
  4189. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4190. char tempchargingProfilePurposeStr[26]={0};
  4191. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4192. char str[100]={0};
  4193. int c = 0;
  4194. //int i = 0;
  4195. //char * pch;
  4196. char *loc;
  4197. char fname[200]={0};
  4198. char comfirmstr[20]={0};
  4199. char word[1600]={0};
  4200. int clearflag = FALSE;
  4201. int chargingProfileIdIsNULL = FALSE;
  4202. int connectorIsNULL = FALSE;
  4203. int chargingProfilePurposeIsNULL = FALSE;
  4204. int stackLevelIsNULL = FALSE;
  4205. //int GotoEnd = FALSE;
  4206. FILE *fptr1, *fptr2;
  4207. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4208. int n_chargingProfile=0;
  4209. int isEmptyFile = FALSE;
  4210. char sLineWord[1600]={0};
  4211. char chargingProfiles[10][100]={0};
  4212. int ChargeProfileCount = 0;
  4213. char ch;
  4214. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4215. strcpy(sstrtemp, stringtrimspace(payload));
  4216. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4217. //***id ****/
  4218. c = 0;
  4219. loc = strstr(sstrtemp, "id");
  4220. memset(sstr ,0, sizeof(sstr) );
  4221. if(loc == NULL)
  4222. {
  4223. chargingProfileIdIsNULL = TRUE;
  4224. }
  4225. else
  4226. {
  4227. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4228. {
  4229. sstr[c] = loc[strlen("id")+2+c];
  4230. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4231. c++;
  4232. }
  4233. sstr[c] = '\0';
  4234. chargingProfileIdInt = atoi(sstr);
  4235. }
  4236. //***connectorId ****/
  4237. c=0;
  4238. loc = strstr(sstrtemp, "connectorId");
  4239. memset(sstr ,0, sizeof(sstr) );
  4240. if(loc == NULL)
  4241. {
  4242. connectorIsNULL = TRUE;
  4243. }
  4244. else
  4245. {
  4246. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4247. {
  4248. sstr[c] = loc[strlen("connectorId")+2+c];
  4249. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4250. c++;
  4251. }
  4252. sstr[c] = '\0';
  4253. connectorIdInt = atoi(sstr);
  4254. }
  4255. //***chargingProfilePurpose ****/
  4256. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4257. memset(sstr ,0, sizeof(sstr) );
  4258. c = 0;
  4259. if(loc == NULL)
  4260. {
  4261. chargingProfilePurposeIsNULL = TRUE;
  4262. }
  4263. else
  4264. {
  4265. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4266. {
  4267. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4268. c++;
  4269. }
  4270. sstr[c] = '\0';
  4271. strcpy(chargingProfilePurposeStr, sstr);
  4272. }
  4273. //***stackLevel ****/
  4274. c=0;
  4275. loc = strstr(sstrtemp, "stackLevel");
  4276. memset(sstr ,0, sizeof(sstr) );
  4277. if(loc == NULL)
  4278. {
  4279. stackLevelIsNULL = TRUE;
  4280. }
  4281. else
  4282. {
  4283. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4284. {
  4285. sstr[c] = loc[strlen("stackLevel")+2+c];
  4286. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4287. c++;
  4288. }
  4289. sstr[c] = '\0';
  4290. stackLevelInt = atoi(sstr);
  4291. }
  4292. if(connectorIsNULL == FALSE)
  4293. {
  4294. switch(connectorIdInt)
  4295. {
  4296. case 0:
  4297. if(chargingProfilePurposeIsNULL == TRUE)
  4298. {
  4299. int l = 0;
  4300. strcpy(fname, ChargePointMaxProfile_JSON);
  4301. if((access(fname,F_OK))!=-1)
  4302. {
  4303. strcpy(chargingProfiles[l], fname);
  4304. l = l + 1;
  4305. }
  4306. strcpy(fname, TxDefaultProfile_0_JSON);
  4307. if((access(fname,F_OK))!=-1)
  4308. {
  4309. strcpy(chargingProfiles[l], fname);
  4310. l = l + 1;
  4311. }
  4312. ChargeProfileCount = l;
  4313. }
  4314. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4315. {
  4316. strcpy(fname, ChargePointMaxProfile_JSON);
  4317. if((access(fname,F_OK))!=-1)
  4318. {
  4319. strcpy(chargingProfiles[0], fname);
  4320. ChargeProfileCount = 1;
  4321. }
  4322. }
  4323. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4324. {
  4325. strcpy(fname, TxDefaultProfile_0_JSON);
  4326. if((access(fname,F_OK))!=-1)
  4327. {
  4328. strcpy(chargingProfiles[0], fname);
  4329. ChargeProfileCount = 1;
  4330. }
  4331. }
  4332. break;
  4333. default:
  4334. if(chargingProfilePurposeIsNULL == TRUE)
  4335. {
  4336. int m = 0;
  4337. memset(fname, 0, sizeof fname);
  4338. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4339. if((access(fname,F_OK))!=-1)
  4340. {
  4341. strcpy(chargingProfiles[m], fname);
  4342. m = m + 1;
  4343. }
  4344. memset(fname, 0, sizeof fname);
  4345. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4346. if((access(fname,F_OK))!=-1)
  4347. {
  4348. strcpy(chargingProfiles[m], fname);
  4349. m = m + 1;
  4350. }
  4351. ChargeProfileCount = m;
  4352. }
  4353. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4354. {
  4355. //strcpy(fname, TxDefaultProfile_1_JSON);
  4356. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4357. if((access(fname,F_OK))!=-1)
  4358. {
  4359. strcpy(chargingProfiles[0], fname);
  4360. ChargeProfileCount = 1;
  4361. }
  4362. }
  4363. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4364. {
  4365. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4366. if((access(fname,F_OK))!=-1)
  4367. {
  4368. strcpy(chargingProfiles[0], fname);
  4369. ChargeProfileCount = 1;
  4370. }
  4371. //strcpy(fname, TxProfile_1_JSON);
  4372. }
  4373. //strcpy(fname, ChargePointMaxProfile_JSON );
  4374. break;
  4375. }
  4376. }
  4377. else // Check all Charging Profiles
  4378. {
  4379. int i = 0;
  4380. char fnametemp[200]={0};
  4381. ChargeProfileCount = 0;
  4382. //Check ChargePointMaxProfile.json exit
  4383. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4384. {
  4385. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4386. i = i + 1;
  4387. }
  4388. //Check TxDefaultProfile_0.json exit
  4389. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4390. {
  4391. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4392. i = i + 1;
  4393. }
  4394. //Check TxDefaultProfile_%d.json
  4395. for(int j=1; j <= gunTotalNumber; j++)
  4396. {
  4397. memset(fnametemp, 0, sizeof fnametemp);
  4398. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4399. if((access(fnametemp,F_OK))!=-1)
  4400. {
  4401. strcpy(chargingProfiles[i], fnametemp);
  4402. i = i + 1;
  4403. }
  4404. }
  4405. //Check TxProfile_%d.json
  4406. for(int j=1; j <= gunTotalNumber; j++)
  4407. {
  4408. memset(fnametemp, 0, sizeof fnametemp);
  4409. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4410. if((access(fnametemp,F_OK))!=-1)
  4411. {
  4412. strcpy(chargingProfiles[i], fnametemp);
  4413. i = i + 1;
  4414. }
  4415. }
  4416. ChargeProfileCount = i;
  4417. }// End connectorIsNULL is TRUE
  4418. if(ChargeProfileCount == 0)
  4419. {
  4420. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4421. goto end;
  4422. }
  4423. #if 0
  4424. fptr1 = fopen(fname, "r");
  4425. if (!fptr1)
  4426. {
  4427. //file not exist
  4428. DEBUG_INFO("Unable to open the input file!!\n");
  4429. fptr1 = fopen(fname, "w+");
  4430. }
  4431. fclose(fptr1);
  4432. #endif
  4433. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4434. {
  4435. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4436. goto end;
  4437. }
  4438. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4439. {
  4440. memset(str, 0, sizeof str);
  4441. // clear temp file
  4442. sprintf(str,"rm -f %s",temp);
  4443. system(str);
  4444. for(int k=0; k < ChargeProfileCount; k++)
  4445. {
  4446. memset(str, 0, sizeof str);
  4447. //clear file in C
  4448. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4449. system(str);
  4450. }
  4451. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4452. goto end;
  4453. }
  4454. else if(connectorIsNULL == TRUE)
  4455. {
  4456. for(int k=0; k < ChargeProfileCount; k++)
  4457. {
  4458. fptr1 = fopen(chargingProfiles[k], "r");
  4459. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4460. //Check Charging Profile Count
  4461. while(fscanf(fptr1, "%s", word) != EOF)
  4462. {
  4463. //DEBUG_INFO("word=%s\n",word);
  4464. if(strstr(word, "chargingProfileId")!= NULL)
  4465. {
  4466. //DEBUG_INFO("test chargingProfileId \n");
  4467. n_chargingProfile = n_chargingProfile + 1;
  4468. //DEBUG_INFO("chargingProfileId Found\n");
  4469. }
  4470. }
  4471. rewind(fptr1);
  4472. //search Charging Profile Element
  4473. //int i= 0;
  4474. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4475. {
  4476. //------------------------tempconnectorIdInt------------------------//
  4477. loc = strstr(sLineWord, "connectorId");
  4478. c = 0;
  4479. memset(sstr ,0, sizeof(sstr) );
  4480. while (loc[strlen("connectorId")+2+c] != ',')
  4481. {
  4482. sstr[c] = loc[strlen("connectorId")+2+c];
  4483. c++;
  4484. }
  4485. sstr[c] = '\0';
  4486. tempconnectorIdInt = atoi(sstr);
  4487. printf("file's gun number is %d\n", tempconnectorIdInt);
  4488. //--------------------------chargingProfileId--------------------//
  4489. c = 0;
  4490. loc = strstr(sLineWord, "chargingProfileId");
  4491. memset(sstr ,0, sizeof(sstr) );
  4492. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4493. {
  4494. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4495. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4496. c++;
  4497. }
  4498. sstr[c] = '\0';
  4499. tempchargingProfileIdInt = atoi(sstr);
  4500. //stackLevel
  4501. c = 0;
  4502. loc = strstr(sLineWord, "stackLevel");
  4503. memset(sstr ,0, sizeof(sstr) );
  4504. while (loc[strlen("stackLevel")+2+c] != ',')
  4505. {
  4506. sstr[c] = loc[strlen("stackLevel")+2+c];
  4507. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4508. c++;
  4509. }
  4510. sstr[c] = '\0';
  4511. tempstackLevelInt = atoi(sstr);
  4512. c = 0;
  4513. loc = strstr(sLineWord, "chargingProfilePurpose");
  4514. memset(sstr ,0, sizeof(sstr) );
  4515. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4516. {
  4517. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4518. c++;
  4519. }
  4520. sstr[c] = '\0';
  4521. strcpy(tempchargingProfilePurposeStr, sstr);
  4522. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4523. {
  4524. //------- not write to fptr2-------//
  4525. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4526. //clearflag = TRUE;
  4527. }
  4528. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4529. {
  4530. //------- not write to fptr2-------//
  4531. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4532. }
  4533. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4534. {
  4535. //------- not write to fptr2-------//
  4536. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4537. }
  4538. else
  4539. {
  4540. fprintf(fptr2, sLineWord);//writing data into file
  4541. }
  4542. memset(sLineWord, 0, sizeof sLineWord);
  4543. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4544. if(clearflag == TRUE)
  4545. {
  4546. fclose(fptr1);
  4547. fclose(fptr2);
  4548. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4549. system(str);
  4550. // clear temp file
  4551. sprintf(str,"rm -f %s",temp);
  4552. system(str);
  4553. }
  4554. else
  4555. {
  4556. fclose(fptr1);
  4557. fclose(fptr2);
  4558. memset(str, 0, sizeof str);
  4559. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4560. system(str);
  4561. resultRename = rename(temp, chargingProfiles[k]);
  4562. if(resultRename == 0)
  4563. {
  4564. DEBUG_INFO("File ChargingProfile renamed successfully");
  4565. }
  4566. else
  4567. {
  4568. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4569. }
  4570. if(comfirmstr[0]== 0)
  4571. {
  4572. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4573. }
  4574. //Check chargingProfile is empty file
  4575. /*------ Read the file ----------------*/
  4576. fptr1=fopen(chargingProfiles[k],"r");
  4577. ch=fgetc(fptr1);
  4578. rewind(fptr1);
  4579. memset(sLineWord, 0, sizeof sLineWord);
  4580. if(ch!=EOF)
  4581. {
  4582. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4583. {
  4584. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4585. if(sLineWord[0]=='\0')
  4586. {
  4587. isEmptyFile = TRUE;
  4588. break;
  4589. }
  4590. else
  4591. {
  4592. isEmptyFile = FALSE;
  4593. break;
  4594. }
  4595. }
  4596. }
  4597. fclose(fptr1);
  4598. if(isEmptyFile == TRUE)
  4599. {
  4600. memset(str, 0, sizeof str);
  4601. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4602. system(str);
  4603. }
  4604. }
  4605. }// End of while(int k=0; k < ChargePointCount; k++)
  4606. }
  4607. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4608. {
  4609. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4610. for(int k=0; k < ChargeProfileCount; k++)
  4611. {
  4612. fptr1 = fopen(chargingProfiles[k], "r");
  4613. fptr2 = fopen(temp, "w+");
  4614. //Check Charging Profile Count
  4615. while(fscanf(fptr1, "%s", word) != EOF)
  4616. {
  4617. //DEBUG_INFO("word=%s\n",word);
  4618. if(strstr(word, "chargingProfileId")!= NULL)
  4619. {
  4620. //DEBUG_INFO("test chargingProfileId \n");
  4621. n_chargingProfile = n_chargingProfile + 1;
  4622. //DEBUG_INFO("chargingProfileId Found\n");
  4623. }
  4624. }
  4625. rewind(fptr1);
  4626. //search Charging Profile Element
  4627. //int i= 0;
  4628. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4629. {
  4630. //*************************tempconnectorIdInt*********************************/
  4631. loc = strstr(sLineWord, "connectorId");
  4632. c = 0;
  4633. memset(sstr ,0, sizeof(sstr) );
  4634. while (loc[strlen("connectorId")+2+c] != ',')
  4635. {
  4636. sstr[c] = loc[strlen("connectorId")+2+c];
  4637. c++;
  4638. }
  4639. sstr[c] = '\0';
  4640. tempconnectorIdInt = atoi(sstr);
  4641. //chargingProfileId
  4642. c = 0;
  4643. loc = strstr(sLineWord, "chargingProfileId");
  4644. memset(sstr ,0, sizeof(sstr) );
  4645. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4646. {
  4647. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4648. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4649. c++;
  4650. }
  4651. sstr[c] = '\0';
  4652. tempchargingProfileIdInt = atoi(sstr);
  4653. //stackLevel
  4654. c = 0;
  4655. loc = strstr(sLineWord, "stackLevel");
  4656. memset(sstr ,0, sizeof(sstr) );
  4657. while (loc[strlen("stackLevel")+2+c] != ',')
  4658. {
  4659. sstr[c] = loc[strlen("stackLevel")+2+c];
  4660. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4661. c++;
  4662. }
  4663. sstr[c] = '\0';
  4664. tempstackLevelInt = atoi(sstr);
  4665. c = 0;
  4666. loc = strstr(sLineWord, "chargingProfilePurpose");
  4667. memset(sstr ,0, sizeof(sstr) );
  4668. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4669. {
  4670. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4671. c++;
  4672. }
  4673. sstr[c] = '\0';
  4674. strcpy(tempchargingProfilePurposeStr, sstr);
  4675. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4676. {
  4677. //------- not write to fptr2-------//
  4678. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4679. //clearflag = TRUE;
  4680. }
  4681. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4682. {
  4683. //------- not write to fptr2-------//
  4684. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4685. }
  4686. else if(stackLevelIsNULL == TRUE)
  4687. {
  4688. //Clear Whole File
  4689. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4690. clearflag = TRUE;
  4691. break;
  4692. }
  4693. else
  4694. {
  4695. fprintf(fptr2, sLineWord);//writing data into file
  4696. }
  4697. memset(sLineWord, 0, sizeof sLineWord);
  4698. }
  4699. if(clearflag == TRUE)
  4700. {
  4701. fclose(fptr1);
  4702. fclose(fptr2);
  4703. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4704. system(str);
  4705. // clear temp file
  4706. sprintf(str,"rm -f %s",temp);
  4707. system(str);
  4708. }
  4709. else
  4710. {
  4711. fclose(fptr1);
  4712. fclose(fptr2);
  4713. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4714. system(str);
  4715. resultRename = rename(temp, chargingProfiles[k]);
  4716. if(resultRename == 0)
  4717. {
  4718. DEBUG_INFO("File ChargingProfile renamed successfully");
  4719. }
  4720. else
  4721. {
  4722. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4723. }
  4724. if(comfirmstr[0]== 0)
  4725. {
  4726. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4727. }
  4728. //Check chargingProfile is empty file
  4729. /*------ Read the file ----------------*/
  4730. fptr1=fopen(chargingProfiles[k],"r");
  4731. ch=fgetc(fptr1);
  4732. rewind(fptr1);
  4733. memset(sLineWord, 0, sizeof sLineWord);
  4734. if(ch!=EOF)
  4735. {
  4736. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4737. {
  4738. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4739. if(sLineWord[0]=='\0')
  4740. {
  4741. isEmptyFile = TRUE;
  4742. break;
  4743. }
  4744. else
  4745. {
  4746. isEmptyFile = FALSE;
  4747. break;
  4748. }
  4749. }
  4750. }
  4751. fclose(fptr1);
  4752. if(isEmptyFile == TRUE)
  4753. {
  4754. memset(str, 0, sizeof str);
  4755. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4756. system(str);
  4757. }
  4758. /*------- End of reading ---------------*/
  4759. }
  4760. } // while(int k=0; k < ChargeProfileCount; k++)
  4761. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4762. end:
  4763. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4764. return result;
  4765. }
  4766. int handleDataTransferRequest(char *uuid, char *payload)
  4767. {
  4768. mtrace();
  4769. int result = FAIL;
  4770. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4771. char tempvendorId[255]={0};
  4772. char tempmessageId[50]={0};
  4773. char tempdata[50]={0};
  4774. char sstr[160]={0};//sstr[200]={ 0 };
  4775. char message[80]={0};
  4776. int c = 0;
  4777. char *loc;
  4778. DEBUG_INFO("handle DataTransferRequest\n");
  4779. if((uuid != NULL) && (payload != NULL))
  4780. {
  4781. //===============================
  4782. // vendorId
  4783. //===============================
  4784. c = 0;
  4785. loc = strstr(payload, "vendorId");
  4786. while (loc[strlen("vendorId")+3+c] != '\"')
  4787. {
  4788. sstr[c] = loc[strlen("vendorId")+3+c];
  4789. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4790. c++;
  4791. }
  4792. sstr[c] = '\0';
  4793. strcpy(tempvendorId,sstr);
  4794. //===============================
  4795. // messageId
  4796. //===============================
  4797. memset(sstr ,0, sizeof(sstr) );
  4798. c = 0;
  4799. loc = strstr(payload, "messageId");
  4800. while (loc[strlen("messageId")+3+c] != '\"')
  4801. {
  4802. sstr[c] = loc[strlen("messageId")+3+c];
  4803. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4804. c++;
  4805. }
  4806. sstr[c] = '\0';
  4807. strcpy(tempmessageId,sstr);
  4808. //===============================
  4809. // data
  4810. //===============================
  4811. memset(sstr ,0, sizeof(sstr) );
  4812. c = 0;
  4813. loc = strstr(payload, "data");
  4814. printf("loc=%s\n",loc);
  4815. while (loc[strlen("data")+3+c] != '\"')
  4816. {
  4817. sstr[c] = loc[strlen("data")+3+c];
  4818. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4819. c++;
  4820. }
  4821. sstr[c] = '\0';
  4822. strcpy(tempdata,sstr);
  4823. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4824. }
  4825. else
  4826. {
  4827. char guid[37]={0};
  4828. random_uuid(guid);
  4829. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4830. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4831. }
  4832. LWS_Send(message);
  4833. return result;
  4834. }
  4835. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4836. {
  4837. mtrace();
  4838. int result = FAIL;
  4839. int connectorIdInt, durationInt;
  4840. char chargingRateUnitStr[4]={0};
  4841. //int tempconnectorIdInt,
  4842. int tempdurationInt;
  4843. float tempminChargingRateFloat = 0.0;
  4844. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4845. int tempStartPeriodInt=0;
  4846. float tempLimitInt=0.0;//0.1;
  4847. int tempNumberPhasesInt=0;
  4848. char fname[200];
  4849. char comfirmstr[20];
  4850. //float totallimit =0.0;
  4851. float MinChargingRate =0.0;
  4852. //double diff_t;
  4853. //struct tm tp;
  4854. FILE *fptr1;
  4855. int c = 0;
  4856. //int i = 0;
  4857. char * pch;
  4858. char *loc;
  4859. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4860. int n_chargingProfile = 0;
  4861. int n_SchedulePeriods = 0;
  4862. char SchedulePeriodList[10][200]={0};
  4863. char sLineWord[1600]={0};
  4864. //int n_periods = 0;
  4865. char word[1000]={0};
  4866. int confirmPeriods = 0;
  4867. struct StructProfile ChargePointMaxProfile;
  4868. struct StructProfile TxDefaultProfile;
  4869. struct StructProfile TxProfile;
  4870. struct StructProfile TxDefaultProfiletemp[2]={0};
  4871. int TxDefaultProfileFileIsNull=FALSE;
  4872. int ChargePointMaxProfileIsNull=FALSE;
  4873. int TxProfileIsNull=FALSE;
  4874. int CompositeSceduleIndex = 0;
  4875. char ChargePointMaxProfileScheduleStr[30]={0};
  4876. char TxDefaultProfileScheduleStr[30]={0};
  4877. char TxProfileScheduleStr[30]={0};
  4878. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  4879. strcpy(sstrtemp, stringtrimspace(payload));
  4880. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  4881. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  4882. memset(&TxProfile,0,sizeof(struct StructProfile));
  4883. c=0;
  4884. loc = strstr(sstrtemp, "connectorId");
  4885. memset(sstr ,0, sizeof(sstr) );
  4886. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  4887. {
  4888. sstr[c] = loc[strlen("connectorId")+2+c];
  4889. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4890. c++;
  4891. }
  4892. sstr[c] = '\0';
  4893. connectorIdInt = atoi(sstr);
  4894. c=0;
  4895. loc = strstr(sstrtemp, "duration");
  4896. memset(sstr ,0, sizeof(sstr) );
  4897. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  4898. {
  4899. sstr[c] = loc[strlen("duration")+2+c];
  4900. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4901. c++;
  4902. }
  4903. sstr[c] = '\0';
  4904. durationInt = atoi(sstr);
  4905. c = 0;
  4906. loc = strstr(sstrtemp, "chargingRateUnit");
  4907. memset(sstr ,0, sizeof(sstr) );
  4908. if(loc == NULL)
  4909. {
  4910. }
  4911. else
  4912. {
  4913. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  4914. {
  4915. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  4916. c++;
  4917. }
  4918. sstr[c] = '\0';
  4919. strcpy(chargingRateUnitStr, sstr);
  4920. }
  4921. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  4922. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  4923. if(connectorIdInt==0) // connectorId is 0
  4924. {
  4925. //******************************ChargePointMaxProfile*****************************************************/
  4926. strcpy(fname, ChargePointMaxProfile_JSON );
  4927. char word[30]={0};
  4928. char sLineWord[1060]={0};
  4929. int n_chargingProfile=0;
  4930. ChargePointMaxProfileIsNull=TRUE;
  4931. if((access(fname,F_OK))!=-1)
  4932. {
  4933. fptr1 = fopen(fname, "r");
  4934. int c;
  4935. c = fgetc(fptr1);
  4936. //DEBUG_INFO("c:%d\n",c);
  4937. rewind(fptr1);
  4938. if(c == EOF)
  4939. {
  4940. DEBUG_INFO("\n End of file ChargingProfile reached.");
  4941. ChargePointMaxProfileIsNull=TRUE;
  4942. fclose(fptr1);
  4943. }
  4944. else
  4945. {
  4946. ChargePointMaxProfileIsNull=FALSE;
  4947. while(fscanf(fptr1, "%s", word) != EOF)
  4948. {
  4949. if(strcmp(word, "chargingProfileId") == 0)
  4950. {
  4951. n_chargingProfile = n_chargingProfile + 1;
  4952. printf("Found\n");
  4953. }
  4954. }
  4955. rewind(fptr1);
  4956. //search Charging Profile Element
  4957. int i= 0;
  4958. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  4959. #if 0
  4960. /***********connectorId****************/
  4961. c = 0;
  4962. loc = strstr(sLineWord, "connectorId");
  4963. // printf("loc=%s\n",loc);
  4964. memset(sstr ,0, sizeof(sstr) );
  4965. while (loc[strlen("connectorId")+2+c] != ',')
  4966. {
  4967. sstr[c] = loc[strlen("connectorId")+2+c];
  4968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4969. c++;
  4970. }
  4971. sstr[c] = '\0';
  4972. tempconnectorIdInt = atoi(sstr);
  4973. #endif
  4974. //***********validFrom**************/
  4975. c = 0;
  4976. loc = strstr(sLineWord, "validFrom");
  4977. //DEBUG_INFO("loc=%s\n",loc);
  4978. memset(sstr ,0, sizeof(sstr) );
  4979. if(loc != NULL)
  4980. {
  4981. while (loc[3+strlen("validFrom")+c] != '\"')
  4982. {
  4983. sstr[c] = loc[3+strlen("validFrom")+c];
  4984. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4985. c++;
  4986. }
  4987. sstr[c] = '\0';
  4988. DEBUG_INFO("validFrom=%s\n",sstr);
  4989. strcpy(tempvalidFromStr,sstr);
  4990. }
  4991. else
  4992. {
  4993. strcpy(tempvalidFromStr,"");
  4994. }
  4995. //**********startSchedule**********/
  4996. c = 0;
  4997. loc = strstr(sLineWord, "startSchedule");
  4998. //DEBUG_INFO("loc=%s\n",loc);
  4999. memset(sstr ,0, sizeof(sstr) );
  5000. if(loc != NULL)
  5001. {
  5002. while (loc[3+strlen("startSchedule")+c] != '\"')
  5003. {
  5004. sstr[c] = loc[3+strlen("startSchedule")+c];
  5005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5006. c++;
  5007. }
  5008. sstr[c] = '\0';
  5009. strcpy(tempstartScheduleStr, sstr);
  5010. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5011. }
  5012. else
  5013. {
  5014. strcpy(tempstartScheduleStr, "");
  5015. strcpy(ChargePointMaxProfileScheduleStr, "");
  5016. }
  5017. //**********chargingRateUnit**********/
  5018. c = 0;
  5019. loc = strstr(sLineWord, "chargingRateUnit");
  5020. memset(sstr ,0, sizeof(sstr) );
  5021. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5022. {
  5023. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5024. c++;
  5025. }
  5026. sstr[c] = '\0';
  5027. strcpy(tempchargingRateUnitStr, sstr);
  5028. //**********minChargingRate*******/
  5029. c = 0;
  5030. loc = strstr(sLineWord, "minChargingRate");
  5031. //printf("loc=%s\n",loc);
  5032. if(loc != NULL)
  5033. {
  5034. memset(sstr ,0, sizeof(sstr) );
  5035. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5036. {
  5037. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5039. c++;
  5040. }
  5041. sstr[c] = '\0';
  5042. tempminChargingRateFloat = atof(sstr);
  5043. }
  5044. else
  5045. {
  5046. tempminChargingRateFloat = 0.0;
  5047. }
  5048. //
  5049. #if 0
  5050. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5051. tp.tm_isdst = -1;
  5052. time_t utc = mktime(&tp);
  5053. // current time
  5054. time_t t = time(NULL);
  5055. #endif
  5056. //diff_t = difftime(t, utc);
  5057. //parsing strings to words
  5058. i = 0;
  5059. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5060. loc = loc+3+strlen("chargingSchedulePeriod");
  5061. pch = strtok(loc ,"{");
  5062. while (pch != NULL)
  5063. {
  5064. strcpy(SchedulePeriodList[i], pch);
  5065. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5066. //printf ("%s\n",pch);
  5067. pch = strtok (NULL, "{");
  5068. i = i + 1;
  5069. }
  5070. n_SchedulePeriods = i;
  5071. for(int i=0;i<n_SchedulePeriods;i++)
  5072. {
  5073. //*************startPeriod****************/
  5074. c = 0;
  5075. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5076. memset(sstr ,0, sizeof(sstr) );
  5077. while (loc[strlen("startPeriod")+2+c] != ',')
  5078. {
  5079. sstr[c] = loc[strlen("startPeriod")+2+c];
  5080. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5081. c++;
  5082. }
  5083. sstr[c] = '\0';
  5084. tempStartPeriodInt = atoi(sstr);
  5085. //*************limit****************/
  5086. c = 0;
  5087. loc = strstr(SchedulePeriodList[i], "limit");
  5088. memset(sstr ,0, sizeof(sstr) );
  5089. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5090. {
  5091. sstr[c] = loc[strlen("limit")+2+c];
  5092. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5093. c++;
  5094. }
  5095. sstr[c] = '\0';
  5096. tempLimitInt = atof(sstr);
  5097. //*************numberPhases****************/
  5098. c = 0;
  5099. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5100. memset(sstr ,0, sizeof(sstr) );
  5101. if(loc != NULL)
  5102. {
  5103. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5104. {
  5105. sstr[c] = loc[strlen("numberPhases")+2+c];
  5106. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5107. c++;
  5108. }
  5109. sstr[c] = '\0';
  5110. tempNumberPhasesInt = atoi(sstr);
  5111. }
  5112. else
  5113. {
  5114. tempNumberPhasesInt = 0;
  5115. }
  5116. ChargePointMaxProfile.Duration = durationInt;
  5117. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5118. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5119. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5120. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5121. }
  5122. if(MinChargingRate < tempminChargingRateFloat)
  5123. MinChargingRate = tempminChargingRateFloat;
  5124. }
  5125. }// End of file ChargingProfile
  5126. } //THE END OF ACCESS ChargePointMaxProfile
  5127. //******************************TxDefaultProfile***********************************************/
  5128. strcpy(fname, TxDefaultProfile_0_JSON);
  5129. memset(word, 0, 30);
  5130. memset(sLineWord, 0, 1060);
  5131. //char word[30]={0};
  5132. //char sLineWord[1060]={0};
  5133. n_chargingProfile=0;
  5134. TxDefaultProfileFileIsNull=TRUE;
  5135. if((access(fname,F_OK))!=-1)
  5136. {
  5137. fptr1 = fopen(fname, "r");
  5138. c = 0;
  5139. c = fgetc(fptr1);
  5140. //DEBUG_INFO("c:%d\n",c);
  5141. rewind(fptr1);
  5142. if(c == EOF)
  5143. {
  5144. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5145. TxDefaultProfileFileIsNull=TRUE;
  5146. fclose(fptr1);
  5147. }
  5148. else
  5149. {
  5150. TxDefaultProfileFileIsNull=FALSE;
  5151. while(fscanf(fptr1, "%s", word) != EOF)
  5152. {
  5153. if(strcmp(word, "chargingProfileId") == 0)
  5154. {
  5155. n_chargingProfile = n_chargingProfile + 1;
  5156. printf("Found\n");
  5157. }
  5158. }
  5159. rewind(fptr1);
  5160. //search Charging Profile Element
  5161. int i= 0;
  5162. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5163. #if 0
  5164. /***********connectorId****************/
  5165. c = 0;
  5166. loc = strstr(sLineWord, "connectorId");
  5167. // printf("loc=%s\n",loc);
  5168. memset(sstr ,0, sizeof(sstr) );
  5169. while (loc[strlen("connectorId")+2+c] != ',')
  5170. {
  5171. sstr[c] = loc[strlen("connectorId")+2+c];
  5172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5173. c++;
  5174. }
  5175. sstr[c] = '\0';
  5176. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5177. tempconnectorIdInt = atoi(sstr);
  5178. #endif
  5179. //***********validFrom**************/
  5180. c = 0;
  5181. loc = strstr(sLineWord, "validFrom");
  5182. //DEBUG_INFO("loc=%s\n",loc);
  5183. memset(sstr ,0, sizeof(sstr) );
  5184. if(loc != NULL)
  5185. {
  5186. while (loc[3+strlen("validFrom")+c] != '\"')
  5187. {
  5188. sstr[c] = loc[3+strlen("validFrom")+c];
  5189. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5190. c++;
  5191. }
  5192. sstr[c] = '\0';
  5193. DEBUG_INFO("validFrom=%s\n",sstr);
  5194. strcpy(tempvalidFromStr,sstr);
  5195. }
  5196. else
  5197. {
  5198. strcpy(tempvalidFromStr,"");
  5199. }
  5200. //**********startSchedule**********/
  5201. c = 0;
  5202. loc = strstr(sLineWord, "startSchedule");
  5203. //DEBUG_INFO("loc=%s\n",loc);
  5204. memset(sstr ,0, sizeof(sstr) );
  5205. if(loc != NULL)
  5206. {
  5207. while (loc[3+strlen("startSchedule")+c] != '\"')
  5208. {
  5209. sstr[c] = loc[3+strlen("startSchedule")+c];
  5210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5211. c++;
  5212. }
  5213. sstr[c] = '\0';
  5214. strcpy(tempstartScheduleStr, sstr);
  5215. strcpy(TxDefaultProfileScheduleStr, sstr);
  5216. }
  5217. else
  5218. {
  5219. strcpy(tempstartScheduleStr, "");
  5220. strcpy(TxDefaultProfileScheduleStr, "");
  5221. }
  5222. //**********chargingRateUnit**********/
  5223. c = 0;
  5224. loc = strstr(sLineWord, "chargingRateUnit");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5227. {
  5228. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5229. c++;
  5230. }
  5231. sstr[c] = '\0';
  5232. strcpy(tempchargingRateUnitStr, sstr);
  5233. //**********minChargingRate*******/
  5234. c = 0;
  5235. loc = strstr(sLineWord, "minChargingRate");
  5236. //printf("loc=%s\n",loc);
  5237. if(loc != NULL)
  5238. {
  5239. memset(sstr ,0, sizeof(sstr) );
  5240. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5241. {
  5242. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5243. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5244. c++;
  5245. }
  5246. sstr[c] = '\0';
  5247. tempminChargingRateFloat = atof(sstr);
  5248. }
  5249. else
  5250. {
  5251. tempminChargingRateFloat = 0.0;
  5252. }
  5253. #if 0
  5254. //
  5255. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5256. tp.tm_isdst = -1;
  5257. time_t utc = mktime(&tp);
  5258. // current time
  5259. time_t t = time(NULL);
  5260. //diff_t = difftime(t, utc);
  5261. #endif
  5262. //parsing strings to words
  5263. i = 0;
  5264. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5265. loc = loc+3+strlen("chargingSchedulePeriod");
  5266. pch = strtok(loc ,"{");
  5267. while (pch != NULL)
  5268. {
  5269. strcpy(SchedulePeriodList[i], pch);
  5270. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5271. //printf ("%s\n",pch);
  5272. pch = strtok (NULL, "{");
  5273. i = i + 1;
  5274. }
  5275. n_SchedulePeriods = i;
  5276. for(int i=0;i<n_SchedulePeriods;i++)
  5277. {
  5278. //*************startPeriod****************/
  5279. c = 0;
  5280. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5281. memset(sstr ,0, sizeof(sstr) );
  5282. while (loc[strlen("startPeriod")+2+c] != ',')
  5283. {
  5284. sstr[c] = loc[strlen("startPeriod")+2+c];
  5285. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5286. c++;
  5287. }
  5288. sstr[c] = '\0';
  5289. tempStartPeriodInt = atoi(sstr);
  5290. //*************limit****************/
  5291. c = 0;
  5292. loc = strstr(SchedulePeriodList[i], "limit");
  5293. memset(sstr ,0, sizeof(sstr) );
  5294. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5295. {
  5296. sstr[c] = loc[strlen("limit")+2+c];
  5297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5298. c++;
  5299. }
  5300. sstr[c] = '\0';
  5301. tempLimitInt = atof(sstr);
  5302. //*************numberPhases****************/
  5303. c = 0;
  5304. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5305. memset(sstr ,0, sizeof(sstr) );
  5306. if(loc != NULL)
  5307. {
  5308. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5309. {
  5310. sstr[c] = loc[strlen("numberPhases")+2+c];
  5311. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5312. c++;
  5313. }
  5314. sstr[c] = '\0';
  5315. tempNumberPhasesInt = atoi(sstr);
  5316. }
  5317. else
  5318. {
  5319. tempNumberPhasesInt = 0;
  5320. }
  5321. TxDefaultProfile.Duration = durationInt;
  5322. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5323. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5324. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5325. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5326. }
  5327. if(MinChargingRate < tempminChargingRateFloat)
  5328. MinChargingRate = tempminChargingRateFloat;
  5329. }
  5330. }
  5331. }// the end of ACCESS TxDefaultProfile
  5332. //--------------------- Composite Schedule-----------------------------//
  5333. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5334. {
  5335. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5336. struct tm tp;
  5337. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5338. tp.tm_isdst = -1;
  5339. time_t utc = mktime(&tp);
  5340. time_t t = time(NULL);
  5341. double diff_f = difftime(t, utc);
  5342. int diff_i; //= (int)diff_f;
  5343. int quotient; //= diff_i / 86400;//86400 seconds/day
  5344. int period = 0;
  5345. if(diff_f >= 0)
  5346. {
  5347. diff_i = (int)diff_f;
  5348. quotient = diff_i / 86400;
  5349. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5350. {
  5351. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5352. {
  5353. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5354. {
  5355. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5356. }
  5357. else
  5358. {
  5359. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5360. }
  5361. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5362. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5363. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5364. period = period + 1;
  5365. }
  5366. }
  5367. }
  5368. confirmPeriods = period;
  5369. }
  5370. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5371. {
  5372. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5373. struct tm tp;
  5374. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5375. tp.tm_isdst = -1;
  5376. time_t utc = mktime(&tp);
  5377. time_t t = time(NULL);
  5378. double diff_f = difftime(t, utc);
  5379. int diff_i; // = (int)diff_f;
  5380. int quotient; // = diff_i / 86400;//86400 seconds/day
  5381. int period = 0;
  5382. if(diff_f >= 0)
  5383. {
  5384. diff_i = (int)diff_f;
  5385. quotient = diff_i / 86400;//86400 seconds/day
  5386. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5387. {
  5388. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5389. {
  5390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5392. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5393. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5394. period = period + 1;
  5395. }
  5396. }
  5397. }
  5398. confirmPeriods = period;
  5399. }
  5400. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5401. {
  5402. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5403. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5404. {
  5405. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5406. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5407. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5408. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5409. }
  5410. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5411. }
  5412. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5413. {
  5414. confirmPeriods = 0;
  5415. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5416. //goto end;
  5417. }
  5418. //* Define temporary variables */
  5419. struct tm *gtime;
  5420. time_t now;
  5421. char buf[28];
  5422. /* Read the current system time */
  5423. time(&now);
  5424. /* Convert the system time to GMT (now UTC) */
  5425. gtime = gmtime(&now);
  5426. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5427. // make .conf
  5428. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5429. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5430. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5431. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5432. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5433. }
  5434. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5435. {
  5436. //*****************************ChargePointMaxProfile******************************************/
  5437. strcpy(fname, ChargePointMaxProfile_JSON);
  5438. ChargePointMaxProfileIsNull=TRUE;
  5439. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5440. {
  5441. fptr1 = fopen(fname, "r");
  5442. int c;
  5443. c = fgetc(fptr1);
  5444. //DEBUG_INFO("c:%d\n",c);
  5445. rewind(fptr1);
  5446. if(c == EOF)
  5447. {
  5448. DEBUG_INFO("\n End of file reached.");
  5449. ChargePointMaxProfileIsNull=TRUE;
  5450. fclose(fptr1);
  5451. }
  5452. else
  5453. {
  5454. ChargePointMaxProfileIsNull=FALSE;
  5455. while(fscanf(fptr1, "%s", word) != EOF)
  5456. {
  5457. if(strcmp(word, "chargingProfileId") == 0)
  5458. {
  5459. n_chargingProfile = n_chargingProfile + 1;
  5460. }
  5461. }
  5462. rewind(fptr1);
  5463. //search Charging Profile Element
  5464. int i = 0;
  5465. int j = 0;
  5466. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5467. #if 0
  5468. /***********connectorId****************/
  5469. c = 0;
  5470. loc = strstr(sLineWord, "connectorId");
  5471. memset(sstr ,0, sizeof(sstr) );
  5472. while (loc[strlen("connectorId")+2+c] != ',')
  5473. {
  5474. sstr[c] = loc[strlen("connectorId")+2+c];
  5475. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5476. c++;
  5477. }
  5478. sstr[c] = '\0';
  5479. tempconnectorIdInt = atoi(sstr);
  5480. #endif
  5481. //***********validFrom**************/
  5482. c = 0;
  5483. loc = strstr(sLineWord, "validFrom");
  5484. if(loc != NULL)
  5485. {
  5486. memset(sstr ,0, sizeof(sstr) );
  5487. while (loc[3+strlen("validFrom")+c] != '\"')
  5488. {
  5489. sstr[c] = loc[3+strlen("validFrom")+c];
  5490. c++;
  5491. }
  5492. sstr[c] = '\0';
  5493. strcpy(tempvalidFromStr,sstr);
  5494. }
  5495. else
  5496. {
  5497. strcpy(tempvalidFromStr,"");
  5498. }
  5499. //***********validFrom**************/
  5500. c = 0;
  5501. loc = strstr(sLineWord, "duration");
  5502. if(loc != NULL)
  5503. {
  5504. memset(sstr ,0, sizeof(sstr) );
  5505. while (loc[2+strlen("duration")+c] != ',')
  5506. {
  5507. sstr[c] = loc[2+strlen("duration")+c];
  5508. c++;
  5509. }
  5510. sstr[c] = '\0';
  5511. tempdurationInt = atoi(sstr);
  5512. }
  5513. else
  5514. {
  5515. tempdurationInt = 0;
  5516. }
  5517. //**********startSchedule**********/
  5518. c = 0;
  5519. loc = strstr(sLineWord, "startSchedule");
  5520. memset(sstr ,0, sizeof(sstr) );
  5521. if(loc != NULL)
  5522. {
  5523. while (loc[3+strlen("startSchedule")+c] != '\"')
  5524. {
  5525. sstr[c] = loc[3+strlen("startSchedule")+c];
  5526. c++;
  5527. }
  5528. sstr[c] = '\0';
  5529. strcpy(tempstartScheduleStr, sstr);
  5530. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5531. }
  5532. else
  5533. {
  5534. strcpy(tempstartScheduleStr, "");
  5535. strcpy(ChargePointMaxProfileScheduleStr, "");
  5536. }
  5537. //**********chargingRateUnit**********/
  5538. c = 0;
  5539. loc = strstr(sLineWord, "chargingRateUnit");
  5540. memset(sstr ,0, sizeof(sstr) );
  5541. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5542. {
  5543. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5544. c++;
  5545. }
  5546. sstr[c] = '\0';
  5547. strcpy(tempchargingRateUnitStr, sstr);
  5548. //**********minChargingRate*******/
  5549. c = 0;
  5550. loc = strstr(sLineWord, "minChargingRate");
  5551. if(loc != NULL)
  5552. {
  5553. memset(sstr ,0, sizeof(sstr) );
  5554. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5555. {
  5556. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5557. c++;
  5558. }
  5559. sstr[c] = '\0';
  5560. tempminChargingRateFloat = atof(sstr);
  5561. }
  5562. else
  5563. {
  5564. tempminChargingRateFloat = 0.0;
  5565. }
  5566. #if 0
  5567. //
  5568. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5569. tp.tm_isdst = -1;
  5570. time_t utc = mktime(&tp);
  5571. time_t t = time(NULL);
  5572. //diff_t = difftime(t, utc);
  5573. #endif
  5574. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5575. //DEBUG_INFO(" debug 5 -1\n");
  5576. //parsing strings to words
  5577. i = 0;
  5578. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5579. loc = loc+3+strlen("chargingSchedulePeriod");
  5580. pch = strtok(loc ,"{");
  5581. while (pch != NULL)
  5582. {
  5583. strcpy(SchedulePeriodList[i], pch);
  5584. pch = strtok (NULL, "{");
  5585. i = i + 1;
  5586. }
  5587. n_SchedulePeriods = i;
  5588. for(int i=0;i<n_SchedulePeriods;i++)
  5589. {
  5590. //*************startPeriod****************/
  5591. c = 0;
  5592. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5593. memset(sstr ,0, sizeof(sstr) );
  5594. while (loc[strlen("startPeriod")+2+c] != ',')
  5595. {
  5596. sstr[c] = loc[strlen("startPeriod")+2+c];
  5597. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5598. c++;
  5599. }
  5600. sstr[c] = '\0';
  5601. tempStartPeriodInt = atoi(sstr);
  5602. //*************limit****************/
  5603. c = 0;
  5604. loc = strstr(SchedulePeriodList[i], "limit");
  5605. memset(sstr ,0, sizeof(sstr) );
  5606. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5607. {
  5608. sstr[c] = loc[strlen("limit")+2+c];
  5609. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5610. c++;
  5611. }
  5612. sstr[c] = '\0';
  5613. tempLimitInt = atof(sstr);
  5614. //*************numberPhases****************/
  5615. c = 0;
  5616. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5617. memset(sstr ,0, sizeof(sstr) );
  5618. if(loc != NULL)
  5619. {
  5620. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5621. {
  5622. sstr[c] = loc[strlen("numberPhases")+2+c];
  5623. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5624. c++;
  5625. }
  5626. sstr[c] = '\0';
  5627. tempNumberPhasesInt = atoi(sstr);
  5628. }
  5629. else
  5630. {
  5631. tempNumberPhasesInt = 0;
  5632. }
  5633. if(j == 0)
  5634. {
  5635. ChargePointMaxProfile.Duration = tempdurationInt;
  5636. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5637. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5638. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5639. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5640. }
  5641. }
  5642. if(MinChargingRate < tempminChargingRateFloat)
  5643. {
  5644. MinChargingRate = tempminChargingRateFloat;
  5645. }
  5646. if(confirmPeriods < n_SchedulePeriods)
  5647. {
  5648. confirmPeriods = n_SchedulePeriods;
  5649. }
  5650. j = j + 1;
  5651. }
  5652. fclose(fptr1);
  5653. }
  5654. }// the end of access file ChargePointMaxProfile
  5655. //****************************TxDefaultProfile************************************************/
  5656. memset(fname, 0, sizeof fname);
  5657. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5658. TxDefaultProfileFileIsNull=TRUE;
  5659. if((access(fname,F_OK))!=-1)
  5660. {
  5661. fptr1 = fopen(fname, "r");
  5662. c = 0;
  5663. c = fgetc(fptr1);
  5664. //DEBUG_INFO("c:%d\n",c);
  5665. rewind(fptr1);
  5666. if(c == EOF)
  5667. {
  5668. DEBUG_INFO("\n End of file reached.");
  5669. TxDefaultProfileFileIsNull=TRUE;
  5670. fclose(fptr1);
  5671. }
  5672. else
  5673. {
  5674. TxDefaultProfileFileIsNull=FALSE;
  5675. while(fscanf(fptr1, "%s", word) != EOF)
  5676. {
  5677. if(strcmp(word, "chargingProfileId") == 0)
  5678. {
  5679. n_chargingProfile = n_chargingProfile + 1;
  5680. }
  5681. }
  5682. rewind(fptr1);
  5683. //search Charging Profile Element
  5684. int i = 0;
  5685. int j = 0;
  5686. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5687. //DEBUG_INFO(" 1-1\n");
  5688. #if 0
  5689. /***********connectorId****************/
  5690. c = 0;
  5691. loc = strstr(sLineWord, "connectorId");
  5692. memset(sstr ,0, sizeof(sstr) );
  5693. while (loc[strlen("connectorId")+2+c] != ',')
  5694. {
  5695. sstr[c] = loc[strlen("connectorId")+2+c];
  5696. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5697. c++;
  5698. }
  5699. sstr[c] = '\0';
  5700. tempconnectorIdInt = atoi(sstr);
  5701. #endif
  5702. //***********validFrom**************/
  5703. c = 0;
  5704. loc = strstr(sLineWord, "validFrom");
  5705. if(loc != NULL)
  5706. {
  5707. memset(sstr ,0, sizeof(sstr) );
  5708. while (loc[3+strlen("validFrom")+c] != '\"')
  5709. {
  5710. sstr[c] = loc[3+strlen("validFrom")+c];
  5711. c++;
  5712. }
  5713. sstr[c] = '\0';
  5714. strcpy(tempvalidFromStr,sstr);
  5715. }
  5716. else
  5717. {
  5718. strcpy(tempvalidFromStr,"");
  5719. }
  5720. //***********duration**************/
  5721. c = 0;
  5722. loc = strstr(sLineWord, "duration");
  5723. if(loc != NULL)
  5724. {
  5725. memset(sstr ,0, sizeof(sstr) );
  5726. while (loc[2+strlen("duration")+c] != ',')
  5727. {
  5728. sstr[c] = loc[2+strlen("duration")+c];
  5729. c++;
  5730. }
  5731. sstr[c] = '\0';
  5732. tempdurationInt = atoi(sstr);
  5733. }
  5734. else
  5735. {
  5736. tempdurationInt = 0;
  5737. }
  5738. //**********startSchedule**********/
  5739. c = 0;
  5740. loc = strstr(sLineWord, "startSchedule");
  5741. memset(sstr ,0, sizeof(sstr) );
  5742. if(loc != NULL)
  5743. {
  5744. while (loc[3+strlen("startSchedule")+c] != '\"')
  5745. {
  5746. sstr[c] = loc[3+strlen("startSchedule")+c];
  5747. c++;
  5748. }
  5749. sstr[c] = '\0';
  5750. strcpy(tempstartScheduleStr, sstr);
  5751. strcpy(TxDefaultProfileScheduleStr, sstr);
  5752. }
  5753. else
  5754. {
  5755. strcpy(tempstartScheduleStr, "");
  5756. strcpy(TxDefaultProfileScheduleStr, "");
  5757. }
  5758. //**********chargingRateUnit**********/
  5759. c = 0;
  5760. loc = strstr(sLineWord, "chargingRateUnit");
  5761. memset(sstr ,0, sizeof(sstr) );
  5762. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5763. {
  5764. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5765. c++;
  5766. }
  5767. sstr[c] = '\0';
  5768. strcpy(tempchargingRateUnitStr, sstr);
  5769. //**********minChargingRate*******/
  5770. c = 0;
  5771. loc = strstr(sLineWord, "minChargingRate");
  5772. if(loc != NULL)
  5773. {
  5774. memset(sstr ,0, sizeof(sstr) );
  5775. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5776. {
  5777. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5778. c++;
  5779. }
  5780. sstr[c] = '\0';
  5781. tempminChargingRateFloat = atof(sstr);
  5782. }
  5783. else
  5784. {
  5785. tempminChargingRateFloat = 0.0;
  5786. }
  5787. #if 0
  5788. //
  5789. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5790. tp.tm_isdst = -1;
  5791. time_t utc = mktime(&tp);
  5792. time_t t = time(NULL);
  5793. //diff_t = difftime(t, utc);
  5794. #endif
  5795. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5796. //parsing strings to words
  5797. i = 0;
  5798. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5799. loc = loc+3+strlen("chargingSchedulePeriod");
  5800. pch = strtok(loc ,"{");
  5801. while (pch != NULL)
  5802. {
  5803. strcpy(SchedulePeriodList[i], pch);
  5804. pch = strtok (NULL, "{");
  5805. i = i + 1;
  5806. }
  5807. n_SchedulePeriods = i;
  5808. for(int i=0;i<n_SchedulePeriods;i++)
  5809. {
  5810. //*************startPeriod****************/
  5811. c = 0;
  5812. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5813. memset(sstr ,0, sizeof(sstr) );
  5814. while (loc[strlen("startPeriod")+2+c] != ',')
  5815. {
  5816. sstr[c] = loc[strlen("startPeriod")+2+c];
  5817. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5818. c++;
  5819. }
  5820. sstr[c] = '\0';
  5821. tempStartPeriodInt = atoi(sstr);
  5822. //*************limit****************/
  5823. c = 0;
  5824. loc = strstr(SchedulePeriodList[i], "limit");
  5825. memset(sstr ,0, sizeof(sstr) );
  5826. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5827. {
  5828. sstr[c] = loc[strlen("limit")+2+c];
  5829. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5830. c++;
  5831. }
  5832. sstr[c] = '\0';
  5833. tempLimitInt = atof(sstr);
  5834. //*************numberPhases****************/
  5835. c = 0;
  5836. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5837. memset(sstr ,0, sizeof(sstr) );
  5838. if(loc != NULL)
  5839. {
  5840. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5841. {
  5842. sstr[c] = loc[strlen("numberPhases")+2+c];
  5843. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5844. c++;
  5845. }
  5846. sstr[c] = '\0';
  5847. tempNumberPhasesInt = atoi(sstr);
  5848. }
  5849. else
  5850. {
  5851. tempNumberPhasesInt = 0;
  5852. }
  5853. if(j == 0)
  5854. {
  5855. TxDefaultProfile.Duration = tempdurationInt;
  5856. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5857. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5858. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5859. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5860. }
  5861. else
  5862. {
  5863. //other stack level charging Profile
  5864. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5865. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5866. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5867. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5868. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5869. }
  5870. }
  5871. if(MinChargingRate < tempminChargingRateFloat)
  5872. MinChargingRate = tempminChargingRateFloat;
  5873. if(confirmPeriods < n_SchedulePeriods)
  5874. confirmPeriods = n_SchedulePeriods;
  5875. j = j + 1;
  5876. //DEBUG_INFO(" 1-2\n");
  5877. }
  5878. fclose(fptr1);
  5879. //Stacking Charging Profiles
  5880. for(int l=0; l <(j-1) ;l++)
  5881. {
  5882. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  5883. {
  5884. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  5885. {
  5886. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  5887. {
  5888. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  5889. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  5890. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  5891. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5892. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5893. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5894. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5895. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5896. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5897. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5898. }
  5899. else
  5900. {
  5901. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  5902. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  5903. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  5904. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  5905. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  5906. }
  5907. }
  5908. }
  5909. }
  5910. //end of Stacking Charging Profiles
  5911. }
  5912. }// the end of ACCESS TxDefaultProfile
  5913. //****************************TxProfile************************************************/
  5914. memset(fname, 0, sizeof fname);
  5915. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5916. TxProfileIsNull=TRUE;
  5917. if((access(fname,F_OK))!=-1)
  5918. {
  5919. fptr1 = fopen(fname, "r");
  5920. c = 0;
  5921. c = fgetc(fptr1);
  5922. //DEBUG_INFO("c:%d\n",c);
  5923. rewind(fptr1);
  5924. if(c == EOF)
  5925. {
  5926. DEBUG_INFO("\n End of file reached.");
  5927. TxProfileIsNull=TRUE;
  5928. fclose(fptr1);
  5929. }
  5930. else
  5931. {
  5932. TxProfileIsNull=FALSE;
  5933. while(fscanf(fptr1, "%s", word) != EOF)
  5934. {
  5935. if(strcmp(word, "chargingProfileId") == 0)
  5936. {
  5937. n_chargingProfile = n_chargingProfile + 1;
  5938. }
  5939. }
  5940. rewind(fptr1);
  5941. //search Charging Profile Element
  5942. int i= 0;
  5943. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5944. #if 0
  5945. /***********connectorId****************/
  5946. c = 0;
  5947. loc = strstr(sLineWord, "connectorId");
  5948. memset(sstr ,0, sizeof(sstr) );
  5949. while (loc[strlen("connectorId")+2+c] != ',')
  5950. {
  5951. sstr[c] = loc[strlen("connectorId")+2+c];
  5952. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5953. c++;
  5954. }
  5955. sstr[c] = '\0';
  5956. tempconnectorIdInt = atoi(sstr);
  5957. #endif
  5958. //***********validFrom**************/
  5959. c = 0;
  5960. loc = strstr(sLineWord, "validFrom");
  5961. if(loc != NULL)
  5962. {
  5963. memset(sstr ,0, sizeof(sstr) );
  5964. while (loc[3+strlen("validFrom")+c] != '\"')
  5965. {
  5966. sstr[c] = loc[3+strlen("validFrom")+c];
  5967. c++;
  5968. }
  5969. sstr[c] = '\0';
  5970. strcpy(tempvalidFromStr,sstr);
  5971. }
  5972. else
  5973. {
  5974. strcpy(tempvalidFromStr,"");
  5975. }
  5976. //**********startSchedule**********/
  5977. c = 0;
  5978. loc = strstr(sLineWord, "startSchedule");
  5979. memset(sstr ,0, sizeof(sstr) );
  5980. if(loc != NULL)
  5981. {
  5982. while (loc[3+strlen("startSchedule")+c] != '\"')
  5983. {
  5984. sstr[c] = loc[3+strlen("startSchedule")+c];
  5985. c++;
  5986. }
  5987. sstr[c] = '\0';
  5988. strcpy(tempstartScheduleStr, sstr);
  5989. strcpy(TxProfileScheduleStr, sstr);
  5990. }
  5991. else
  5992. {
  5993. strcpy(tempstartScheduleStr, "");
  5994. strcpy(TxProfileScheduleStr, "");
  5995. }
  5996. //**********chargingRateUnit**********/
  5997. c = 0;
  5998. loc = strstr(sLineWord, "chargingRateUnit");
  5999. memset(sstr ,0, sizeof(sstr) );
  6000. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6001. {
  6002. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6003. c++;
  6004. }
  6005. sstr[c] = '\0';
  6006. strcpy(tempchargingRateUnitStr, sstr);
  6007. //**********minChargingRate*******/
  6008. c = 0;
  6009. loc = strstr(sLineWord, "minChargingRate");
  6010. if(loc != NULL)
  6011. {
  6012. memset(sstr ,0, sizeof(sstr) );
  6013. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6014. {
  6015. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6016. c++;
  6017. }
  6018. sstr[c] = '\0';
  6019. tempminChargingRateFloat = atof(sstr);
  6020. }
  6021. else
  6022. {
  6023. tempminChargingRateFloat = 0.0;
  6024. }
  6025. #if 0
  6026. //
  6027. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6028. tp.tm_isdst = -1;
  6029. time_t utc = mktime(&tp);
  6030. time_t t = time(NULL);
  6031. //diff_t = difftime(t, utc);
  6032. #endif
  6033. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6034. //parsing strings to words
  6035. i = 0;
  6036. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6037. loc = loc+3+strlen("chargingSchedulePeriod");
  6038. pch = strtok(loc ,"{");
  6039. while (pch != NULL)
  6040. {
  6041. strcpy(SchedulePeriodList[i], pch);
  6042. pch = strtok (NULL, "{");
  6043. i = i + 1;
  6044. }
  6045. n_SchedulePeriods = i;
  6046. for(int i=0;i<n_SchedulePeriods;i++)
  6047. {
  6048. //*************startPeriod****************/
  6049. c = 0;
  6050. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6051. memset(sstr ,0, sizeof(sstr) );
  6052. while (loc[strlen("startPeriod")+2+c] != ',')
  6053. {
  6054. sstr[c] = loc[strlen("startPeriod")+2+c];
  6055. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6056. c++;
  6057. }
  6058. sstr[c] = '\0';
  6059. tempStartPeriodInt = atoi(sstr);
  6060. //*************limit****************/
  6061. c = 0;
  6062. loc = strstr(SchedulePeriodList[i], "limit");
  6063. memset(sstr ,0, sizeof(sstr) );
  6064. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6065. {
  6066. sstr[c] = loc[strlen("limit")+2+c];
  6067. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6068. c++;
  6069. }
  6070. sstr[c] = '\0';
  6071. tempLimitInt = atof(sstr);
  6072. //*************numberPhases****************/
  6073. c = 0;
  6074. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6075. memset(sstr ,0, sizeof(sstr) );
  6076. if(loc != NULL)
  6077. {
  6078. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6079. {
  6080. sstr[c] = loc[strlen("numberPhases")+2+c];
  6081. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6082. c++;
  6083. }
  6084. sstr[c] = '\0';
  6085. tempNumberPhasesInt = atoi(sstr);
  6086. }
  6087. else
  6088. {
  6089. tempNumberPhasesInt = 0;
  6090. }
  6091. TxProfile.Duration = durationInt;
  6092. TxProfile.TotalPeriod = n_SchedulePeriods;
  6093. TxProfile.Period[i].Limit = tempLimitInt;
  6094. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6095. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6096. }
  6097. if(MinChargingRate < tempminChargingRateFloat)
  6098. MinChargingRate = tempminChargingRateFloat;
  6099. if(confirmPeriods < n_SchedulePeriods)
  6100. confirmPeriods = n_SchedulePeriods;
  6101. }
  6102. fclose(fptr1);
  6103. }
  6104. }// the end of ACCESS TxProfile
  6105. //CompositeSchedule
  6106. int period=0;
  6107. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6108. {
  6109. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6110. struct tm tp;
  6111. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6112. tp.tm_isdst = -1;
  6113. time_t utc = mktime(&tp);
  6114. time_t t = time(NULL);
  6115. double diff_f = difftime(t, utc);
  6116. int diff_i; // = (int)diff_f;
  6117. int quotient; // = diff_i / 86400;//86400 seconds/day
  6118. //int remainder = diff_i % 86400;
  6119. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6120. {
  6121. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6122. {
  6123. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6124. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6125. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6126. period = period + 1;
  6127. }
  6128. else
  6129. {
  6130. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6131. {
  6132. }
  6133. else
  6134. {
  6135. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6136. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6137. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6138. period = period + 1;
  6139. }
  6140. }
  6141. }
  6142. if( diff_f >= 0)
  6143. {
  6144. diff_i = (int)diff_f;
  6145. quotient = diff_i / 86400;//86400 seconds/day
  6146. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6147. {
  6148. if(((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)&& ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod %86400) > ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  6149. {
  6150. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6151. {
  6152. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6153. }
  6154. else
  6155. {
  6156. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6157. }
  6158. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6159. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6160. period = period + 1;
  6161. }
  6162. }
  6163. // Check Last Period
  6164. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6165. {
  6166. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6167. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6168. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6169. period = period + 1;
  6170. }
  6171. } // diff_f >= 0
  6172. }
  6173. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6174. {
  6175. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6176. struct tm tp;
  6177. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6178. tp.tm_isdst = -1;
  6179. time_t utc = mktime(&tp);
  6180. time_t t = time(NULL);
  6181. double diff_f = difftime(t, utc);
  6182. int diff_i;// = (int)diff_f;
  6183. int quotient; // = diff_i / 86400;//86400 seconds/day
  6184. //int remainder = diff_i % 86400;
  6185. if(diff_f >= 0)
  6186. {
  6187. diff_i = (int)diff_f;
  6188. quotient = diff_i / 86400;//86400 seconds/day
  6189. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6190. {
  6191. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6192. {
  6193. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6194. {
  6195. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6196. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6197. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6198. period = period + 1;
  6199. }
  6200. else
  6201. {
  6202. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6203. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6204. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6205. period = period + 1;
  6206. }
  6207. }
  6208. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6209. {
  6210. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6211. {
  6212. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6213. {
  6214. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6215. {
  6216. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6217. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6218. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6219. period = period + 1;
  6220. }
  6221. else
  6222. {
  6223. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6224. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6225. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6226. period = period + 1;
  6227. }
  6228. }
  6229. }
  6230. }
  6231. }
  6232. } // end diff_f >= 0
  6233. }
  6234. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6235. {
  6236. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6237. struct tm tp;
  6238. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6239. tp.tm_isdst = -1;
  6240. time_t utc = mktime(&tp);
  6241. time_t t = time(NULL);
  6242. double diff_f = difftime(t, utc);
  6243. int diff_i; // = (int)diff_f;
  6244. int quotient; // = diff_i / 86400;//86400 seconds/day
  6245. //int remainder = diff_i % 86400;
  6246. if(diff_f >= 0)
  6247. {
  6248. diff_i = (int)diff_f;
  6249. quotient = diff_i / 86400;//86400 seconds/day
  6250. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6251. {
  6252. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6253. {
  6254. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6255. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6256. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6257. period = period + 1;
  6258. }
  6259. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6260. {
  6261. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6262. {
  6263. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6264. {
  6265. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6266. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6267. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6268. period = period + 1;
  6269. }
  6270. }
  6271. }
  6272. }
  6273. } // diff_f >= 0
  6274. }
  6275. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6276. {
  6277. confirmPeriods = 0;
  6278. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6279. //goto end;
  6280. }
  6281. confirmPeriods = period;
  6282. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6283. //---- Define StartSchedule----/
  6284. struct tm *gtime;
  6285. time_t now;
  6286. char buf[28];
  6287. //---Read the current system time---/
  6288. time(&now);
  6289. //---Convert the system time to GMT (now UTC)---/
  6290. gtime = gmtime(&now);
  6291. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6292. // make .conf
  6293. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6294. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6295. //DEBUG_INFO(" debug 11\n");
  6296. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6297. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6298. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6299. }
  6300. else
  6301. {
  6302. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6303. }
  6304. //end:
  6305. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6306. return result;
  6307. }
  6308. int handleGetConfigurationRequest(char *uuid, char *payload)
  6309. {
  6310. mtrace();
  6311. int result = FAIL;
  6312. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6313. //struct json_object *jsonitem;
  6314. int MaxKeySupported = 0;
  6315. int n_keys = 0;
  6316. char requestKey[43][50]={0};
  6317. char search[]="[";
  6318. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6319. //int pos;
  6320. int l, c = 0;
  6321. int i = 0;
  6322. char *delim = "\",\"";
  6323. char * pch;
  6324. strcpy(sstrtemp, stringtrimspace(payload));
  6325. char *loc = strstr(sstrtemp, search);
  6326. //********************* Parsing String ***********************************/
  6327. if(loc == NULL) {
  6328. DEBUG_INFO("no key match in Configuration \n");
  6329. }
  6330. else {
  6331. //pos = loc - payload;
  6332. l = strlen(loc)-4;
  6333. while (c < l)
  6334. {
  6335. sstr[c] = loc[c+2];
  6336. c++;
  6337. }
  6338. sstr[c] = '\0';
  6339. //parsing strings to words
  6340. pch = strtok(sstr,delim);
  6341. if(pch == NULL)
  6342. {
  6343. strcpy(requestKey[0], sstr);
  6344. }
  6345. else
  6346. {
  6347. while (pch != NULL)
  6348. {
  6349. strcpy(requestKey[i], pch);
  6350. pch = strtok (NULL, delim);
  6351. i = i + 1;
  6352. }
  6353. n_keys = i;
  6354. }
  6355. }
  6356. UnknownKeynum = 0;
  6357. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6358. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6359. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6360. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6361. if(n_keys != 0)
  6362. {
  6363. for(int i=0;i<n_keys;i++)
  6364. {
  6365. getKeyValue(requestKey[i]);
  6366. //json_object_put(jsonitem);
  6367. }
  6368. }
  6369. else
  6370. {
  6371. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6372. getKeyValue("");
  6373. }
  6374. processUnkownKey();
  6375. sendGetConfigurationConfirmation(uuid);
  6376. return result;
  6377. }
  6378. static char fnamePlusPath[100]={0};
  6379. static char fnamePWithNoPath[60]={0};
  6380. void checkUploadLog(void)
  6381. {
  6382. FILE *fp;
  6383. /* Open the command for reading. */
  6384. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6385. if (fp == NULL) {
  6386. printf("Failed to run command\n" );
  6387. exit(1);
  6388. }
  6389. int ftppathlen = 0;
  6390. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6391. int i = 0;
  6392. /* Read the output a line at a time - output it. */
  6393. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6394. if(i==0)
  6395. {
  6396. ftppathlen = strlen(fnamePlusPath);
  6397. printf("%s\n", fnamePlusPath);
  6398. fnamePlusPath[ftppathlen]='\0';
  6399. break;
  6400. }
  6401. i= i+1;
  6402. }
  6403. /* close */
  6404. pclose(fp);
  6405. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6406. {
  6407. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6408. {
  6409. fnamePlusPath[k]='\0';
  6410. }
  6411. }
  6412. i=1;
  6413. //char fname[60]={0};
  6414. while(i < ftppathlen)
  6415. {
  6416. int len=ftppathlen-i;
  6417. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6418. {
  6419. printf("compare '/' all right\n");
  6420. break;
  6421. }
  6422. i=i+1;
  6423. }
  6424. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6425. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6426. fnamePWithNoPath[i+1] = '\0';
  6427. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6428. {
  6429. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6430. {
  6431. fnamePWithNoPath[j]='\0';
  6432. }
  6433. }
  6434. FILE* fp1 = fopen(fnamePlusPath, "r");
  6435. if (fp1)
  6436. {
  6437. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6438. // file exists
  6439. fclose(fp1);
  6440. }
  6441. else
  6442. {
  6443. // file doesn't exist
  6444. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6445. }
  6446. }
  6447. static char GetDiagnosticspayloadData[300]={0};
  6448. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6449. {
  6450. mtrace();
  6451. int result = FAIL;
  6452. pthread_t t; // pthread 變數
  6453. system("exec /root/logPackTools 'log' 6");
  6454. #if 0
  6455. //char buffer [128];
  6456. time (&rawtime);
  6457. //printf("%ld\n", rawtime);
  6458. timeinfo = localtime (&rawtime);
  6459. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6460. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6461. if((access(fnamePlusPath,F_OK))!=-1)
  6462. {
  6463. DEBUG_INFO("fnamePlusPath exist.\n");
  6464. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6465. }
  6466. else
  6467. {
  6468. DEBUG_INFO("fnamePlusPath not exist!\n");
  6469. }
  6470. #endif
  6471. checkUploadLog();
  6472. memset(GetDiagnosticspayloadData, 0, 300);
  6473. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6474. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6475. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6476. return result;
  6477. }
  6478. void* GetDiagnosticsProcess(void* data)
  6479. {
  6480. pthread_detach(pthread_self());
  6481. mtrace();
  6482. int retriesInt=0, retryIntervalInt=0;
  6483. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6484. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6485. 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};
  6486. int port=0;
  6487. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6488. int c = 0;
  6489. char *loc;
  6490. int isSuccess = FALSE;
  6491. char ftpbuf[200]={0};
  6492. //char temp[100]={0};
  6493. char * pch;
  6494. // [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"}]
  6495. char str[300]={ 0 };
  6496. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6497. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6498. DEBUG_INFO("GetDiagnosticsProcess\n");
  6499. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6500. //****************location*******************/
  6501. c = 0;
  6502. memset(sstr ,0, sizeof(sstr) );
  6503. loc = strstr(str, "location");
  6504. while (loc[3+strlen("location")+c] != '\"')
  6505. {
  6506. sstr[c] = loc[3+strlen("location")+c];
  6507. c++;
  6508. }
  6509. sstr[c] = '\0';
  6510. strcpy(locationstr,sstr);
  6511. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6512. if(strcmp(locationstr,"")==0)
  6513. {
  6514. DEBUG_INFO("location is <Empty>!\n");
  6515. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6516. goto end;
  6517. }
  6518. //****************retries*******************/
  6519. c = 0;
  6520. loc = strstr(str, "retries");
  6521. if(loc == NULL)
  6522. {
  6523. retriesIsNULL = TRUE;
  6524. }
  6525. else
  6526. {
  6527. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6528. {
  6529. sstr[c] = loc[strlen("retries")+2+c];
  6530. c++;
  6531. }
  6532. sstr[c] = '\0';
  6533. retriesInt = atoi(sstr);
  6534. }
  6535. if(retriesIsNULL == TRUE)
  6536. {
  6537. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6538. }
  6539. //****************retryInterval*******************/
  6540. c = 0;
  6541. loc = strstr(str, "retryInterval");
  6542. if(loc == NULL)
  6543. {
  6544. retryIntervalIsNULL = TRUE;
  6545. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6546. }
  6547. else
  6548. {
  6549. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6550. {
  6551. sstr[c] = loc[strlen("retryInterval")+2+c];
  6552. c++;
  6553. }
  6554. sstr[c] = '\0';
  6555. retryIntervalInt = atoi(sstr);
  6556. }
  6557. //****************startTime*******************/
  6558. c = 0;
  6559. memset(sstr ,0, sizeof(sstr) );
  6560. loc = strstr(str, "startTime");
  6561. if(loc == NULL)
  6562. {
  6563. startTimeIsNULL = TRUE;
  6564. }
  6565. else
  6566. {
  6567. while (loc[3+strlen("startTime")+c] != '\"')
  6568. {
  6569. sstr[c] = loc[3+strlen("startTime")+c];
  6570. c++;
  6571. }
  6572. sstr[c] = '\0';
  6573. strcpy(startTimestr,sstr);
  6574. }
  6575. //****************stopTime*******************/
  6576. c = 0;
  6577. memset(sstr ,0, sizeof(sstr) );
  6578. loc = strstr(str, "stopTime");
  6579. if(loc == NULL)
  6580. {
  6581. stopTimeIsNULL = TRUE;
  6582. }
  6583. else
  6584. {
  6585. while (loc[3+strlen("stopTime")+c] != '\"')
  6586. {
  6587. sstr[c] = loc[3+strlen("stopTime")+c];
  6588. c++;
  6589. }
  6590. sstr[c] = '\0';
  6591. strcpy(stopTimestr,sstr);
  6592. }
  6593. memset(protocol, 0, sizeof(protocol));
  6594. memset(user, 0, sizeof(user) );
  6595. memset(password, 0, sizeof(password));
  6596. memset(host, 0, sizeof(host));
  6597. memset(path, 0, sizeof(path));
  6598. memset(ftppath, 0, sizeof(ftppath));
  6599. memset(host1, 0, sizeof(host1));
  6600. memset(path1, 0, sizeof(path1));
  6601. /*location: ftp://user:password@host:port/path*/
  6602. #if 0
  6603. time_t rawtime;
  6604. struct tm * timeinfo;
  6605. //char buffer [128];
  6606. time (&rawtime);
  6607. //printf("%ld\n", rawtime);
  6608. timeinfo = localtime (&rawtime);
  6609. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6610. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6611. #endif
  6612. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6613. if((access(fnamePlusPath,F_OK))!=-1)
  6614. {
  6615. DEBUG_INFO("fnamePlusPath exist.\n");
  6616. }
  6617. else
  6618. {
  6619. DEBUG_INFO("fnamePlusPath not exist!\n");
  6620. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6621. goto end;
  6622. }
  6623. pch=strchr(locationstr,'@');
  6624. if(pch==NULL)
  6625. {
  6626. sscanf(locationstr,
  6627. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6628. protocol, host, &port, path);
  6629. strcpy(user,"anonymous");
  6630. strcpy(password,"");
  6631. }
  6632. else
  6633. {
  6634. //DEBUG_INFO("pch=%s\n", pch);
  6635. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6636. protocol, user, password, host, &port, path);
  6637. }
  6638. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6639. {
  6640. DEBUG_INFO("protocol is not ftp/http ! \n");
  6641. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6642. goto end;
  6643. }
  6644. if(strncmp(locationstr,"http", 4) == 0)
  6645. {
  6646. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6647. sprintf(ftppath,"/%s", path);
  6648. do{
  6649. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6650. sleep(retryIntervalInt);
  6651. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6652. if(!isSuccess)
  6653. {
  6654. DEBUG_INFO("Diagnostics fail.\n");
  6655. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6656. }
  6657. else
  6658. {
  6659. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6660. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6661. }
  6662. }
  6663. else
  6664. {
  6665. sscanf(host,"%[^/]%s",host1, path1);
  6666. sprintf(ftppath,"%s", path1);
  6667. int ftppathlen=strlen(ftppath);
  6668. int i=1;
  6669. char filenametemp[50];
  6670. while(i < ftppathlen)
  6671. {
  6672. int len=ftppathlen-i;
  6673. if(ftppath[len]== 47) // '/' ascll code: 47
  6674. {
  6675. DEBUG_INFO("find '/' all right\n");
  6676. break;
  6677. }
  6678. i=i+1;
  6679. }
  6680. memset(filenametemp, 0, sizeof(filenametemp));
  6681. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6682. filenametemp[i+1] = 0;
  6683. memset(ftpbuf, 0, sizeof(ftpbuf));
  6684. if(port == 0)
  6685. port = 21;
  6686. do{
  6687. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6688. sleep(retryIntervalInt);
  6689. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6690. if(!isSuccess)
  6691. {
  6692. DEBUG_INFO("Diagnostics fail.\n");
  6693. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6694. }
  6695. else
  6696. {
  6697. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6698. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6699. }
  6700. }
  6701. end:
  6702. DiagnosticsStatusNotificationStatus = 0; //Idle
  6703. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6704. }
  6705. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6706. {
  6707. mtrace();
  6708. int result = FAIL;
  6709. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6710. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6711. {
  6712. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6713. localversion = -1;
  6714. }
  6715. else
  6716. {
  6717. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6718. OCPP_getListVerion();
  6719. }
  6720. //from db.OCPP_getListVerion
  6721. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6722. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6723. sendGetLocalListVersionConfirmation(uuid,"");
  6724. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6725. return result;
  6726. }
  6727. int handleRemoteStartRequest(char *uuid, char *payload)
  6728. {
  6729. mtrace();
  6730. int result = FAIL;
  6731. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6732. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6733. int tempIndex = 0;
  6734. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6735. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6736. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6737. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6738. int chargingSchedulePeriodCount = 0;
  6739. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6740. int c = 0;
  6741. char *loc;
  6742. char comfirmstr[20]={0};
  6743. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6744. if(server_pending == TRUE)
  6745. {
  6746. return 0;
  6747. }
  6748. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6749. strcpy(sstrtemp, stringtrimspace(payload));
  6750. //**********connectorId****************/
  6751. c = 0;
  6752. memset(sstr ,0, sizeof(sstr) );
  6753. loc = strstr(sstrtemp, "connectorId");
  6754. if(loc == NULL)
  6755. {
  6756. connectorIdIsNULL = TRUE;
  6757. }
  6758. else
  6759. {
  6760. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6761. {
  6762. sstr[c] = loc[strlen("connectorId")+2+c];
  6763. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6764. c++;
  6765. }
  6766. sstr[c] = '\0';
  6767. connectorIdInt = atoi(sstr);
  6768. }
  6769. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6770. {
  6771. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6772. goto end;
  6773. }
  6774. //****************idTag*******************/
  6775. c = 0;
  6776. memset(sstr ,0, sizeof(sstr) );
  6777. loc = strstr(sstrtemp, "idTag");
  6778. while (loc[3+strlen("idTag")+c] != '\"')
  6779. {
  6780. sstr[c] = loc[3+strlen("idTag")+c];
  6781. c++;
  6782. }
  6783. sstr[c] = '\0';
  6784. strcpy(idTagstr,sstr);
  6785. //****************chargingProfile*******************/
  6786. c = 0;
  6787. memset(sstr ,0, sizeof(sstr) );
  6788. loc = strstr(sstrtemp, "chargingProfile");
  6789. if(loc == NULL)
  6790. {
  6791. chargingProfileIsNULL = TRUE;
  6792. }
  6793. else
  6794. {
  6795. //****************chargingProfileId*******************/
  6796. c=0;
  6797. loc = strstr(sstrtemp, "chargingProfileId");
  6798. memset(sstr ,0, sizeof(sstr) );
  6799. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6800. {
  6801. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6802. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6803. c++;
  6804. }
  6805. sstr[c] = '\0';
  6806. chargingProfileIdInt = atoi(sstr);
  6807. //****************transactionId*******************/
  6808. loc = strstr(sstrtemp, "transactionId");
  6809. if(loc == NULL)
  6810. {
  6811. transactionIdIsNULL = TRUE;
  6812. }
  6813. else
  6814. {
  6815. c=0;
  6816. memset(sstr ,0, sizeof(sstr) );
  6817. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6818. {
  6819. sstr[c] = loc[strlen("transactionId")+2+c];
  6820. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6821. c++;
  6822. }
  6823. sstr[c] = '\0';
  6824. transactionIdInt = atoi(sstr);
  6825. }
  6826. //****************stackLevel*******************/
  6827. c=0;
  6828. loc = strstr(sstrtemp, "stackLevel");
  6829. memset(sstr ,0, sizeof(sstr) );
  6830. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6831. {
  6832. sstr[c] = loc[strlen("stackLevel")+2+c];
  6833. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6834. c++;
  6835. }
  6836. sstr[c] = '\0';
  6837. stackLevelInt = atoi(sstr);
  6838. //****************chargingProfilePurpose*******************/
  6839. c = 0;
  6840. memset(sstr ,0, sizeof(sstr) );
  6841. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6842. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6843. {
  6844. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6845. c++;
  6846. }
  6847. sstr[c] = '\0';
  6848. strcpy(chargingProfilePurposestr,sstr);
  6849. //****************chargingProfileKind*******************/
  6850. c = 0;
  6851. memset(sstr ,0, sizeof(sstr) );
  6852. loc = strstr(sstrtemp, "chargingProfileKind");
  6853. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6854. {
  6855. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6856. c++;
  6857. }
  6858. sstr[c] = '\0';
  6859. strcpy(chargingProfileKindstr,sstr);
  6860. //****************recurrencyKind*******************/
  6861. loc = strstr(sstrtemp, "recurrencyKind");
  6862. if(loc == NULL)
  6863. {
  6864. recurrencyKindIsNULL = TRUE;
  6865. }
  6866. else
  6867. {
  6868. c = 0;
  6869. memset(sstr ,0, sizeof(sstr) );
  6870. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6871. {
  6872. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6873. c++;
  6874. }
  6875. sstr[c] = '\0';
  6876. strcpy(recurrencyKindstr,sstr);
  6877. }
  6878. //****************validFrom*******************/
  6879. loc = strstr(sstrtemp, "validFrom");
  6880. if(loc == NULL)
  6881. {
  6882. validFromIsNULL = TRUE;
  6883. }
  6884. else
  6885. {
  6886. c = 0;
  6887. memset(sstr ,0, sizeof(sstr) );
  6888. while (loc[3+strlen("validFrom")+c] != '\"')
  6889. {
  6890. sstr[c] = loc[3+strlen("validFrom")+c];
  6891. c++;
  6892. }
  6893. sstr[c] = '\0';
  6894. strcpy(validFromstr,sstr);
  6895. }
  6896. //****************validTo*******************/
  6897. loc = strstr(sstrtemp, "validTo");
  6898. if(loc == NULL)
  6899. {
  6900. validToIsNULL = TRUE;
  6901. }
  6902. else
  6903. {
  6904. c = 0;
  6905. memset(sstr ,0, sizeof(sstr) );
  6906. while (loc[3+strlen("validTo")+c] != '\"')
  6907. {
  6908. sstr[c] = loc[3+strlen("validTo")+c];
  6909. c++;
  6910. }
  6911. sstr[c] = '\0';
  6912. strcpy(validTostr,sstr);
  6913. }
  6914. //****************chargingSchedule*******************/
  6915. loc = strstr(sstrtemp, "chargingSchedule");
  6916. if(loc != NULL)
  6917. {
  6918. //****************duration*******************/
  6919. loc = strstr(sstrtemp, "duration");
  6920. if(loc == NULL)
  6921. {
  6922. durationIsNULL = TRUE;
  6923. }
  6924. else
  6925. {
  6926. c=0;
  6927. memset(sstr ,0, sizeof(sstr) );
  6928. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6929. {
  6930. sstr[c] = loc[strlen("duration")+2+c];
  6931. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6932. c++;
  6933. }
  6934. sstr[c] = '\0';
  6935. durationInt = atoi(sstr);
  6936. }
  6937. //****************startSchedule******************/
  6938. loc = strstr(sstrtemp, "startSchedule");
  6939. if(loc == NULL)
  6940. {
  6941. startScheduleIsNULL = TRUE;
  6942. }
  6943. else
  6944. {
  6945. c = 0;
  6946. memset(sstr ,0, sizeof(sstr) );
  6947. while (loc[3+strlen("startSchedule")+c] != '\"')
  6948. {
  6949. sstr[c] = loc[3+strlen("startSchedule")+c];
  6950. c++;
  6951. }
  6952. sstr[c] = '\0';
  6953. strcpy(startSchedulestr,sstr);
  6954. }
  6955. //****************chargingRateUnit*******************/
  6956. c = 0;
  6957. memset(sstr ,0, sizeof(sstr) );
  6958. loc = strstr(sstrtemp, "chargingRateUnit");
  6959. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6960. {
  6961. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6962. c++;
  6963. }
  6964. sstr[c] = '\0';
  6965. strcpy(chargingRateUnitstr,sstr);
  6966. //****************minChargingRate*******************/
  6967. loc = strstr(sstrtemp, "minChargingRate");
  6968. if(loc == NULL)
  6969. {
  6970. minChargingRateIsNULL = TRUE;
  6971. }
  6972. else
  6973. {
  6974. c=0;
  6975. memset(sstr ,0, sizeof(sstr) );
  6976. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6977. {
  6978. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6979. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6980. c++;
  6981. }
  6982. sstr[c] = '\0';
  6983. minChargingRateflaot = atof(sstr);
  6984. }
  6985. //****************chargingSchedulePeriod count*******************/
  6986. int what_len = strlen("startPeriod");
  6987. char *where = sstrtemp;
  6988. while ((where = strstr(where, "startPeriod"))) {
  6989. where += what_len;
  6990. chargingSchedulePeriodCount++;
  6991. }
  6992. where = sstrtemp;
  6993. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6994. {
  6995. //****************startPeriod*******************/
  6996. c=0;
  6997. loc = strstr(where, "startPeriod");
  6998. memset(sstr ,0, sizeof(sstr) );
  6999. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7000. {
  7001. sstr[c] = loc[strlen("startPeriod")+2+c];
  7002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7003. c++;
  7004. }
  7005. sstr[c] = '\0';
  7006. startPeriodInt[periodNums] = atoi(sstr);
  7007. //****************limit*******************/
  7008. c=0;
  7009. loc = strstr(where, "limit");
  7010. memset(sstr ,0, sizeof(sstr) );
  7011. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7012. {
  7013. sstr[c] = loc[strlen("limit")+2+c];
  7014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7015. c++;
  7016. }
  7017. sstr[c] = '\0';
  7018. limitflaot[periodNums] = atof(sstr);
  7019. //****************numberPhases*******************/
  7020. loc = strstr(where, "numberPhases");
  7021. if(loc == NULL)
  7022. {
  7023. numberPhasesIsNULL = TRUE;
  7024. }
  7025. else
  7026. {
  7027. c=0;
  7028. memset(sstr ,0, sizeof(sstr) );
  7029. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7030. {
  7031. sstr[c] = loc[strlen("numberPhases")+2+c];
  7032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7033. c++;
  7034. }
  7035. sstr[c] = '\0';
  7036. numberPhasesInt[periodNums] = atoi(sstr);
  7037. }
  7038. where = loc;
  7039. } // END FOR chargingSchedulePeriodCount
  7040. }// END IF chargingSchedule
  7041. } // END chargingProfile
  7042. /*
  7043. enum _SYSTEM_STATUS
  7044. {
  7045. S_BOOTING = 0,
  7046. S_IDLE, = 1
  7047. S_AUTHORIZING, =2
  7048. S_REASSIGN_CHECK, =3
  7049. S_REASSIGN, =4
  7050. S_PRECHARGE, =5
  7051. S_PREPARING_FOR_EV, =6
  7052. S_PREPARING_FOR_EVSE, =7
  7053. S_CHARGING, =8
  7054. S_TERMINATING, =9
  7055. S_COMPLETE, =10
  7056. S_ALARM, =11
  7057. S_FAULT =12
  7058. }
  7059. */
  7060. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7061. {
  7062. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7063. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7064. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7065. //check Transaction active
  7066. if(gunType[connectorIdInt -1] == 'J')
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = connectorIdInt -1;
  7075. }
  7076. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7079. {
  7080. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7081. {
  7082. //Reserved
  7083. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7084. }
  7085. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7086. {
  7087. //Reserved
  7088. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7090. goto end;
  7091. }
  7092. else
  7093. {
  7094. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7095. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7096. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7097. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7098. {
  7099. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7100. goto end;
  7101. }
  7102. }//END FOR ELSE
  7103. }
  7104. }// END FOR CHAdeMO_QUANTITY
  7105. }
  7106. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7107. {
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7109. {
  7110. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7111. }
  7112. else
  7113. {
  7114. tempIndex = connectorIdInt -1;
  7115. }
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7119. {
  7120. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7121. {
  7122. //Reserved
  7123. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7124. }
  7125. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7126. {
  7127. //Reserved
  7128. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7129. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7130. goto end;
  7131. }
  7132. else
  7133. {
  7134. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7135. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7136. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7137. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7138. {
  7139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7140. goto end;
  7141. }
  7142. }// END FOR ELSE
  7143. }
  7144. }// END FOR CCS_QUANTITY
  7145. }
  7146. else if(gunType[connectorIdInt -1] == 'G')
  7147. {
  7148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7149. {
  7150. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7151. }
  7152. else
  7153. {
  7154. tempIndex = connectorIdInt -1;
  7155. }
  7156. for (int index = 0; index < GB_QUANTITY; index++)
  7157. {
  7158. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7159. {
  7160. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7161. {
  7162. //Reserved
  7163. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7164. }
  7165. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7166. {
  7167. //Reserved
  7168. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7169. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7170. goto end;
  7171. }
  7172. else
  7173. {
  7174. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7175. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7176. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7177. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7178. {
  7179. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7180. goto end;
  7181. }
  7182. }// END FOR ELSE
  7183. }
  7184. } // END FOR GB_QUANTITY
  7185. }
  7186. else
  7187. {
  7188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7189. {
  7190. tempIndex = 2;
  7191. }
  7192. else
  7193. {
  7194. tempIndex = connectorIdInt -1;
  7195. }
  7196. for (int index = 0; index < AC_QUANTITY; index++)
  7197. {
  7198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7199. {
  7200. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7201. {
  7202. //Reserved
  7203. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7204. }
  7205. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7210. goto end;
  7211. }
  7212. else
  7213. {
  7214. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7215. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7216. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7217. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7218. {
  7219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7220. goto end;
  7221. }
  7222. }//END FOR ELSE
  7223. }
  7224. }// END FOR AC_QUANTITY
  7225. }
  7226. if(chargingProfileIsNULL == FALSE)
  7227. {
  7228. //ChargingProfile
  7229. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7230. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7231. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7232. if(recurrencyKindIsNULL == FALSE) //OPTION
  7233. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7234. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7235. if(transactionIdIsNULL == FALSE) // OPTION
  7236. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7237. if(validFromIsNULL == FALSE) // OPTION
  7238. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7239. if(validToIsNULL == FALSE) //OPTION
  7240. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7241. //ChargingSchedule
  7242. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7243. if(durationIsNULL == FALSE) //OPTION
  7244. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7245. if(minChargingRateIsNULL == FALSE) //OPTION
  7246. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7247. if(startScheduleIsNULL == FALSE) //OPTION
  7248. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7249. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7250. {
  7251. //ChargingSchedulePeriod
  7252. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7253. if(numberPhasesIsNULL == FALSE)
  7254. {
  7255. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7256. }
  7257. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7258. }
  7259. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7260. {
  7261. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7262. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7263. //memset idTag
  7264. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7265. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7266. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7267. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7268. }
  7269. else
  7270. {
  7271. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7272. }
  7273. }
  7274. else
  7275. {
  7276. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7277. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7278. //memset idTag
  7279. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7280. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7281. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7282. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7283. }
  7284. }
  7285. else
  7286. {
  7287. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7288. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7289. }
  7290. end:
  7291. if(connectorIdIsNULL == FALSE)
  7292. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7293. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7294. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7295. //OCPP send RemoteStartConfirmation by first.
  7296. sendRemoteStartConfirmation(uuid, comfirmstr);
  7297. return result;
  7298. }
  7299. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. int match = FALSE;
  7304. int GunNO = 0;
  7305. int tempIndex = 0;
  7306. int transactionIdInt=0;
  7307. int transactionIdIsNULL= FALSE;
  7308. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7309. int c = 0;
  7310. char *loc;
  7311. char comfirmstr[20];
  7312. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7313. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7314. if(server_pending == TRUE)
  7315. {
  7316. return 0;
  7317. }
  7318. strcpy(sstrtemp, stringtrimspace(payload));
  7319. c=0;
  7320. loc = strstr(sstrtemp, "transactionId");
  7321. if(loc == NULL)
  7322. {
  7323. transactionIdIsNULL= TRUE;
  7324. }
  7325. else
  7326. {
  7327. memset(sstr ,0, sizeof(sstr) );
  7328. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7329. {
  7330. sstr[c] = loc[strlen("transactionId")+2+c];
  7331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. transactionIdInt = atoi(sstr);
  7336. }
  7337. if(transactionIdIsNULL == FALSE)
  7338. {
  7339. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7340. {
  7341. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7342. {
  7343. //check Transaction active
  7344. if(gunType[gun_index] == 'J')
  7345. {
  7346. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7347. {
  7348. tempIndex = ((gun_index==2) ? 1: 0);
  7349. }
  7350. else
  7351. {
  7352. tempIndex = gun_index;
  7353. }
  7354. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7355. {
  7356. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7357. {
  7358. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7359. {
  7360. match = TRUE;
  7361. GunNO = gun_index;
  7362. }
  7363. }
  7364. }// END FOR CHAdeMO_QUANTITY
  7365. }
  7366. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7367. {
  7368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7369. {
  7370. tempIndex = ((gun_index==2) ? 1: 0);
  7371. }
  7372. else
  7373. {
  7374. tempIndex = gun_index;
  7375. }
  7376. for (int index = 0; index < CCS_QUANTITY; index++)
  7377. {
  7378. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7379. {
  7380. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7381. {
  7382. match = TRUE;
  7383. GunNO = gun_index;
  7384. }
  7385. }
  7386. }// END FOR CCS_QUANTITY
  7387. }
  7388. else if(gunType[gun_index] == 'G')
  7389. {
  7390. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7391. {
  7392. tempIndex = ((gun_index==2) ? 1: 0);
  7393. }
  7394. else
  7395. {
  7396. tempIndex = gun_index;
  7397. }
  7398. for (int index = 0; index < GB_QUANTITY; index++)
  7399. {
  7400. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7401. {
  7402. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7403. {
  7404. match = TRUE;
  7405. GunNO = gun_index;
  7406. }
  7407. }
  7408. }// END FOR GB_QUANTITY
  7409. }
  7410. else
  7411. {
  7412. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7413. {
  7414. tempIndex = 2;
  7415. }
  7416. else
  7417. {
  7418. tempIndex = gun_index;
  7419. }
  7420. for (int index = 0; index < AC_QUANTITY; index++)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7423. {
  7424. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7425. {
  7426. match = TRUE;
  7427. GunNO = gun_index;
  7428. }
  7429. }
  7430. }// END FOR CHAdeMO_QUANTITY
  7431. } // END FOR AC ELSE
  7432. }// CHECK IF ResponseTransactionId == transactionIdInt
  7433. }//END FOR
  7434. if( match == TRUE)
  7435. {
  7436. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7437. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7438. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7439. }
  7440. else
  7441. {
  7442. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7443. }
  7444. }
  7445. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7446. return result;
  7447. }
  7448. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7449. {
  7450. mtrace();
  7451. int result = FAIL;
  7452. int connectorIdInt=0, reservationIdInt=0;
  7453. int tempIndex = 0;
  7454. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7455. char comfirmstr[20]={0};
  7456. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7457. int c = 0;
  7458. char *loc;
  7459. //char *ptr;
  7460. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7461. strcpy(sstrtemp, stringtrimspace(payload));
  7462. //***(1)connectorId ****/
  7463. c=0;
  7464. loc = strstr(sstrtemp, "connectorId");
  7465. memset(sstr ,0, sizeof(sstr) );
  7466. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7467. {
  7468. sstr[c] = loc[strlen("connectorId")+2+c];
  7469. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7470. c++;
  7471. }
  7472. sstr[c] = '\0';
  7473. connectorIdInt = atoi(sstr);
  7474. //***(2)expiryDate ****/
  7475. loc = strstr(sstrtemp, "expiryDate");
  7476. memset(sstr ,0, sizeof(sstr) );
  7477. c = 0;
  7478. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7479. {
  7480. sstr[c] = loc[3+strlen("expiryDate")+c];
  7481. c++;
  7482. }
  7483. sstr[c] = '\0';
  7484. strcpy(expiryDatestr, sstr);
  7485. //***(3)idTag ****/
  7486. loc = strstr(sstrtemp, "idTag");
  7487. memset(sstr ,0, sizeof(sstr) );
  7488. c = 0;
  7489. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7490. {
  7491. sstr[c] = loc[3+strlen("idTag")+c];
  7492. c++;
  7493. }
  7494. sstr[c] = '\0';
  7495. strcpy(idTagstr, sstr);
  7496. //***(4)parentIdTag ****/
  7497. loc = strstr(sstrtemp, "parentIdTag");
  7498. memset(sstr ,0, sizeof(sstr) );
  7499. c = 0;
  7500. if(loc == NULL)
  7501. {
  7502. strcpy(parentIdTagstr, "");
  7503. }
  7504. else
  7505. {
  7506. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7507. {
  7508. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7509. c++;
  7510. }
  7511. sstr[c] = '\0';
  7512. strcpy(parentIdTagstr, sstr);
  7513. }
  7514. //***(5)reservationId ****/
  7515. c=0;
  7516. loc = strstr(sstrtemp, "reservationId");
  7517. memset(sstr ,0, sizeof(sstr) );
  7518. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7519. {
  7520. sstr[c] = loc[strlen("reservationId")+2+c];
  7521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7522. c++;
  7523. }
  7524. sstr[c] = '\0';
  7525. reservationIdInt = atoi(sstr);
  7526. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7527. /*
  7528. enum SYSTEM_STATUS
  7529. {
  7530. SYS_MODE_BOOTING = 0,
  7531. SYS_MODE_IDLE = 1,
  7532. SYS_MODE_AUTHORIZING = 2,
  7533. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7534. SYS_MODE_REASSIGN = 4,
  7535. SYS_MODE_PREPARING = 5,
  7536. SYS_MODE_PREPARE_FOR_EV = 6,
  7537. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7538. SYS_MODE_CHARGING = 8,
  7539. SYS_MODE_TERMINATING = 9,
  7540. SYS_MODE_COMPLETE = 10,
  7541. SYS_MODE_ALARM = 11,
  7542. SYS_MODE_FAULT = 12,
  7543. SYS_MODE_RESERVATION = 13,
  7544. SYS_MODE_BOOKING = 14,
  7545. SYS_MODE_MAINTAIN = 15,
  7546. SYS_MODE_DEBUG = 16,
  7547. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7548. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7549. SYS_MODE_UPDATE = 19
  7550. };
  7551. */
  7552. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7553. {
  7554. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7555. goto end;
  7556. }
  7557. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7558. {
  7559. //check Transaction active
  7560. if(gunType[connectorIdInt -1] == 'J')
  7561. {
  7562. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7563. {
  7564. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7565. }
  7566. else
  7567. {
  7568. tempIndex = connectorIdInt -1;
  7569. }
  7570. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7571. {
  7572. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7573. {
  7574. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7575. {
  7576. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7577. {
  7578. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7579. {
  7580. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7582. }
  7583. 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'))
  7584. {
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7586. }
  7587. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7588. {
  7589. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7590. }
  7591. else
  7592. {
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7594. }
  7595. }
  7596. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  7597. {
  7598. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7599. }
  7600. }
  7601. else
  7602. {
  7603. //replace reservation
  7604. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7605. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7606. }
  7607. }
  7608. } // END FOR CHAdeMO_QUANTITY
  7609. }
  7610. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7611. {
  7612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7613. {
  7614. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7615. }
  7616. else
  7617. {
  7618. tempIndex = connectorIdInt -1;
  7619. }
  7620. for (int index = 0; index < CCS_QUANTITY; index++)
  7621. {
  7622. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7623. {
  7624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7625. {
  7626. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7627. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7628. {
  7629. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7633. }
  7634. 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'))
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7637. }
  7638. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7639. {
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7641. }
  7642. else
  7643. {
  7644. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7645. }
  7646. }
  7647. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) ||(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAUL, SYS_MODE_TERMINATING ---> SuspendedEV
  7648. {
  7649. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7650. }
  7651. }
  7652. else
  7653. {
  7654. //replace reservation
  7655. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7656. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7657. }
  7658. }
  7659. } // END FOR CCS_QUANTITY
  7660. }
  7661. else if(gunType[connectorIdInt -1] == 'G')
  7662. {
  7663. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7664. {
  7665. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7666. }
  7667. else
  7668. {
  7669. tempIndex = connectorIdInt -1;
  7670. }
  7671. for (int index = 0; index < GB_QUANTITY; index++)
  7672. {
  7673. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7674. {
  7675. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7676. {
  7677. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7678. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7679. {
  7680. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7681. {
  7682. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7684. }
  7685. 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'))
  7686. {
  7687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7688. }
  7689. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7690. {
  7691. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7692. }
  7693. else
  7694. {
  7695. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7696. }
  7697. }
  7698. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7699. {
  7700. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7701. }
  7702. }
  7703. else
  7704. {
  7705. //replace reservation
  7706. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7708. }
  7709. }
  7710. }// END FOR GB_QUANTITY
  7711. }
  7712. else
  7713. {
  7714. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7715. {
  7716. tempIndex = 2;
  7717. }
  7718. else
  7719. {
  7720. tempIndex = (connectorIdInt -1);
  7721. }
  7722. for (int index = 0; index < AC_QUANTITY; index++)
  7723. {
  7724. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7725. {
  7726. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7727. {
  7728. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7729. {
  7730. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  7733. {
  7734. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7735. }
  7736. else
  7737. {
  7738. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7740. }
  7741. }
  7742. 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'))
  7743. {
  7744. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7745. }
  7746. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7749. }
  7750. else
  7751. {
  7752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7753. }
  7754. }
  7755. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM, SYS_MODE_TERMINATING ---> SuspendedEV
  7756. {
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7758. }
  7759. }
  7760. else
  7761. {
  7762. //replace reservation
  7763. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7765. }
  7766. }
  7767. } // END FOR AC_QUANTITY
  7768. }
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7770. }
  7771. else if(connectorIdInt == 0)
  7772. {
  7773. //check Transaction active
  7774. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7775. {
  7776. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7777. {
  7778. 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'))
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7781. goto end;
  7782. }
  7783. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7784. {
  7785. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7786. goto end;
  7787. }
  7788. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7791. goto end;
  7792. }
  7793. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7796. goto end;
  7797. }
  7798. }
  7799. }// END FOR CHAdeMO_QUANTITY
  7800. for (int index = 0; index < CCS_QUANTITY; index++)
  7801. {
  7802. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7803. {
  7804. 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'))
  7805. {
  7806. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7807. goto end;
  7808. }
  7809. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7810. {
  7811. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7812. goto end;
  7813. }
  7814. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7817. goto end;
  7818. }
  7819. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7820. {
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7822. goto end;
  7823. }
  7824. }
  7825. } // END FOR CCS_QUANTITY
  7826. for (int index = 0; index < GB_QUANTITY; index++)
  7827. {
  7828. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7829. {
  7830. 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'))
  7831. {
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7833. goto end;
  7834. }
  7835. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7836. {
  7837. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7838. goto end;
  7839. }
  7840. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus ==SYS_MODE_TERMINATING) ) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7841. {
  7842. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7843. goto end;
  7844. }
  7845. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7846. {
  7847. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7848. goto end;
  7849. }
  7850. }
  7851. } // END FOR GB_QUANTITY
  7852. for (int index = 0; index < AC_QUANTITY; index++)
  7853. {
  7854. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7855. {
  7856. 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'))
  7857. {
  7858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7859. goto end;
  7860. }
  7861. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7862. {
  7863. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7864. goto end;
  7865. }
  7866. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_TERMINATING ---> SuspendedEV
  7867. {
  7868. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7869. goto end;
  7870. }
  7871. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7872. {
  7873. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7876. goto end;
  7877. }
  7878. }
  7879. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7880. {
  7881. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7882. goto end;
  7883. }
  7884. }
  7885. }// END FOR AC_QUANTITY
  7886. //The connectorId is 0
  7887. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7888. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7889. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7890. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7891. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7892. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7893. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7894. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7895. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7896. result = TRUE;
  7897. return result;
  7898. }
  7899. else
  7900. {
  7901. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7902. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7903. }
  7904. if(strcmp(comfirmstr,"Accepted") == 0)
  7905. {
  7906. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7907. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7908. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7909. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7910. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7911. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7912. result = TRUE;
  7913. return result;
  7914. }
  7915. end:
  7916. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7917. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7918. return result;
  7919. }
  7920. int handleResetRequest(char *uuid, char *payload)
  7921. {
  7922. mtrace();
  7923. int result = FAIL;
  7924. char sstr[10]={0},sstrtemp[30]={ 0 };
  7925. char typestr[10]={0};
  7926. char comfirmstr[20]={0};
  7927. int c = 0;
  7928. char *loc;
  7929. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  7930. DEBUG_INFO("handleResetRequest ...\n");
  7931. strcpy(sstrtemp, stringtrimspace(payload));
  7932. loc = strstr(sstrtemp, "type");
  7933. memset(sstr ,0, sizeof(sstr) );
  7934. c = 0;
  7935. while (loc[3+strlen("type")+c] != '\"')
  7936. {
  7937. sstr[c] = loc[3+strlen("type")+c];
  7938. c++;
  7939. }
  7940. sstr[c] = '\0';
  7941. strcpy(typestr,sstr);
  7942. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7943. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  7944. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7945. {
  7946. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7947. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7948. result = TRUE;
  7949. return result;
  7950. }
  7951. else
  7952. {
  7953. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7954. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7955. goto errorend;
  7956. }
  7957. errorend:
  7958. sendResetConfirmation(uuid, comfirmstr);
  7959. return result;
  7960. }
  7961. int handleSendLocalListRequest(char *uuid, char *payload)
  7962. {
  7963. mtrace();
  7964. int result = FAIL;
  7965. int listVersionInt;
  7966. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7967. char listsearch[]="listVersion";
  7968. char updateTypesearch[]="updateType";
  7969. char localAuthorizationListsearch[]="localAuthorizationList";
  7970. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7971. char CardList[500][160]={0};
  7972. char updateTypestr[15]={0};
  7973. char idTagstr[20]={0};
  7974. char parentIdTag[20]={0};
  7975. char expiryDate[30]={0};
  7976. char idTagstatus[16]={0};
  7977. int c = 0;
  7978. int i = 0;
  7979. char *delim1 = "}";
  7980. char * pch;
  7981. char *loc;
  7982. //char *ptr;
  7983. char comfirmstr[20];
  7984. //int n_localAuthorizations = 0;
  7985. int checkState_Faulted = FALSE;
  7986. DEBUG_INFO("handleSendLocalListRequest\n");
  7987. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7988. {
  7989. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7990. goto end;
  7991. }
  7992. //check Charge Point state
  7993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7994. {
  7995. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7996. {
  7997. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7998. }
  7999. }
  8000. for (int index = 0; index < CCS_QUANTITY; index++)
  8001. {
  8002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8003. {
  8004. checkState_Faulted = TRUE; //OCPP Status
  8005. }
  8006. }
  8007. for (int index = 0; index < GB_QUANTITY; index++)
  8008. {
  8009. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8010. {
  8011. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8012. }
  8013. }
  8014. //check Charge Point state
  8015. for (int index = 0; index < AC_QUANTITY; index++)
  8016. {
  8017. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8018. {
  8019. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8020. }
  8021. }
  8022. if(checkState_Faulted == TRUE)
  8023. {
  8024. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8025. goto end;
  8026. }
  8027. //Filter payload space
  8028. strcpy(sstrtemp, stringtrimspace(payload));
  8029. //listVersion
  8030. c = 0;
  8031. loc = strstr(sstrtemp, listsearch);
  8032. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8033. {
  8034. sstr[c] = loc[strlen("listVersion")+2+c];
  8035. c++;
  8036. }
  8037. sstr[c] = '\0';
  8038. listVersionInt = atoi(sstr);
  8039. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8040. //updateType
  8041. loc = strstr(sstrtemp, updateTypesearch);
  8042. c = 0;
  8043. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8044. {
  8045. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8046. c++;
  8047. }
  8048. sstr[c] = '\0';
  8049. strcpy(updateTypestr, sstr);
  8050. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8051. //localAuthorizationList
  8052. memset(sstr ,0, sizeof(sstr) );
  8053. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8054. if(loc != NULL) // localAuthorizationList is not NULL
  8055. {
  8056. //Check UpdateType
  8057. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8058. {
  8059. //Local list full update
  8060. printf("Local list full update.\n");
  8061. OCPP_getListVerion();
  8062. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8063. {
  8064. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8065. goto end;
  8066. }
  8067. OCPP_cleanLocalList();
  8068. }
  8069. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8070. {
  8071. //Local list different update
  8072. printf("Local list different update.\n");
  8073. OCPP_getListVerion();
  8074. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8075. {
  8076. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8077. goto end;
  8078. }
  8079. }
  8080. else
  8081. {
  8082. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8083. goto end;
  8084. }
  8085. c = 0;
  8086. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8087. {
  8088. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8089. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8090. c++;
  8091. }
  8092. sstr[c] = '\0';
  8093. //DEBUG_INFO("sstr=%s\n", sstr);
  8094. //parsing strings to words
  8095. i = 0;
  8096. pch = strtok(sstr,delim1);
  8097. while (pch != NULL)
  8098. {
  8099. strcpy(CardList[i], pch);
  8100. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8101. pch = strtok (NULL, delim1);
  8102. i = i + 1;
  8103. }
  8104. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8105. //local Authorizations List Numbers
  8106. //n_localAuthorizations = i;
  8107. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8108. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8109. c= 0;
  8110. while(c < i) // i is CardList Number
  8111. {
  8112. //Search "IdToken"
  8113. memset(sstr ,0, sizeof(sstr) );
  8114. loc = strstr(CardList[c], "idTag");
  8115. int j = 0;
  8116. while (loc[3+strlen("idTag")+j] != '\"')
  8117. {
  8118. sstr[j] = loc[3+strlen("idTag")+j];
  8119. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8120. j++;
  8121. }
  8122. sstr[j] = '\0';
  8123. strcpy(idTagstr, sstr);
  8124. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8125. //Search "expiryDate"
  8126. memset(sstr ,0, sizeof(sstr) );
  8127. loc = strstr(CardList[c], "expiryDate");
  8128. j = 0;
  8129. if(loc != NULL)
  8130. {
  8131. while (loc[3+strlen("expiryDate")+j] != '\"')
  8132. {
  8133. sstr[j] = loc[3+strlen("expiryDate")+j];
  8134. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8135. j++;
  8136. }
  8137. sstr[j] = '\0';
  8138. strcpy(expiryDate, sstr);
  8139. }
  8140. else
  8141. {
  8142. strcpy(expiryDate, "");
  8143. }
  8144. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8145. //Search "parentIdTag"
  8146. memset(sstr ,0, sizeof(sstr) );
  8147. loc = strstr(CardList[c], "parentIdTag");
  8148. j = 0;
  8149. if(loc != NULL)
  8150. {
  8151. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8152. {
  8153. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8154. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8155. j++;
  8156. }
  8157. sstr[j] = '\0';
  8158. strcpy(parentIdTag, sstr);
  8159. }
  8160. else
  8161. {
  8162. strcpy(parentIdTag, "");
  8163. }
  8164. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8165. //Search "status"
  8166. memset(sstr ,0, sizeof(sstr) );
  8167. loc = strstr(CardList[c], "status");
  8168. j = 0;
  8169. while (loc[3+strlen("status")+j] != '\"')
  8170. {
  8171. sstr[j] = loc[3+strlen("status")+j];
  8172. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8173. j++;
  8174. }
  8175. sstr[j] = '\0';
  8176. strcpy(idTagstatus, sstr);
  8177. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8178. OCPP_getIdTag(idTagstr);
  8179. //OCPP_getIdTag("test"); For Test
  8180. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8181. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8182. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8183. {
  8184. //Local list full update
  8185. DEBUG_INFO("Local list full update.\n");
  8186. // update list
  8187. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8188. //DEBUG_INFO("Local list full update. 1\n");
  8189. //OCPP_get_TableAuthlocalAllData();
  8190. //DEBUG_INFO("Local list full update. 2\n");
  8191. }
  8192. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8193. {
  8194. #if 0
  8195. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8196. {
  8197. //OCPP_deleteIdTag(idTagstr);
  8198. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8199. }
  8200. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8201. {
  8202. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8203. }
  8204. #endif
  8205. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8206. }
  8207. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8208. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8209. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8210. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8211. c++;
  8212. }
  8213. }
  8214. else
  8215. {
  8216. //Check UpdateType
  8217. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8218. {
  8219. //Local list full update
  8220. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8221. OCPP_cleanLocalList();
  8222. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8223. goto end;
  8224. }
  8225. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8226. {
  8227. //Local list different update
  8228. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8229. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8230. goto end;
  8231. }
  8232. }
  8233. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8234. end:
  8235. sendSendLocalListConfirmation(uuid, comfirmstr);
  8236. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8237. return result;
  8238. }
  8239. #define MAX 200
  8240. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8241. {
  8242. mtrace();
  8243. int result = FAIL;
  8244. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8245. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8246. char chargingProfilePurposeStr[30]={0};
  8247. char chargingProfileKindStr[16]={0};
  8248. char recurrencyKindStr[10]={0};
  8249. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8250. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8251. int chargingSchedulePeriodCount = 0;
  8252. //int updateflag = FALSE;
  8253. char comfirmstr[20]={0};
  8254. int meet= FALSE;
  8255. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8256. int c = 0;
  8257. char *loc;
  8258. FILE *fptr1;//, *fptr2;
  8259. //int lno=0;//, linectr = 0;
  8260. //int modifyflag = FALSE;
  8261. char filename[MAX]={0};
  8262. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8263. //int resultRename=0;
  8264. char rmFileCmd[50]={0};
  8265. char tempchargingProfilePurposeStr[30]={0};
  8266. char word[1600]={0};
  8267. int n_chargingProfile = 0;
  8268. //[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}}}]
  8269. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8270. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8271. //Filter string space
  8272. strcpy(sstrtemp, stringtrimspace(payload));
  8273. //*********************connectorId***************************/
  8274. loc = strstr(sstrtemp, "connectorId");
  8275. c = 0;
  8276. memset(sstr ,0, sizeof(sstr) );
  8277. while (loc[strlen("connectorId")+2+c] != ',')
  8278. {
  8279. sstr[c] = loc[strlen("connectorId")+2+c];
  8280. c++;
  8281. }
  8282. sstr[c] = '\0';
  8283. connectorIdInt = atoi(sstr);
  8284. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8285. {
  8286. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8287. }
  8288. else
  8289. {
  8290. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8291. }
  8292. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8293. //*********************chargingProfileId***************************/
  8294. loc = strstr(sstrtemp, "chargingProfileId");
  8295. c = 0;
  8296. memset(sstr ,0, sizeof(sstr) );
  8297. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8298. {
  8299. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8300. c++;
  8301. }
  8302. sstr[c] = '\0';
  8303. chargingProfileIdInt = atoi(sstr);
  8304. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8305. {
  8306. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8307. }
  8308. else
  8309. {
  8310. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8311. }
  8312. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8313. //*********************transactionId***************************/
  8314. loc = strstr(sstrtemp, "transactionId");
  8315. if(loc != NULL)
  8316. {
  8317. c = 0;
  8318. memset(sstr ,0, sizeof(sstr) );
  8319. while (loc[strlen("transactionId")+2+c] != ',')
  8320. {
  8321. sstr[c] = loc[strlen("transactionId")+2+c];
  8322. c++;
  8323. }
  8324. sstr[c] = '\0';
  8325. transactionIdInt = atoi(sstr);
  8326. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8327. {
  8328. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8329. }
  8330. else
  8331. {
  8332. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8333. }
  8334. }
  8335. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8336. //*********************stackLevel***************************/
  8337. loc = strstr(sstrtemp, "stackLevel");
  8338. c = 0;
  8339. memset(sstr ,0, sizeof(sstr) );
  8340. while (loc[strlen("stackLevel")+2+c] != ',')
  8341. {
  8342. sstr[c] = loc[strlen("stackLevel")+2+c];
  8343. c++;
  8344. }
  8345. sstr[c] = '\0';
  8346. stackLevelInt = atoi(sstr);
  8347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8348. {
  8349. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8350. }
  8351. else
  8352. {
  8353. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8354. }
  8355. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8356. //*********************chargingProfilePurpose***************************/
  8357. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8358. c = 0;
  8359. memset(sstr ,0, sizeof(sstr) );
  8360. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8361. {
  8362. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8364. c++;
  8365. }
  8366. sstr[c] = '\0';
  8367. strcpy(chargingProfilePurposeStr,sstr);
  8368. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8369. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8370. {
  8371. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8372. }
  8373. else
  8374. {
  8375. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8376. }
  8377. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8378. //*********************chargingProfileKind***************************/
  8379. loc = strstr(sstrtemp, "chargingProfileKind");
  8380. c = 0;
  8381. memset(sstr ,0, sizeof(sstr) );
  8382. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8383. {
  8384. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8386. c++;
  8387. }
  8388. sstr[c] = '\0';
  8389. strcpy(chargingProfileKindStr,sstr);
  8390. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8391. {
  8392. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8393. }
  8394. else
  8395. {
  8396. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8397. }
  8398. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8399. //*********************recurrencyKind***************************/
  8400. loc = strstr(sstrtemp, "recurrencyKind");
  8401. if(loc != NULL)
  8402. {
  8403. c = 0;
  8404. memset(sstr ,0, sizeof(sstr) );
  8405. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8406. {
  8407. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8408. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8409. c++;
  8410. }
  8411. sstr[c] = '\0';
  8412. strcpy(recurrencyKindStr,sstr);
  8413. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8414. {
  8415. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8416. }
  8417. else
  8418. {
  8419. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8420. }
  8421. }
  8422. else
  8423. {
  8424. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8425. {
  8426. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8427. }
  8428. else
  8429. {
  8430. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8431. }
  8432. }
  8433. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8434. //*********************validFrom***************************/
  8435. loc = strstr(sstrtemp, "validFrom");
  8436. if(loc != NULL)
  8437. {
  8438. c = 0;
  8439. memset(sstr ,0, sizeof(sstr) );
  8440. while (loc[3+strlen("validFrom")+c] != '\"')
  8441. {
  8442. sstr[c] = loc[3+strlen("validFrom")+c];
  8443. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8444. c++;
  8445. }
  8446. sstr[c] = '\0';
  8447. strcpy(validFromStr,sstr);
  8448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8449. {
  8450. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8451. }
  8452. else
  8453. {
  8454. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8455. }
  8456. }
  8457. else
  8458. {
  8459. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8460. {
  8461. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8462. }
  8463. else
  8464. {
  8465. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8466. }
  8467. }
  8468. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8469. //*********************validTo***************************/
  8470. loc = strstr(sstrtemp, "validTo");
  8471. if(loc != NULL)
  8472. {
  8473. c = 0;
  8474. memset(sstr ,0, sizeof(sstr) );
  8475. while (loc[3+strlen("validTo")+c] != '\"')
  8476. {
  8477. sstr[c] = loc[3+strlen("validTo")+c];
  8478. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8479. c++;
  8480. }
  8481. sstr[c] = '\0';
  8482. strcpy(validToStr,sstr);
  8483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8484. {
  8485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8486. }
  8487. else
  8488. {
  8489. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8490. }
  8491. }
  8492. else
  8493. {
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8497. }
  8498. else
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8501. }
  8502. }
  8503. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8504. //*********************duration***************************/
  8505. loc = strstr(sstrtemp, "duration");
  8506. if(loc != NULL)
  8507. {
  8508. c = 0;
  8509. memset(sstr ,0, sizeof(sstr) );
  8510. while (loc[strlen("duration")+2+c] != ',')
  8511. {
  8512. sstr[c] = loc[strlen("duration")+2+c];
  8513. c++;
  8514. }
  8515. sstr[c] = '\0';
  8516. durationInt = atoi(sstr);
  8517. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8518. {
  8519. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8520. }
  8521. else
  8522. {
  8523. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8524. }
  8525. }
  8526. else
  8527. {
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8531. }
  8532. else
  8533. {
  8534. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8535. }
  8536. }
  8537. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8538. //*********************startSchedule***************************/
  8539. loc = strstr(sstrtemp, "startSchedule");
  8540. if(loc != NULL)
  8541. {
  8542. c = 0;
  8543. memset(sstr ,0, sizeof(sstr) );
  8544. while (loc[3+strlen("startSchedule")+c] != '\"')
  8545. {
  8546. sstr[c] = loc[3+strlen("startSchedule")+c];
  8547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8548. c++;
  8549. }
  8550. sstr[c] = '\0';
  8551. strcpy(startScheduleStr,sstr);
  8552. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8553. {
  8554. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8555. }
  8556. else
  8557. {
  8558. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8559. }
  8560. }
  8561. else
  8562. {
  8563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8564. {
  8565. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8566. }
  8567. else
  8568. {
  8569. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8570. }
  8571. }
  8572. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8573. //*********************chargingRateUnit***************************/
  8574. loc = strstr(sstrtemp, "chargingRateUnit");
  8575. if(loc != NULL)
  8576. {
  8577. c = 0;
  8578. memset(sstr ,0, sizeof(sstr) );
  8579. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8580. {
  8581. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8582. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8583. c++;
  8584. }
  8585. sstr[c] = '\0';
  8586. strcpy(chargingRateUnitStr,sstr);
  8587. #if 0
  8588. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8589. {
  8590. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8591. goto end;
  8592. }
  8593. #endif
  8594. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8595. {
  8596. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8597. }
  8598. else
  8599. {
  8600. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8601. }
  8602. }
  8603. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8604. //****************chargingSchedulePeriod count start*******************/
  8605. int what_len = strlen("startPeriod");
  8606. char tempChargingProfile[1600]={0};
  8607. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8608. char *where = tempChargingProfile;
  8609. if (what_len)
  8610. {
  8611. while ((where = strstr(where, "startPeriod"))) {
  8612. where += what_len;
  8613. chargingSchedulePeriodCount++;
  8614. }
  8615. }
  8616. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8617. {
  8618. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8619. goto end;
  8620. }
  8621. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8622. //where = payload;
  8623. int templength = 0;
  8624. //int searchstart = 0;
  8625. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8626. {
  8627. //****************startPeriod*******************/
  8628. c=0;
  8629. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8630. memset(sstr ,0, sizeof(sstr) );
  8631. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8632. {
  8633. sstr[c] = loc[strlen("startPeriod")+2+c];
  8634. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8635. c++;
  8636. }
  8637. sstr[c] = '\0';
  8638. startPeriodInt[periodNums] = atoi(sstr);
  8639. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8640. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8641. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8642. {
  8643. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8644. }
  8645. else
  8646. {
  8647. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8648. }
  8649. templength = strlen("startPeriod")+2+c;
  8650. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8651. //****************limit*******************/
  8652. c=0;
  8653. loc = strstr(tempChargingProfile + templength, "limit");
  8654. memset(sstr ,0, sizeof(sstr) );
  8655. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8656. {
  8657. sstr[c] = loc[strlen("limit")+2+c];
  8658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8659. c++;
  8660. }
  8661. sstr[c] = '\0';
  8662. limitflaot[periodNums] = atof(sstr);
  8663. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8664. {
  8665. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8666. }
  8667. else
  8668. {
  8669. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8670. }
  8671. templength = templength + strlen("limit")+2+c;
  8672. //****************numberPhases*******************/
  8673. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8674. if(loc != NULL)
  8675. {
  8676. c=0;
  8677. memset(sstr ,0, sizeof(sstr) );
  8678. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8679. {
  8680. sstr[c] = loc[strlen("numberPhases")+2+c];
  8681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8682. c++;
  8683. }
  8684. sstr[c] = '\0';
  8685. numberPhasesInt[periodNums] = atoi(sstr);
  8686. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8687. {
  8688. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8689. }
  8690. else
  8691. {
  8692. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8693. }
  8694. templength = templength + strlen("numberPhases")+2+c;
  8695. }
  8696. //where = loc;
  8697. }
  8698. //****************chargingSchedulePeriod count end*******************/
  8699. //*********************minChargingRate***************************/
  8700. loc = strstr(sstrtemp, "minChargingRate");
  8701. if(loc != NULL)
  8702. {
  8703. c = 0;
  8704. memset(sstr ,0, sizeof(sstr) );
  8705. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8706. {
  8707. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8708. c++;
  8709. }
  8710. sstr[c] = '\0';
  8711. minChargingRateFloat = atof(sstr);
  8712. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8713. {
  8714. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8715. }
  8716. else
  8717. {
  8718. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8719. }
  8720. }
  8721. else
  8722. {
  8723. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8724. {
  8725. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8726. }
  8727. else
  8728. {
  8729. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8730. }
  8731. }
  8732. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8733. {
  8734. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8735. if(connectorIdInt != 0)
  8736. {
  8737. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8738. goto end;
  8739. }
  8740. strcpy(filename, ChargePointMaxProfile_JSON );
  8741. fptr1 = fopen(filename, "r");
  8742. if (!fptr1)
  8743. {
  8744. //file not exist
  8745. DEBUG_INFO("Unable to open the input file!!\n");
  8746. fptr1 = fopen(filename, "w+");
  8747. }
  8748. else
  8749. {
  8750. //Check Charging Profile Count
  8751. while(fscanf(fptr1, "%s", word) != EOF)
  8752. {
  8753. //DEBUG_INFO("word=%s\n",word);
  8754. if(strstr(word, "chargingProfileId")!= NULL)
  8755. {
  8756. //DEBUG_INFO("test chargingProfileId \n");
  8757. n_chargingProfile = n_chargingProfile + 1;
  8758. //DEBUG_INFO("chargingProfileId Found\n");
  8759. }
  8760. }
  8761. }
  8762. fclose(fptr1);
  8763. }
  8764. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8765. {
  8766. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8767. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8768. {
  8769. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8770. goto end;
  8771. }
  8772. memset(filename, 0, sizeof filename);
  8773. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8774. fptr1 = fopen(filename, "r");
  8775. if (!fptr1)
  8776. {
  8777. //file not exist
  8778. //DEBUG_INFO("Unable to open the input file!!\n");
  8779. fptr1 = fopen(filename, "w+");
  8780. }
  8781. else
  8782. {
  8783. //Check Charging Profile Count
  8784. while(fscanf(fptr1, "%s", word) != EOF)
  8785. {
  8786. //DEBUG_INFO("word=%s\n",word);
  8787. if(strstr(word, "chargingProfileId")!= NULL)
  8788. {
  8789. //DEBUG_INFO("test chargingProfileId \n");
  8790. n_chargingProfile = n_chargingProfile + 1;
  8791. //DEBUG_INFO("chargingProfileId Found\n");
  8792. }
  8793. }
  8794. }
  8795. fclose(fptr1);
  8796. }
  8797. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8798. {
  8799. //printf("set chargingProfile 1-4\n");
  8800. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8801. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8802. if(connectorIdInt == 0)
  8803. {
  8804. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8805. goto end;
  8806. }
  8807. int tempIndex = 0;
  8808. //check Transaction active
  8809. if(gunType[connectorIdInt -1] == 'J')
  8810. {
  8811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8812. {
  8813. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8814. }
  8815. else
  8816. {
  8817. tempIndex = connectorIdInt -1;
  8818. }
  8819. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8820. {
  8821. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8822. {
  8823. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8824. {
  8825. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8826. {
  8827. meet = TRUE;
  8828. break;
  8829. }
  8830. }
  8831. }
  8832. }
  8833. }
  8834. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8835. {
  8836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8837. {
  8838. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8839. }
  8840. else
  8841. {
  8842. tempIndex = connectorIdInt -1;
  8843. }
  8844. for (int index = 0; index < CCS_QUANTITY; index++)
  8845. {
  8846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8847. {
  8848. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8849. {
  8850. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8851. {
  8852. meet = TRUE;
  8853. break;
  8854. }
  8855. }
  8856. }
  8857. }
  8858. }
  8859. else if(gunType[connectorIdInt -1] == 'G')
  8860. {
  8861. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8862. {
  8863. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8864. }
  8865. else
  8866. {
  8867. tempIndex = connectorIdInt -1;
  8868. }
  8869. for (int index = 0; index < GB_QUANTITY; index++)
  8870. {
  8871. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8872. {
  8873. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8874. {
  8875. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8876. {
  8877. meet = TRUE;
  8878. break;
  8879. }
  8880. }
  8881. }
  8882. }
  8883. }
  8884. else
  8885. {
  8886. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8887. {
  8888. tempIndex = 2;
  8889. }
  8890. else
  8891. {
  8892. tempIndex = (connectorIdInt -1);
  8893. }
  8894. for (int index = 0; index < AC_QUANTITY; index++)
  8895. {
  8896. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8897. {
  8898. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8899. {
  8900. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8901. {
  8902. meet = TRUE;
  8903. break;
  8904. }
  8905. }
  8906. }
  8907. }
  8908. }
  8909. //check Transaction active
  8910. if(meet == FALSE)
  8911. {
  8912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8913. goto end;
  8914. }
  8915. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8916. {
  8917. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8918. goto end;
  8919. }
  8920. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8921. fptr1 = fopen(filename, "r");
  8922. if (!fptr1)
  8923. {
  8924. //file not exist
  8925. DEBUG_INFO("Unable to open the input file!!\n");
  8926. fptr1 = fopen(filename, "w+");
  8927. }
  8928. else
  8929. {
  8930. //Check Charging Profile Count
  8931. while(fscanf(fptr1, "%s", word) != EOF)
  8932. {
  8933. //DEBUG_INFO("word=%s\n",word);
  8934. if(strstr(word, "chargingProfileId")!= NULL)
  8935. {
  8936. //DEBUG_INFO("test chargingProfileId \n");
  8937. n_chargingProfile = n_chargingProfile + 1;
  8938. //DEBUG_INFO("chargingProfileId Found\n");
  8939. }
  8940. }
  8941. }
  8942. fclose(fptr1);
  8943. }
  8944. // Check ChargeProfileMaxStackLevel
  8945. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8946. {
  8947. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8948. goto end;
  8949. }
  8950. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8951. {
  8952. int i = 0;
  8953. char fnametemp[200]={0};
  8954. n_chargingProfile = 0;
  8955. //Check ChargePointMaxProfile.json exit
  8956. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8957. {
  8958. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8959. //Check Charging Profile Count
  8960. while(fscanf(fptr1, "%s", word) != EOF)
  8961. {
  8962. //DEBUG_INFO("word=%s\n",word);
  8963. if(strstr(word, "chargingProfileId")!= NULL)
  8964. {
  8965. //DEBUG_INFO("test chargingProfileId \n");
  8966. n_chargingProfile = n_chargingProfile + 1;
  8967. i = i + 1;
  8968. //DEBUG_INFO("chargingProfileId Found\n");
  8969. }
  8970. memset(word, 0, sizeof word);
  8971. }
  8972. fclose(fptr1);
  8973. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8974. }
  8975. //Check TxDefaultProfile_0.json exit
  8976. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8977. {
  8978. i = 0;
  8979. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8980. //Check Charging Profile Count
  8981. while(fscanf(fptr1, "%s", word) != EOF)
  8982. {
  8983. //DEBUG_INFO("word=%s\n",word);
  8984. if(strstr(word, "chargingProfileId")!= NULL)
  8985. {
  8986. //DEBUG_INFO("test chargingProfileId \n");
  8987. n_chargingProfile = n_chargingProfile + 1;
  8988. i = i + 1;
  8989. //DEBUG_INFO("chargingProfileId Found\n");
  8990. }
  8991. memset(word, 0, sizeof word);
  8992. }
  8993. fclose(fptr1);
  8994. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8995. }
  8996. //Check TxDefaultProfile_%d.json
  8997. for(int j=1; j <= gunTotalNumber; j++)
  8998. {
  8999. memset(fnametemp, 0, sizeof fnametemp);
  9000. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9001. if((access(fnametemp,F_OK))!=-1)
  9002. {
  9003. i = 0;
  9004. fptr1 = fopen(fnametemp, "r");
  9005. //Check Charging Profile Count
  9006. while(fscanf(fptr1, "%s", word) != EOF)
  9007. {
  9008. //DEBUG_INFO("word=%s\n",word);
  9009. if(strstr(word, "chargingProfileId")!= NULL)
  9010. {
  9011. //DEBUG_INFO("test chargingProfileId \n");
  9012. n_chargingProfile = n_chargingProfile + 1;
  9013. i = i + 1;
  9014. //DEBUG_INFO("chargingProfileId Found\n");
  9015. }
  9016. memset(word, 0, sizeof word);
  9017. }
  9018. fclose(fptr1);
  9019. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9020. }
  9021. }
  9022. //Check TxProfile_%d.json
  9023. for(int j=1; j <= gunTotalNumber; j++)
  9024. {
  9025. memset(fnametemp, 0, sizeof fnametemp);
  9026. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9027. if((access(fnametemp,F_OK))!=-1)
  9028. {
  9029. i = 0;
  9030. fptr1 = fopen(fnametemp, "r");
  9031. //Check Charging Profile Count
  9032. while(fscanf(fptr1, "%s", word) != EOF)
  9033. {
  9034. //DEBUG_INFO("word=%s\n",word);
  9035. if(strstr(word, "chargingProfileId")!= NULL)
  9036. {
  9037. //DEBUG_INFO("test chargingProfileId \n");
  9038. n_chargingProfile = n_chargingProfile + 1;
  9039. i = i + 1;
  9040. //DEBUG_INFO("chargingProfileId Found\n");
  9041. }
  9042. memset(word, 0, sizeof word);
  9043. }
  9044. fclose(fptr1);
  9045. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9046. }
  9047. }
  9048. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9049. {
  9050. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9051. goto end;
  9052. }
  9053. }
  9054. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9055. //**********************************Write to File********************************************************/
  9056. FILE *infile;
  9057. FILE *outfile;
  9058. // open file for writing
  9059. infile = fopen (filename, "r");
  9060. outfile = fopen (tempfile, "w");
  9061. int d =0;
  9062. d = fgetc(infile);
  9063. //DEBUG_INFO("d:%d\n",d);
  9064. rewind(infile);
  9065. //*检测到文件结束标识返回1,否则返回0。*/
  9066. if(d == EOF)
  9067. {
  9068. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9069. fprintf(outfile,"%s\n",payload);
  9070. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9071. fclose(infile);
  9072. fclose(outfile);
  9073. sprintf(rmFileCmd,"rm -f %s",filename);
  9074. system(rmFileCmd);
  9075. rename(tempfile, filename);
  9076. sleep(1);
  9077. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9078. //system(rmFileCmd);
  9079. }
  9080. else
  9081. {
  9082. char buf[1000]={0};
  9083. int ChargingProfileAdded = FALSE;
  9084. while (fgets(buf, sizeof(buf), infile) != NULL)
  9085. {
  9086. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9087. //*************************tempconnectorIdInt*********************************/
  9088. loc = strstr(buf, "connectorId");
  9089. c = 0;
  9090. memset(sstr ,0, sizeof(sstr) );
  9091. while (loc[strlen("connectorId")+2+c] != ',')
  9092. {
  9093. sstr[c] = loc[strlen("connectorId")+2+c];
  9094. c++;
  9095. }
  9096. sstr[c] = '\0';
  9097. tempconnectorIdInt = atoi(sstr);
  9098. //*************************tempchargingProfileIdInt*********************************/
  9099. loc = strstr(buf, "chargingProfileId");
  9100. c = 0;
  9101. memset(sstr ,0, sizeof(sstr) );
  9102. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9103. {
  9104. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9105. c++;
  9106. }
  9107. sstr[c] = '\0';
  9108. tempchargingProfileIdInt = atoi(sstr);
  9109. //*************************tempstackLevelInt*********************************/
  9110. loc = strstr(buf, "stackLevel");
  9111. c = 0;
  9112. memset(sstr ,0, sizeof(sstr) );
  9113. while (loc[strlen("stackLevel")+2+c] != ',')
  9114. {
  9115. sstr[c] = loc[strlen("stackLevel")+2+c];
  9116. c++;
  9117. }
  9118. sstr[c] = '\0';
  9119. tempstackLevelInt = atoi(sstr);
  9120. //*************************tempchargingProfilePurposeStr*********************************/
  9121. loc = strstr(payload, "chargingProfilePurpose");
  9122. c = 0;
  9123. memset(sstr ,0, sizeof(sstr) );
  9124. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9125. {
  9126. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9128. c++;
  9129. }
  9130. sstr[c] = '\0';
  9131. strcpy(tempchargingProfilePurposeStr,sstr);
  9132. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9133. {
  9134. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9135. {
  9136. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9137. if(ChargingProfileAdded == FALSE)
  9138. {
  9139. fprintf(outfile,"%s\n",payload);
  9140. ChargingProfileAdded = TRUE;
  9141. }
  9142. }
  9143. else
  9144. {
  9145. if(tempstackLevelInt < stackLevelInt)
  9146. {
  9147. if(ChargingProfileAdded == FALSE)
  9148. {
  9149. fprintf(outfile,"%s\n",payload);
  9150. ChargingProfileAdded = TRUE;
  9151. fprintf(outfile,"%s\n",buf);
  9152. }
  9153. else
  9154. {
  9155. fprintf(outfile,"%s\n",buf);
  9156. }
  9157. }
  9158. else
  9159. {
  9160. if(ChargingProfileAdded == FALSE)
  9161. {
  9162. fprintf(outfile,"%s\n",buf);
  9163. fprintf(outfile,"%s\n",payload);
  9164. ChargingProfileAdded = TRUE;
  9165. }
  9166. else
  9167. {
  9168. fprintf(outfile,"%s\n",buf);
  9169. }
  9170. }
  9171. }
  9172. }
  9173. else
  9174. {
  9175. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9176. {
  9177. if(ChargingProfileAdded == FALSE)
  9178. {
  9179. fprintf(outfile,"%s\n",payload);
  9180. ChargingProfileAdded = TRUE;
  9181. fprintf(outfile,"%s\n",buf);
  9182. }
  9183. else
  9184. {
  9185. fprintf(outfile,"%s\n",buf);
  9186. }
  9187. }
  9188. else if(tempstackLevelInt < stackLevelInt)
  9189. {
  9190. if(ChargingProfileAdded == FALSE)
  9191. {
  9192. fprintf(outfile,"%s\n",payload);
  9193. ChargingProfileAdded = TRUE;
  9194. fprintf(outfile,"%s\n",buf);
  9195. }
  9196. else
  9197. {
  9198. fprintf(outfile,"%s\n",buf);
  9199. }
  9200. }
  9201. else
  9202. {
  9203. if(ChargingProfileAdded == FALSE)
  9204. {
  9205. fprintf(outfile,"%s\n",buf);
  9206. fprintf(outfile,"%s\n",payload);
  9207. ChargingProfileAdded = TRUE;
  9208. }
  9209. else
  9210. {
  9211. fprintf(outfile,"%s\n",buf);
  9212. }
  9213. }
  9214. }
  9215. } // end of while loop
  9216. fclose(infile);
  9217. fclose(outfile);
  9218. sprintf(rmFileCmd,"rm -f %s",filename);
  9219. system(rmFileCmd);
  9220. rename(tempfile, filename);
  9221. sleep(1);
  9222. result = TRUE;
  9223. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9224. }
  9225. end:
  9226. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9227. return result;
  9228. return result;
  9229. }
  9230. int handleTriggerMessageRequest(char *uuid, char *payload)
  9231. {
  9232. mtrace();
  9233. int result = FAIL;
  9234. int connectorIdIsNULL = FALSE;
  9235. int connectorIdInt =0;
  9236. char sstr[40]={0},sstrtemp[100]={ 0 };
  9237. char requestedMessagestr[40]={0};
  9238. char comfirmstr[20]={0};
  9239. int c = 0;
  9240. char *loc;
  9241. DEBUG_INFO("handleTriggerMessageRequest\n");
  9242. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9243. strcpy(sstrtemp, stringtrimspace(payload));
  9244. c = 0;
  9245. loc = strstr(sstrtemp, "requestedMessage");
  9246. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9247. {
  9248. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9249. c++;
  9250. }
  9251. sstr[c] = '\0';
  9252. strcpy(requestedMessagestr, sstr);
  9253. c = 0;
  9254. loc = strstr(sstrtemp, "connectorId");
  9255. if(loc == NULL)
  9256. {
  9257. connectorIdIsNULL = TRUE;
  9258. }
  9259. else
  9260. {
  9261. memset(sstr ,0, sizeof(sstr) );
  9262. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9263. {
  9264. sstr[c] = loc[strlen("connectorId")+2+c];
  9265. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9266. c++;
  9267. }
  9268. sstr[c] = '\0';
  9269. connectorIdInt = atoi(sstr);
  9270. }
  9271. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9272. {
  9273. //connectorIdInt = json_object_get_int(connectorId);
  9274. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9275. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9276. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9277. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9278. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9279. }
  9280. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9281. {
  9282. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9283. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9284. return TRUE;
  9285. }
  9286. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9287. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9288. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9289. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9290. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9291. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9292. {
  9293. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9294. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9295. return TRUE;
  9296. }
  9297. else
  9298. {
  9299. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9300. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9301. }
  9302. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9303. {
  9304. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9305. {
  9306. FirmwareStatusNotificationStatus = 3;
  9307. }
  9308. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9309. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9310. }
  9311. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9312. {
  9313. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9314. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9315. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9316. }
  9317. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9318. {
  9319. sendBootNotificationRequest();
  9320. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9321. }
  9322. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9323. {
  9324. sendHeartbeatRequest(connectorIdInt);
  9325. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9326. }
  9327. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9328. {
  9329. if(connectorIdIsNULL == FALSE)
  9330. {
  9331. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9332. {
  9333. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9334. sendMeterValuesRequest(connectorIdInt -1);
  9335. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9336. }
  9337. }
  9338. else
  9339. {
  9340. for(int idx=0;idx< gunTotalNumber;idx++)
  9341. {
  9342. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9343. sendMeterValuesRequest(idx);
  9344. }
  9345. }
  9346. }
  9347. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9348. {
  9349. if(connectorIdIsNULL == FALSE)
  9350. {
  9351. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9352. {
  9353. sendStatusNotificationRequest(connectorIdInt -1);
  9354. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9355. }
  9356. }
  9357. else
  9358. {
  9359. for(int idx=0;idx< gunTotalNumber;idx++)
  9360. sendStatusNotificationRequest(idx);
  9361. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9362. }
  9363. }
  9364. return result;
  9365. }
  9366. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9367. {
  9368. mtrace();
  9369. int result = FAIL;
  9370. char sstr[6]={0},sstrtemp[50]={ 0 };
  9371. int connectorIdInt =0;
  9372. char comfirmstr[20]={0};
  9373. int c = 0;
  9374. int tempIndex = 0;
  9375. char *loc;
  9376. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9377. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9378. strcpy(sstrtemp, stringtrimspace(payload));
  9379. c = 0;
  9380. loc = strstr(sstrtemp, "connectorId");
  9381. memset(sstr ,0, sizeof(sstr) );
  9382. while (loc[strlen("connectorId")+2+c] != '}')
  9383. {
  9384. sstr[c] = loc[strlen("connectorId")+2+c];
  9385. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9386. c++;
  9387. }
  9388. sstr[c] = '\0';
  9389. connectorIdInt = atoi(sstr);
  9390. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9391. if(gunTotalNumber == 0)
  9392. {
  9393. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9394. goto end;
  9395. }
  9396. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9397. {
  9398. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9399. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9400. goto end;
  9401. }
  9402. else
  9403. {
  9404. //check Transaction active
  9405. if(gunType[connectorIdInt-1] == 'J')
  9406. {
  9407. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9408. {
  9409. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9410. }
  9411. else
  9412. {
  9413. tempIndex = connectorIdInt -1;
  9414. }
  9415. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9416. {
  9417. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9418. {
  9419. //stop Transaction
  9420. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9421. }
  9422. }
  9423. }
  9424. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9425. {
  9426. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9427. {
  9428. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9429. }
  9430. else
  9431. {
  9432. tempIndex = connectorIdInt -1;
  9433. }
  9434. for (int index = 0; index < CCS_QUANTITY; index++)
  9435. {
  9436. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9437. {
  9438. //stop Transaction
  9439. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9440. }
  9441. }
  9442. }
  9443. else if(gunType[connectorIdInt-1] == 'G')
  9444. {
  9445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9446. {
  9447. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9448. }
  9449. else
  9450. {
  9451. tempIndex = connectorIdInt -1;
  9452. }
  9453. for (int index = 0; index < GB_QUANTITY; index++)
  9454. {
  9455. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9456. {
  9457. //stop Transaction
  9458. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9459. }
  9460. }
  9461. }
  9462. else
  9463. {
  9464. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9465. {
  9466. tempIndex = 2;
  9467. }
  9468. else
  9469. {
  9470. tempIndex = connectorIdInt-1;
  9471. }
  9472. for (int index = 0; index < AC_QUANTITY; index++)
  9473. {
  9474. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9475. {
  9476. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9477. }
  9478. }
  9479. }
  9480. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9481. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9482. result = TRUE;
  9483. return result;
  9484. }
  9485. end:
  9486. //json_object_put(obj); --- remove temporally
  9487. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9488. return result;
  9489. }
  9490. static char UpdateFirmwarepayloadData[300]={0};
  9491. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9492. {
  9493. mtrace();
  9494. int result = FAIL;
  9495. pthread_t t;
  9496. sendUpdateFirmwareConfirmation(uuid);
  9497. memset(UpdateFirmwarepayloadData, 0, 300);
  9498. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9499. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9500. ////pthread_join(t, NULL); //
  9501. //pthread_detach(t);
  9502. //sendUpdateFirmwareConfirmation(uuid);
  9503. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9504. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9505. return result;
  9506. }
  9507. void *UpdateFirmwareProcess(void *data)
  9508. {
  9509. pthread_detach(pthread_self());
  9510. mtrace();
  9511. int retriesInt =0, retryIntervalInt=0;
  9512. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9513. int port=0;
  9514. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9515. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9516. //char comfirmstr[20];
  9517. int isSuccess = 0;
  9518. char ftpbuf[200];
  9519. char temp[100];
  9520. char * pch;
  9521. int retriesISNULL=FALSE;
  9522. int retryInterval=FALSE;
  9523. int c = 0;
  9524. //int i = 0;
  9525. char *loc;
  9526. char sstr[300]={ 0 };
  9527. char str[300]={ 0 };
  9528. //char *str = (char*) data; // ? ?輸入資 ?
  9529. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9530. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9531. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9532. //***************location **************/
  9533. loc = strstr(str, "location");
  9534. memset(sstr ,0, sizeof(sstr) );
  9535. c = 0;
  9536. while (loc[3+strlen("location")+c] != '\"')
  9537. {
  9538. sstr[c] = loc[3+strlen("location")+c];
  9539. c++;
  9540. }
  9541. sstr[c] = '\0';
  9542. strcpy(locationstr, sstr);
  9543. //***************retries**************/
  9544. c = 0;
  9545. loc = strstr(str, "retries");
  9546. if(loc == NULL)
  9547. {
  9548. retriesISNULL=TRUE;
  9549. }
  9550. else
  9551. {
  9552. memset(sstr ,0, sizeof(sstr) );
  9553. while (loc[strlen("retries")+2+c] != ',')
  9554. {
  9555. sstr[c] = loc[strlen("retries")+2+c];
  9556. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9557. c++;
  9558. }
  9559. sstr[c] = '\0';
  9560. }
  9561. if(retriesISNULL == FALSE)
  9562. {
  9563. retriesInt = atoi(sstr);
  9564. }
  9565. //***************retrieveDate **************/
  9566. loc = strstr(str, "retrieveDate");
  9567. memset(sstr ,0, sizeof(sstr) );
  9568. c = 0;
  9569. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9570. {
  9571. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9572. c++;
  9573. }
  9574. sstr[c] = '\0';
  9575. strcpy(retrieveDatestr, sstr);
  9576. //***************retryInterval **************/
  9577. c = 0;
  9578. loc = strstr(str, "retryInterval");
  9579. memset(sstr ,0, sizeof(sstr) );
  9580. if(loc == NULL)
  9581. {
  9582. retryInterval=TRUE;
  9583. }
  9584. else
  9585. {
  9586. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9587. {
  9588. sstr[c] = loc[strlen("retryInterval")+2+c];
  9589. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9590. c++;
  9591. }
  9592. sstr[c] = '\0';
  9593. }
  9594. if(retryInterval==FALSE)
  9595. {
  9596. retryIntervalInt = atoi(sstr);
  9597. }
  9598. memset(ftppath, 0, sizeof(ftppath));
  9599. memset(path, 0, sizeof(path));
  9600. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9601. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9602. if(strncmp(locationstr,"http", 4) == 0)
  9603. {
  9604. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9605. protocol, host, path);
  9606. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9607. // protocol, user, password, host, path);
  9608. sprintf(ftppath,"/%s", path);
  9609. //DEBUG_INFO("protocol =%s\n",protocol);
  9610. //DEBUG_INFO("host =%s\n",host);
  9611. //DEBUG_INFO("path =%s\n",path);
  9612. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9613. int ftppathlen=strlen(ftppath);
  9614. int i=1;
  9615. char filenametemp[50];
  9616. while(i < ftppathlen)
  9617. {
  9618. int len=ftppathlen-i;
  9619. if(ftppath[len]== 47) // '/' ascll code: 47
  9620. {
  9621. DEBUG_INFO("compare '/' all right\n");
  9622. break;
  9623. }
  9624. i=i+1;
  9625. }
  9626. memset(filenametemp, 0, sizeof(filenametemp));
  9627. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9628. filenametemp[i+1] = 0;
  9629. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9630. do{
  9631. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9632. sleep(retryIntervalInt);
  9633. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9634. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9635. if(!isSuccess)
  9636. {
  9637. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9638. }
  9639. else
  9640. {
  9641. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9642. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9643. //isUpdateRequest = TRUE;
  9644. }
  9645. }
  9646. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9647. {
  9648. memset(ftpbuf, 0, sizeof(ftpbuf));
  9649. memset(temp, 0, sizeof(temp));
  9650. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9651. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9652. int ftppathlen=strlen(ftpbuf);
  9653. int i=1;
  9654. char filenametemp[50];
  9655. while(i < ftppathlen)
  9656. {
  9657. int len=ftppathlen-i;
  9658. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9659. {
  9660. DEBUG_INFO(" compare '/' all right\n");
  9661. break;
  9662. }
  9663. i=i+1;
  9664. }
  9665. memset(filenametemp, 0, sizeof(filenametemp));
  9666. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9667. filenametemp[i+1] = 0;
  9668. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9669. pch=strchr(temp,'@');
  9670. if(pch==NULL)
  9671. {
  9672. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9673. protocol, host, &port, path);
  9674. strcpy(user,"anonymous");
  9675. strcpy(password,"");
  9676. }
  9677. else
  9678. {
  9679. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9680. protocol, user, password, host, &port, path);
  9681. }
  9682. sscanf(host,"%[^/]%s",host1, path1);
  9683. sprintf(ftppath,"%s", path1);
  9684. //DEBUG_INFO("protocol =%s\n",protocol);
  9685. //DEBUG_INFO("user =%s\n",user);
  9686. //DEBUG_INFO("password =%s\n",password);
  9687. //DEBUG_INFO("host1 =%s\n",host1);
  9688. //DEBUG_INFO("port =%d\n",port);
  9689. //DEBUG_INFO("path1 =%s\n",path1);
  9690. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9691. //ftpFile(host, user, password, port, ftppath, fname);
  9692. //download firmware pthred
  9693. if(port == 0)
  9694. {
  9695. port = 21;
  9696. }
  9697. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9698. do{
  9699. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9700. sleep(retryIntervalInt);
  9701. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9702. if(!isSuccess)
  9703. {
  9704. //BulldogUtil.sleepMs(interval*1000);
  9705. DEBUG_INFO("Update firmware request and download file fail.\n");
  9706. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9707. }
  9708. else
  9709. {
  9710. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9711. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9712. //isUpdateRequest = TRUE;
  9713. }
  9714. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9715. }
  9716. else
  9717. {
  9718. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9719. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9720. }
  9721. pthread_exit(NULL);
  9722. }
  9723. //==========================================
  9724. // Handle server response routine
  9725. //==========================================
  9726. void handleAuthorizeResponse(char *payload, int gun_index)
  9727. {
  9728. mtrace();
  9729. char expiryDatestr[30]={0};
  9730. char parentIdTagstr[20]={0};
  9731. char statusstr[20]={0};
  9732. char expiryDatestrtemp[30]={0};
  9733. char parentIdTagstrtemp[20]={0};
  9734. char IdTagstrtemp[20]={0};
  9735. char statusstrtemp[20]={0};
  9736. int expiryDateISNULL=FALSE;
  9737. int parentIdTagISNULL=FALSE;
  9738. char sstr[160]={0},sstrtemp[160]={0};
  9739. char* filename = AuthorizationCache_JSON;
  9740. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9741. int c = 0;
  9742. char *loc;
  9743. int resultRename=0;
  9744. int responseIdTagInfoAsZero= 0;
  9745. char rmFileCmd[50]={0};
  9746. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9747. strcpy(sstrtemp, stringtrimspace(payload));
  9748. //***********expiryDate*************/
  9749. loc = strstr(sstrtemp, "expiryDate");
  9750. memset(sstr ,0, sizeof(sstr) );
  9751. c = 0;
  9752. if(loc == NULL)
  9753. {
  9754. expiryDateISNULL = TRUE;
  9755. }
  9756. else
  9757. {
  9758. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9759. {
  9760. sstr[c] = loc[3+strlen("expiryDate")+c];
  9761. c++;
  9762. }
  9763. sstr[c] = '\0';
  9764. strcpy(expiryDatestr, sstr);
  9765. }
  9766. //***********parentIdTag*************/
  9767. loc = strstr(sstrtemp, "parentIdTag");
  9768. memset(sstr ,0, sizeof(sstr) );
  9769. c = 0;
  9770. if(loc == NULL)
  9771. {
  9772. parentIdTagISNULL = TRUE;
  9773. }
  9774. else
  9775. {
  9776. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9777. {
  9778. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9779. c++;
  9780. }
  9781. sstr[c] = '\0';
  9782. strcpy(parentIdTagstr, sstr);
  9783. }
  9784. //***********status*************/
  9785. loc = strstr(sstrtemp, "status");
  9786. memset(sstr ,0, sizeof(sstr) );
  9787. c = 0;
  9788. while (loc[3+strlen("status")+c] != '\"')
  9789. {
  9790. sstr[c] = loc[3+strlen("status")+c];
  9791. c++;
  9792. }
  9793. sstr[c] = '\0';
  9794. strcpy(statusstr, sstr);
  9795. if(expiryDateISNULL == FALSE)
  9796. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9797. if(parentIdTagISNULL == FALSE)
  9798. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9799. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9800. //Update idTag information to authorization cache if supproted
  9801. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9802. {
  9803. if((access(filename,F_OK))!=-1)
  9804. {
  9805. printf("AuthorizationCache exist.\n");
  9806. }
  9807. else
  9808. {
  9809. printf("AuthorizationCache not exist\n");
  9810. FILE *log = fopen(filename, "w+");
  9811. if(log == NULL)
  9812. {
  9813. printf("log is NULL\n");
  9814. goto out;
  9815. }
  9816. else
  9817. {
  9818. fclose(log);
  9819. }
  9820. }
  9821. FILE *infile;
  9822. FILE *outfile;
  9823. // open file for writing
  9824. infile = fopen (filename, "r");
  9825. outfile = fopen (tempfile, "w");
  9826. //*检测到文件结束标识返回1,否则返回0。*/
  9827. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9828. int c;
  9829. c = fgetc(infile);
  9830. //DEBUG_INFO("c:%d\n",c);
  9831. rewind(infile);
  9832. if(c == EOF)
  9833. {
  9834. DEBUG_INFO("Orignal File is NULL\n");
  9835. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9836. {
  9837. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9838. }
  9839. else
  9840. {
  9841. strcpy(expiryDatestrtemp, "");
  9842. }
  9843. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9844. {
  9845. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9846. }
  9847. else
  9848. {
  9849. //write Authorize IdTag
  9850. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9851. }
  9852. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9853. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9854. fclose(infile);
  9855. fclose(outfile);
  9856. sprintf(rmFileCmd,"rm -f %s",filename);
  9857. system(rmFileCmd);
  9858. resultRename = rename(tempfile, filename);
  9859. if(resultRename == 0)
  9860. {
  9861. printf("File renamed successfully");
  9862. }
  9863. else
  9864. {
  9865. printf("Error: unable to rename the file");
  9866. }
  9867. }
  9868. else
  9869. {
  9870. char buf[160]={0};
  9871. while (fgets(buf, sizeof(buf), infile) != NULL)
  9872. {
  9873. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9874. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9875. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9876. memset(statusstr, 0, sizeof(statusstrtemp));
  9877. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9878. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9879. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9880. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9881. //------------------IdTag-----------------------
  9882. loc = strstr(buf, "idTag");
  9883. memset(sstr ,0, sizeof(sstr) );
  9884. c = 0;
  9885. while (loc[3+strlen("idTag")+c] != '\"')
  9886. {
  9887. sstr[c] = loc[3+strlen("idTag")+c];
  9888. c++;
  9889. }
  9890. sstr[c] = '\0';
  9891. strcpy(IdTagstrtemp,sstr);
  9892. //*********************expiryDate***************/
  9893. loc = strstr(buf, "expiryDate");
  9894. memset(sstr ,0, sizeof(sstr) );
  9895. c = 0;
  9896. while (loc[3+strlen("expiryDate")+c] != '\"')
  9897. {
  9898. sstr[c] = loc[3+strlen("expiryDate")+c];
  9899. c++;
  9900. }
  9901. sstr[c] = '\0';
  9902. strcpy(expiryDatestr,sstr);
  9903. //*********************parentIdTag***************/
  9904. loc = strstr(buf, "parentIdTag");
  9905. memset(sstr ,0, sizeof(sstr) );
  9906. c = 0;
  9907. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9908. {
  9909. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9910. c++;
  9911. }
  9912. sstr[c] = '\0';
  9913. strcpy(parentIdTagstr,sstr);
  9914. //*********************status***************/
  9915. loc = strstr(buf, "status");
  9916. memset(sstr ,0, sizeof(sstr) );
  9917. c = 0;
  9918. while (loc[3+strlen("status")+c] != '\"')
  9919. {
  9920. sstr[c] = loc[3+strlen("status")+c];
  9921. c++;
  9922. }
  9923. sstr[c] = '\0';
  9924. strcpy(statusstr,sstr);
  9925. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9926. {
  9927. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9928. responseIdTagInfoAsZero = 1;
  9929. }
  9930. else
  9931. {
  9932. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9933. }
  9934. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9935. {
  9936. //modify item
  9937. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9938. {
  9939. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9940. }
  9941. else
  9942. {
  9943. strcpy(expiryDatestrtemp, "");
  9944. }
  9945. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9946. {
  9947. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9948. }
  9949. else
  9950. {
  9951. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9952. }
  9953. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9954. }
  9955. else
  9956. {
  9957. //wrie original item
  9958. strcpy(expiryDatestrtemp, expiryDatestr);
  9959. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9960. strcpy(statusstrtemp, statusstr);
  9961. }
  9962. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9963. }
  9964. fclose(infile);
  9965. fclose(outfile);
  9966. sprintf(rmFileCmd,"rm -f %s",filename);
  9967. system(rmFileCmd);
  9968. resultRename = rename(tempfile, filename);
  9969. if(resultRename == 0)
  9970. {
  9971. DEBUG_INFO("File renamed successfully");
  9972. }
  9973. else
  9974. {
  9975. DEBUG_INFO("Error: unable to rename the file");
  9976. }
  9977. }
  9978. }
  9979. out:
  9980. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9981. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9982. authorizeRetryTimes = 0;
  9983. }
  9984. char * strtrimc( char * s )
  9985. {
  9986. char * p1 = s;
  9987. char * p2 = s;
  9988. while(*p1 != '\0')
  9989. {
  9990. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9991. {
  9992. if(*p1 != ',')
  9993. {
  9994. p1 ++;
  9995. }
  9996. else
  9997. {
  9998. break;
  9999. }
  10000. }
  10001. if(*p1 != ',')
  10002. {
  10003. * p2 ++ = *p1 ++;
  10004. //printf("p2=%s\n",p2);
  10005. }
  10006. else
  10007. {
  10008. break;
  10009. }
  10010. }
  10011. *p2 = '\0';
  10012. return (s);
  10013. }
  10014. void handleBootNotificationResponse(char *payload, int gun_index)
  10015. {
  10016. mtrace();
  10017. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10018. char statusStr[12]={0};
  10019. char currentTimeStr[30]={0};
  10020. char *loc;
  10021. int intervalInt = 0;
  10022. int c = 0;
  10023. //double diff_t;
  10024. struct tm tp;
  10025. char buf[28]={0};
  10026. char timebuf[50]={0};
  10027. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10028. //Filter string space
  10029. strcpy(sstrtemp, stringtrimspace(payload));
  10030. //*** interval ****/
  10031. c = 0;
  10032. loc = strstr(sstrtemp, "interval");
  10033. //printf("loc=%s\n",loc);
  10034. memset(sstr ,0, sizeof(sstr) );
  10035. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10036. {
  10037. sstr[c] = loc[strlen("interval")+2+c];
  10038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10039. c++;
  10040. }
  10041. sstr[c] = '\0';
  10042. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10043. intervalInt = atoi(sstr);
  10044. //***status ****/
  10045. loc = strstr(sstrtemp, "status");
  10046. memset(sstr ,0, sizeof(sstr) );
  10047. c = 0;
  10048. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10049. {
  10050. sstr[c] = loc[3+strlen("status")+c];
  10051. c++;
  10052. }
  10053. sstr[c] = '\0';
  10054. strcpy(statusStr, sstr);
  10055. //***currentTime ****/
  10056. loc = strstr(sstrtemp, "currentTime");
  10057. //printf("loc=%s\n",loc);
  10058. memset(sstr ,0, sizeof(sstr) );
  10059. c = 0;
  10060. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10061. {
  10062. sstr[c] = loc[3+strlen("currentTime")+c];
  10063. c++;
  10064. }
  10065. sstr[c] = '\0';
  10066. strcpy(currentTimeStr, sstr);
  10067. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10068. //HeartBeatWaitTime = BootNotificationInterval;
  10069. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10070. BootNotificationInterval = intervalInt;
  10071. HeartBeatWaitTime = intervalInt;
  10072. clientTime.Heartbeat=time((time_t*)NULL);
  10073. //write back to ShmOCPP16Data->BootNotification
  10074. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10075. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10076. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10077. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10078. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10079. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10080. {
  10081. server_sign = TRUE;
  10082. server_pending =FALSE;
  10083. }
  10084. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10085. {
  10086. server_pending = TRUE;
  10087. }
  10088. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10089. tp.tm_isdst = -1;
  10090. //time_t utc = mktime(&tp);
  10091. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10092. memset(timebuf, 0, sizeof timebuf);
  10093. sprintf(timebuf,"date -s '%s'",buf);
  10094. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10095. system(timebuf);
  10096. //==============================================
  10097. // RTC sync
  10098. //==============================================
  10099. system("/sbin/hwclock -w --systohc");
  10100. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10101. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10102. }
  10103. void handleDataTransferResponse(char *payload, int gun_index)
  10104. {
  10105. char sstr[160]={0};//sstr[200]={ 0 };
  10106. int c = 0;
  10107. char *loc;
  10108. DEBUG_INFO("handleDataTransferResponse ...\n");
  10109. loc = strstr(payload, "status");
  10110. printf("loc=%s\n",loc);
  10111. c = 0;
  10112. while (loc[3+strlen("status")+c] != '\"')
  10113. {
  10114. sstr[c] = loc[3+strlen("status")+c];
  10115. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10116. c++;
  10117. }
  10118. sstr[c] = '\0';
  10119. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10120. }
  10121. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10122. {
  10123. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10124. //struct json_object *obj;
  10125. // obj = json_tokener_parse(payload);
  10126. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10127. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10128. //No fields are defined.
  10129. }
  10130. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10131. {
  10132. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10133. //struct json_object *obj;
  10134. // obj = json_tokener_parse(payload);
  10135. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10136. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10137. //No fields are defined.
  10138. }
  10139. void handleHeartbeatResponse(char *payload, int gun_index)
  10140. {
  10141. mtrace();
  10142. //double diff_t;
  10143. struct tm tp;
  10144. char buf[28]={0};
  10145. char timebuf[50]={0},sstrtemp[100]={0};
  10146. char sstr[30]={ 0 };
  10147. int c = 0;
  10148. char *loc;
  10149. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10150. if(FirstHeartBeat == 0)
  10151. {
  10152. FirstHeartBeat = 1;
  10153. DEBUG_INFO("FirstHeartBeat \n");
  10154. }
  10155. HeartBeatWithNOResponse = 0;
  10156. strcpy(sstrtemp, stringtrimspace(payload));
  10157. c = 0;
  10158. loc = strstr(sstrtemp, "currentTime");
  10159. memset(sstr ,0, sizeof(sstr) );
  10160. while (loc[3+strlen("currentTime")+c] != '\"')
  10161. {
  10162. sstr[c] = loc[3+strlen("currentTime")+c];
  10163. c++;
  10164. }
  10165. sstr[c] = '\0';
  10166. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10167. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10168. tp.tm_isdst = -1;
  10169. //time_t utc = mktime(&tp);
  10170. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10171. memset(timebuf, 0, sizeof timebuf);
  10172. sprintf(timebuf,"date -s '%s'",buf);
  10173. system(timebuf);
  10174. //==============================================
  10175. // RTC sync
  10176. //==============================================
  10177. system("/sbin/hwclock -w --systohc");
  10178. //===============================================
  10179. //Print Out HeartBeat log
  10180. //===============================================
  10181. {
  10182. double diff_t;
  10183. struct tm tp,tp1;
  10184. // BootNotification Receive Time
  10185. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10186. tp.tm_isdst = -1;
  10187. time_t BootNotificationReceiveTime = mktime(&tp);
  10188. //HeartBeat Receive Time
  10189. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10190. tp1.tm_isdst = -1;
  10191. time_t HeartBeatReceiveTime = mktime(&tp1);
  10192. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10193. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10194. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10195. {
  10196. HeartBeatCountPerHour = (int)diff_t / 3600;
  10197. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10198. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10199. }
  10200. }
  10201. }
  10202. void handleMeterValuesResponse(char *payload, int gun_index)
  10203. {
  10204. mtrace();
  10205. //struct json_object *obj;
  10206. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10207. //No fields are defined.
  10208. }
  10209. void handleStartTransactionResponse(char *payload, int gun_index)
  10210. {
  10211. mtrace();
  10212. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10213. int c = 0;
  10214. int copyTo = 0;
  10215. char *loc;
  10216. //int transactionIdInt = 0;
  10217. FILE *outfile;
  10218. char data[100]={0};
  10219. //char *delim = ":";
  10220. //char requestKey[2][50]={0};
  10221. //char * pch;
  10222. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10223. DEBUG_INFO("handleStartTransactionResponse\n");
  10224. //****************expiryDate********************/
  10225. strcpy(sstrtemp, stringtrimspace(payload));
  10226. loc = strstr(sstrtemp, "expiryDate");
  10227. if(loc == NULL)
  10228. {
  10229. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10230. }
  10231. else
  10232. {
  10233. #if 0
  10234. c = 0;
  10235. memset(sstr ,0, sizeof(sstr) );
  10236. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10237. memset(requestKey ,0, sizeof(requestKey) );
  10238. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10239. //printf("sstrtemp=%s\n",sstrtemp);
  10240. //parsing strings to words
  10241. pch = strtok(sstrtemp,",");
  10242. while (pch != NULL)
  10243. {
  10244. strcpy(requestKey[c], pch);
  10245. pch = strtok (NULL, ",");
  10246. c = c + 1;
  10247. }
  10248. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10249. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10250. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10251. #endif
  10252. #if 1
  10253. c = 0;
  10254. memset(sstr ,0, sizeof(sstr) );
  10255. while (loc[3+strlen("expiryDate")+c] != '\"')
  10256. {
  10257. sstr[c] = loc[3+strlen("expiryDate")+c];
  10258. c++;
  10259. }
  10260. sstr[c] = '\0';
  10261. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10262. #endif
  10263. }
  10264. //****************parentIdTag********************/
  10265. loc = strstr(sstrtemp, "parentIdTag");
  10266. if(loc == NULL)
  10267. {
  10268. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10269. }
  10270. else
  10271. {
  10272. #if 0
  10273. c = 0;
  10274. memset(sstr ,0, sizeof(sstr) );
  10275. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10276. memset(requestKey ,0, sizeof(requestKey) );
  10277. strcpy(sstrtemp,loc);
  10278. //printf("sstrtemp=%s\n",sstrtemp);
  10279. //parsing strings to words
  10280. pch = strtok(sstrtemp,delim);
  10281. while (pch != NULL)
  10282. {
  10283. strcpy(requestKey[c], pch);
  10284. pch = strtok (NULL, delim);
  10285. c = c + 1;
  10286. }
  10287. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10288. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10289. #endif
  10290. #if 1
  10291. c = 0;
  10292. memset(sstr ,0, sizeof(sstr) );
  10293. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10294. {
  10295. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10296. c++;
  10297. }
  10298. sstr[c] = '\0';
  10299. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10300. #endif
  10301. }
  10302. //****************status********************/
  10303. loc = strstr(sstrtemp, "status");
  10304. if(loc == NULL)
  10305. {
  10306. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10307. }
  10308. else
  10309. {
  10310. #if 0
  10311. c = 0;
  10312. memset(sstr ,0, sizeof(sstr) );
  10313. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10314. memset(requestKey ,0, sizeof(requestKey) );
  10315. strcpy(sstrtemp,loc);
  10316. //printf("sstrtemp=%s\n",sstrtemp);
  10317. //parsing strings to words
  10318. pch = strtok(sstrtemp,delim);
  10319. while (pch != NULL)
  10320. {
  10321. strcpy(requestKey[c], pch);
  10322. pch = strtok (NULL, delim);
  10323. c = c + 1;
  10324. }
  10325. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10326. //strcpy(statusStr, strtrimc(requestKey[1]));
  10327. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10328. #endif
  10329. #if 1
  10330. c = 0;
  10331. memset(sstr ,0, sizeof(sstr) );
  10332. while (loc[3+strlen("status")+c] != '\"')
  10333. {
  10334. sstr[c] = loc[3+strlen("status")+c];
  10335. c++;
  10336. }
  10337. sstr[c] = '\0';
  10338. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10339. #endif
  10340. }
  10341. //****************transactionId********************/
  10342. c=0;
  10343. copyTo = 0;
  10344. loc = strstr(sstrtemp, "transactionId");
  10345. memset(sstr ,0, sizeof(sstr) );
  10346. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10347. {
  10348. if(loc[strlen("transactionId")+2+c] != ' ')
  10349. {
  10350. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10351. copyTo = copyTo + 1;
  10352. }
  10353. c++;
  10354. }
  10355. sstr[copyTo] = '\0';
  10356. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10357. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10358. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10359. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10360. //-----------Start : write to the Queue TransactionId file -----------------//
  10361. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10362. {
  10363. //DEBUG_INFO("QueueTransactionId exist.\n");
  10364. }
  10365. else
  10366. {
  10367. //DEBUG_INFO("QueueTransactionId not exist\n");
  10368. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10369. if(log == NULL)
  10370. {
  10371. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10372. return ;
  10373. }
  10374. else
  10375. {
  10376. fclose(log);
  10377. }
  10378. }
  10379. // open file for writing
  10380. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10381. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10382. {
  10383. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10384. //DEBUG_INFO("data=%s\n",data);
  10385. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10386. fputs(data, outfile);
  10387. //fputs("\n", outfile);
  10388. fclose (outfile);
  10389. }
  10390. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10391. //TransactionId[gun_index] = transactionIdInt;
  10392. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10393. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10394. #ifdef SystemLogMessage
  10395. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10396. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10397. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10398. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10399. #endif
  10400. }
  10401. void handleStatusNotificationResponse(char *payload, int gun_index)
  10402. {
  10403. mtrace();
  10404. printf("handleStatusNotificationResponse\n");
  10405. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10406. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10407. }
  10408. void handleStopTransactionnResponse(char *payload, int gun_index)
  10409. {
  10410. mtrace();
  10411. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10412. int c = 0;
  10413. char *loc;
  10414. //char *delim = ":";
  10415. //char requestKey[3][50]={0};
  10416. //char * pch;
  10417. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10418. strcpy(sstrtemp, stringtrimspace(payload));
  10419. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10420. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10421. loc = strstr(sstrtemp, "idTagInfo");
  10422. //***********************idTagInfo************************/
  10423. if(loc != NULL)
  10424. {
  10425. //***********************expiryDate************************/
  10426. loc = strstr(sstrtemp, "expiryDate");
  10427. if(loc != NULL)
  10428. {
  10429. memset(sstr ,0, sizeof(sstr) );
  10430. c = 0;
  10431. while (loc[3+strlen("expiryDate")+c] != '\"')
  10432. {
  10433. sstr[c] = loc[3+strlen("expiryDate")+c];
  10434. c++;
  10435. }
  10436. sstr[c] = '\0';
  10437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10438. }
  10439. //***********************parentIdTag************************/
  10440. loc = strstr(sstrtemp, "parentIdTag");
  10441. if(loc != NULL)
  10442. {
  10443. memset(sstr ,0, sizeof(sstr) );
  10444. c = 0;
  10445. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10446. {
  10447. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10448. c++;
  10449. }
  10450. sstr[c] = '\0';
  10451. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10452. }
  10453. //***********************status************************/
  10454. loc = strstr(sstrtemp, "status");
  10455. memset(sstr ,0, sizeof(sstr) );
  10456. c = 0;
  10457. while (loc[3+strlen("status")+c] != '\"')
  10458. {
  10459. sstr[c] = loc[3+strlen("status")+c];
  10460. c++;
  10461. }
  10462. sstr[c] = '\0';
  10463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10464. }
  10465. #ifdef SystemLogMessage
  10466. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10467. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10468. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10469. #endif
  10470. }
  10471. //==========================================
  10472. // Handle Error routine
  10473. //==========================================
  10474. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10475. {
  10476. mtrace();
  10477. #ifdef SystemLogMessage
  10478. DEBUG_INFO("errorCode: %s\n", errorCode);
  10479. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10480. DEBUG_INFO("errorDetails: %s\n", payload);
  10481. #endif
  10482. }
  10483. //===============================================
  10484. // Common routine
  10485. //===============================================
  10486. int initialConfigurationTable(void)
  10487. {
  10488. //clock_t start_t, end_t, total_t;
  10489. FILE *fp;
  10490. FILE *outfile;
  10491. char str[200]={0};
  10492. char sstr[100]={0};
  10493. int c = 0;
  10494. char *loc;
  10495. printf("initialConfigurationTable \n");
  10496. //start_t = clock();
  10497. //printf("Starting of the program, start_t = %ld\n", start_t);
  10498. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10499. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10500. {
  10501. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10502. if(outfile == NULL) {
  10503. DEBUG_INFO("Error opening file");
  10504. return FALSE;
  10505. }
  10506. /*Core Profile*/
  10507. //AllowOfflineTxForUnknownId
  10508. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10509. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10510. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10512. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10513. //AuthorizationCacheEnabled
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10515. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10516. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10517. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10518. //AuthorizeRemoteTxRequests
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10523. //BlinkRepeat
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10527. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10528. //ClockAlignedDataInterval
  10529. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10530. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10531. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10532. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10533. //ConnectionTimeOut
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10536. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10538. //GetConfigurationMaxKeys
  10539. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10543. // HeartbeatInterval
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10545. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10547. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10548. // LightIntensity
  10549. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10550. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10551. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10552. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10553. // LocalAuthorizeOffline
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10557. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10558. // LocalPreAuthorize
  10559. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10560. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10561. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10562. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10563. // MaxEnergyOnInvalidId
  10564. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10565. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10566. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10567. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10568. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10569. // MeterValuesAlignedData
  10570. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10571. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10572. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10573. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10574. // MeterValuesAlignedDataMaxLength
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10578. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10579. // MeterValuesSampledData
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10583. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10584. // MeterValuesSampledDataMaxLength
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10586. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10587. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10588. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "5");
  10589. // MeterValueSampleInterval
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10592. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10594. // MinimumStatusDuration
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10598. server_cycle_Status = 120; //StatusNotification cycle
  10599. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10600. // NumberOfConnectors
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10603. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10604. {
  10605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10606. }
  10607. else
  10608. {
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10610. }
  10611. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10612. // ResetRetries
  10613. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10614. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10615. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10616. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10617. // ConnectorPhaseRotation
  10618. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10620. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10622. // ConnectorPhaseRotationMaxLength
  10623. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10627. // StopTransactionOnEVSideDisconnect
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10629. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10631. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10632. // StopTransactionOnInvalidId
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10636. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10637. // StopTxnAlignedData
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10641. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10642. // StopTxnAlignedDataMaxLength
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10647. // StopTxnSampledData
  10648. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC");
  10652. // StopTxnSampledDataMaxLength
  10653. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10655. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10656. {
  10657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10658. }
  10659. else
  10660. {
  10661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10662. }
  10663. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10665. // SupportedFeatureProfiles
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10669. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10670. // SupportedFeatureProfilesMaxLength
  10671. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10675. // TransactionMessageAttempts
  10676. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10679. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10680. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10681. // TransactionMessageRetryInterval
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10685. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10687. // UnlockConnectorOnEVSideDisconnect
  10688. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10692. // WebSocketPingInterval
  10693. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10696. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10697. //* Local Auth List Management Profile*/
  10698. #if 0
  10699. //For OCTT Test Case
  10700. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10703. #endif
  10704. #if 1
  10705. //LocalAuthListEnabled
  10706. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10708. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10710. #endif
  10711. //LocalAuthListMaxLength
  10712. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10716. //SendLocalListMaxLength
  10717. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10720. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10721. //ReserveConnectorZeroSupported
  10722. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10725. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10726. //* Smart Charging Profile */
  10727. //ChargeProfileMaxStackLevel
  10728. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10732. // ChargingScheduleAllowedChargingRateUnit
  10733. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10737. // ChargingScheduleMaxPeriods
  10738. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10742. // ConnectorSwitch3to1PhaseSupported
  10743. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10747. // MaxChargingProfilesInstalled
  10748. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10752. fclose(outfile);
  10753. }
  10754. else
  10755. {
  10756. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10757. char keystr[60]={0};
  10758. char readonlystr[10]={0};
  10759. char valuestr[100]={0};
  10760. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10761. if(fp == NULL) {
  10762. DEBUG_INFO("Error opening file");
  10763. return FALSE;
  10764. }
  10765. while( fgets (str, sizeof(str), fp)!=NULL )
  10766. {
  10767. //DEBUG_INFO("Get Configuration \n");
  10768. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10769. //*************************key*********************************/
  10770. loc = strstr(str, "key");
  10771. c = 0;
  10772. memset(sstr ,0, sizeof(sstr) );
  10773. while (loc[strlen("key")+3+c] != '\"')
  10774. {
  10775. sstr[c] = loc[strlen("key")+3+c];
  10776. c++;
  10777. }
  10778. sstr[c] = '\0';
  10779. strcpy(keystr,sstr);
  10780. //*************************readonly*********************************/
  10781. loc = strstr(str, "readonly");
  10782. c = 0;
  10783. memset(sstr ,0, sizeof(sstr) );
  10784. while (loc[strlen("readonly")+2+c] != ',')
  10785. {
  10786. sstr[c] = loc[strlen("readonly")+2+c];
  10787. c++;
  10788. }
  10789. sstr[c] = '\0';
  10790. strcpy(readonlystr,sstr);
  10791. //*************************value*********************************/
  10792. loc = strstr(str, "value");
  10793. c = 0;
  10794. memset(sstr ,0, sizeof(sstr) );
  10795. while (loc[strlen("value")+3+c] != '\"')
  10796. {
  10797. sstr[c] = loc[strlen("value")+3+c];
  10798. c++;
  10799. }
  10800. sstr[c] = '\0';
  10801. strcpy(valuestr,sstr);
  10802. // DEBUG_INFO("keystr=%s\n",keystr);
  10803. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10804. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10805. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10806. {
  10807. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10808. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10809. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10810. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10811. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10812. }
  10813. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10814. {
  10815. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10818. }
  10819. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10820. {
  10821. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10823. }
  10824. if(strcmp(keystr, "BlinkRepeat") == 0)
  10825. {
  10826. //Charger.BlinkRepeat = Integer.parseInt(value);
  10827. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10828. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10829. }
  10830. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10831. {
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10834. }
  10835. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10836. {
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10839. }
  10840. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10841. {
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10843. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10844. }
  10845. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10846. {
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10849. HeartBeatWaitTime = atoi(valuestr);
  10850. }
  10851. if(strcmp(keystr, "LightIntensity") == 0)
  10852. {
  10853. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10854. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10855. }
  10856. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10857. {
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10859. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10860. }
  10861. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10862. {
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10865. }
  10866. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10867. {
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10870. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10871. }
  10872. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10873. {
  10874. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10875. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10876. }
  10877. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10878. {
  10879. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10881. }
  10882. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10883. {
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10885. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10886. }
  10887. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10888. {
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10891. }
  10892. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10893. {
  10894. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10895. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10896. }
  10897. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10898. {
  10899. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10901. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10902. }
  10903. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10904. {
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10906. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10907. }
  10908. if(strcmp(keystr, "ResetRetries") == 0)
  10909. {
  10910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10911. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10912. }
  10913. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10914. {
  10915. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10916. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10917. }
  10918. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10919. {
  10920. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10921. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10922. }
  10923. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10924. {
  10925. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10926. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10927. }
  10928. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10929. {
  10930. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10931. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10932. }
  10933. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10934. {
  10935. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10936. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10937. }
  10938. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10939. {
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10942. }
  10943. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10944. {
  10945. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10946. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10947. }
  10948. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10949. {
  10950. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10951. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10952. }
  10953. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10954. {
  10955. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10956. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10957. }
  10958. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10959. {
  10960. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10962. }
  10963. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10964. {
  10965. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10966. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10967. TransactionMessageAttemptsValue = atoi(valuestr);
  10968. }
  10969. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10970. {
  10971. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10972. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10973. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10974. }
  10975. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10976. {
  10977. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10978. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10979. }
  10980. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10981. {
  10982. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10984. }
  10985. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10986. {
  10987. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10989. }
  10990. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10991. {
  10992. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10994. }
  10995. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10996. {
  10997. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10998. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10999. }
  11000. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11001. {
  11002. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11004. }
  11005. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11006. {
  11007. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11009. }
  11010. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11011. {
  11012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11014. }
  11015. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11016. {
  11017. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11019. }
  11020. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11021. {
  11022. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11024. }
  11025. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11026. {
  11027. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11029. }
  11030. }
  11031. fclose(fp);
  11032. }
  11033. //end_t = clock();
  11034. //printf("End of the big loop, end_t = %ld\n", end_t);
  11035. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11036. //printf("Total time taken by CPU: %f\n", total_t );
  11037. return 0;
  11038. }
  11039. void StoreConfigurationTable(void)
  11040. {
  11041. FILE *outfile;
  11042. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11043. if(outfile == NULL)
  11044. {
  11045. DEBUG_INFO("Error opening file");
  11046. return ;
  11047. }
  11048. /*Core Profile*/
  11049. //AllowOfflineTxForUnknownId
  11050. /*
  11051. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11052. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11055. */
  11056. //DEBUG_INFO("data=%s\n",data);
  11057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11058. //AuthorizationCacheEnabled
  11059. /*
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11063. */
  11064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11065. //AuthorizeRemoteTxRequests
  11066. /*
  11067. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11068. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11069. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11070. */
  11071. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11072. //BlinkRepeat
  11073. /*
  11074. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11076. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11077. */
  11078. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11079. //ClockAlignedDataInterval
  11080. /*
  11081. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11082. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11084. */
  11085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11086. //ConnectionTimeOut
  11087. /*
  11088. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11091. */
  11092. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11093. //GetConfigurationMaxKeys
  11094. /*
  11095. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11098. */
  11099. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11100. // HeartbeatInterval
  11101. /*
  11102. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11103. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11105. */
  11106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11107. // LightIntensity
  11108. /*
  11109. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11112. */
  11113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11114. // LocalAuthorizeOffline
  11115. /*
  11116. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11118. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11119. */
  11120. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11121. // LocalPreAuthorize
  11122. /*
  11123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11126. */
  11127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11128. // MaxEnergyOnInvalidId
  11129. /*
  11130. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11133. */
  11134. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11135. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11136. // MeterValuesAlignedData
  11137. /*
  11138. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11141. */
  11142. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11143. // MeterValuesAlignedDataMaxLength
  11144. /*
  11145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11148. */
  11149. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11150. // MeterValuesSampledData
  11151. /*
  11152. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11154. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11155. */
  11156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11157. // MeterValuesSampledDataMaxLength
  11158. /*
  11159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11162. */
  11163. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11164. // MeterValueSampleInterval
  11165. /*
  11166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11169. */
  11170. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11171. // MinimumStatusDuration
  11172. /*
  11173. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11174. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11176. */
  11177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11178. // NumberOfConnectors
  11179. /*
  11180. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11182. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11183. {
  11184. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11185. }
  11186. else
  11187. {
  11188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11189. }
  11190. */
  11191. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11192. // ResetRetries
  11193. /*
  11194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11197. */
  11198. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11199. // ConnectorPhaseRotation
  11200. /*
  11201. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11204. */
  11205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11206. // ConnectorPhaseRotationMaxLength
  11207. /*
  11208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11211. */
  11212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11213. // StopTransactionOnEVSideDisconnect
  11214. /*
  11215. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11218. */
  11219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11220. // StopTransactionOnInvalidId
  11221. /*
  11222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11225. */
  11226. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11227. // StopTxnAlignedData
  11228. /*
  11229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11232. */
  11233. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11234. // StopTxnAlignedDataMaxLength
  11235. /*
  11236. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11237. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11239. */
  11240. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11241. // StopTxnSampledData
  11242. /*
  11243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11246. */
  11247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11248. // StopTxnSampledDataMaxLength
  11249. /*
  11250. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11253. */
  11254. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11255. // SupportedFeatureProfiles
  11256. /*
  11257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11260. */
  11261. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11262. // SupportedFeatureProfilesMaxLength
  11263. /*
  11264. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11266. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11267. */
  11268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11269. // TransactionMessageAttempts
  11270. /*
  11271. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11274. */
  11275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11276. // TransactionMessageRetryInterval
  11277. /*
  11278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11281. */
  11282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11283. // UnlockConnectorOnEVSideDisconnect
  11284. /*
  11285. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11288. */
  11289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11290. // WebSocketPingInterval
  11291. /*
  11292. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11295. */
  11296. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11297. //* Local Auth List Management Profile*/
  11298. //LocalAuthListEnabled
  11299. /*
  11300. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11303. */
  11304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11305. //LocalAuthListMaxLength
  11306. /*
  11307. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11310. */
  11311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11312. //SendLocalListMaxLength
  11313. /*
  11314. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11317. */
  11318. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11319. //ReserveConnectorZeroSupported
  11320. /*
  11321. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11324. */
  11325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11326. //* Smart Charging Profile */
  11327. //ChargeProfileMaxStackLevel
  11328. /*
  11329. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11332. */
  11333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11334. // ChargingScheduleAllowedChargingRateUnit
  11335. /*
  11336. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11339. */
  11340. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11341. // ChargingScheduleMaxPeriods
  11342. /*
  11343. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11344. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11345. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11346. */
  11347. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11348. // ConnectorSwitch3to1PhaseSupported
  11349. /*
  11350. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11353. */
  11354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11355. // MaxChargingProfilesInstalled
  11356. /*
  11357. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11360. */
  11361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11362. fclose(outfile);
  11363. }
  11364. void getKeyValue(char *keyReq)
  11365. {
  11366. int isEmpty = FALSE;
  11367. int isKnowKey = FALSE;
  11368. //int unKnowIndex = 0;
  11369. DEBUG_INFO("getKeyValue \n");
  11370. DEBUG_INFO("keyReq=%s \n",keyReq);
  11371. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11372. isEmpty = TRUE;
  11373. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11374. {
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11377. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11378. {
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11380. }
  11381. else
  11382. {
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11384. }
  11385. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11386. isKnowKey = TRUE;
  11387. }
  11388. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11389. {
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11393. {
  11394. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11395. }
  11396. else
  11397. {
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11399. }
  11400. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11401. isKnowKey = TRUE;
  11402. }
  11403. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11404. {
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11407. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11408. {
  11409. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11410. }
  11411. else
  11412. {
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11414. }
  11415. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11416. isKnowKey = TRUE;
  11417. }
  11418. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11422. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11429. }
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11431. isKnowKey = TRUE;
  11432. }
  11433. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11434. {
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11438. {
  11439. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11440. }
  11441. else
  11442. {
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11444. }
  11445. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11446. isKnowKey = TRUE;
  11447. }
  11448. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11449. {
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11452. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11453. {
  11454. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11455. }
  11456. else
  11457. {
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11459. }
  11460. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11461. isKnowKey = TRUE;
  11462. }
  11463. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11467. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11476. isKnowKey = TRUE;
  11477. }
  11478. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11479. {
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11482. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11483. {
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11485. }
  11486. else
  11487. {
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11489. }
  11490. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11491. isKnowKey = TRUE;
  11492. }
  11493. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11494. {
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11497. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11498. {
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11500. }
  11501. else
  11502. {
  11503. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11504. }
  11505. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11506. isKnowKey = TRUE;
  11507. }
  11508. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11509. {
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11513. {
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11515. }
  11516. else
  11517. {
  11518. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11519. }
  11520. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11521. isKnowKey = TRUE;
  11522. }
  11523. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11524. {
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11527. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11528. {
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11530. }
  11531. else
  11532. {
  11533. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11534. }
  11535. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11536. isKnowKey = TRUE;
  11537. }
  11538. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11539. {
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11543. {
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11545. }
  11546. else
  11547. {
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11549. }
  11550. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11551. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11552. isKnowKey = TRUE;
  11553. }
  11554. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11558. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11567. isKnowKey = TRUE;
  11568. }
  11569. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11580. }
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11582. isKnowKey = TRUE;
  11583. }
  11584. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11588. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11591. }
  11592. else
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11595. }
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11597. isKnowKey = TRUE;
  11598. }
  11599. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11600. {
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11602. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11603. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11606. }
  11607. else
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11610. }
  11611. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11612. isKnowKey = TRUE;
  11613. }
  11614. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11615. {
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11617. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11618. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11621. }
  11622. else
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11625. }
  11626. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11627. isKnowKey = TRUE;
  11628. }
  11629. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11630. {
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11632. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11636. }
  11637. else
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11640. }
  11641. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11642. isKnowKey = TRUE;
  11643. }
  11644. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11645. {
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11647. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11651. }
  11652. else
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11655. }
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11657. isKnowKey = TRUE;
  11658. }
  11659. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11660. {
  11661. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11663. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11666. }
  11667. else
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11670. }
  11671. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11672. isKnowKey = TRUE;
  11673. }
  11674. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11677. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11678. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11679. {
  11680. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11681. }
  11682. else
  11683. {
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11685. }
  11686. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11687. isKnowKey = TRUE;
  11688. }
  11689. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11692. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11693. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11694. {
  11695. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11696. }
  11697. else
  11698. {
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11700. }
  11701. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11702. isKnowKey = TRUE;
  11703. }
  11704. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11707. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11708. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11709. {
  11710. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11711. }
  11712. else
  11713. {
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11715. }
  11716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11717. isKnowKey = TRUE;
  11718. }
  11719. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11723. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11724. {
  11725. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11726. }
  11727. else
  11728. {
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11730. }
  11731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11732. isKnowKey = TRUE;
  11733. }
  11734. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11738. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11739. {
  11740. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11741. }
  11742. else
  11743. {
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11745. }
  11746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11747. isKnowKey = TRUE;
  11748. }
  11749. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11754. {
  11755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11756. }
  11757. else
  11758. {
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11760. }
  11761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11762. isKnowKey = TRUE;
  11763. }
  11764. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11768. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11769. {
  11770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11771. }
  11772. else
  11773. {
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11775. }
  11776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11777. isKnowKey = TRUE;
  11778. }
  11779. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11783. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11784. {
  11785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11786. }
  11787. else
  11788. {
  11789. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11790. }
  11791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11792. isKnowKey = TRUE;
  11793. }
  11794. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11795. {
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11799. {
  11800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11801. }
  11802. else
  11803. {
  11804. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11805. }
  11806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11807. isKnowKey = TRUE;
  11808. }
  11809. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11810. {
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11813. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11814. {
  11815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11816. }
  11817. else
  11818. {
  11819. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11820. }
  11821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11822. isKnowKey = TRUE;
  11823. }
  11824. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11825. {
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11828. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11829. {
  11830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11831. }
  11832. else
  11833. {
  11834. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11835. }
  11836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11837. isKnowKey = TRUE;
  11838. }
  11839. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11840. {
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11844. {
  11845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11846. }
  11847. else
  11848. {
  11849. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11850. }
  11851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11852. isKnowKey = TRUE;
  11853. }
  11854. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11855. {
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11858. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11859. {
  11860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11861. }
  11862. else
  11863. {
  11864. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11865. }
  11866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11867. isKnowKey = TRUE;
  11868. }
  11869. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11870. {
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11873. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11874. {
  11875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11876. }
  11877. else
  11878. {
  11879. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11880. }
  11881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11882. isKnowKey = TRUE;
  11883. }
  11884. #if 0
  11885. //For OCTT Test Case
  11886. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  11887. {
  11888. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  11889. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  11890. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11891. {
  11892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11893. }
  11894. else
  11895. {
  11896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11897. }
  11898. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11899. isKnowKey = TRUE;
  11900. }
  11901. #endif
  11902. #if 1
  11903. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11904. {
  11905. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11906. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11907. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11908. {
  11909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11910. }
  11911. else
  11912. {
  11913. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11914. }
  11915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11916. isKnowKey = TRUE;
  11917. }
  11918. #endif
  11919. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11920. {
  11921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11923. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11924. {
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11926. }
  11927. else
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11930. }
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11932. isKnowKey = TRUE;
  11933. }
  11934. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11935. {
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11938. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11939. {
  11940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11941. }
  11942. else
  11943. {
  11944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11945. }
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11947. isKnowKey = TRUE;
  11948. }
  11949. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11950. {
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11953. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11954. {
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11956. }
  11957. else
  11958. {
  11959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11960. }
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11962. isKnowKey = TRUE;
  11963. }
  11964. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11965. {
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11968. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11969. {
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11971. }
  11972. else
  11973. {
  11974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11975. }
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11977. isKnowKey = TRUE;
  11978. }
  11979. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11980. {
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11983. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11984. {
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11986. }
  11987. else
  11988. {
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11990. }
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11992. isKnowKey = TRUE;
  11993. }
  11994. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11998. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11999. {
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12001. }
  12002. else
  12003. {
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12005. }
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12007. isKnowKey = TRUE;
  12008. }
  12009. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12010. {
  12011. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12012. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12013. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12014. {
  12015. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12016. }
  12017. else
  12018. {
  12019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12020. }
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12022. isKnowKey = TRUE;
  12023. }
  12024. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12025. {
  12026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12028. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12029. {
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12031. }
  12032. else
  12033. {
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12035. }
  12036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12037. isKnowKey = TRUE;
  12038. }
  12039. //=========================================================
  12040. if(!isEmpty && !isKnowKey)
  12041. {
  12042. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12043. strcpy(unknownkey[UnknownKeynum], keyReq);
  12044. UnknownKeynum = UnknownKeynum + 1;
  12045. }
  12046. }
  12047. void processUnkownKey(void)
  12048. {
  12049. DEBUG_INFO("processUnkownKey\n");
  12050. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12051. for(int index=0; index < UnknownKeynum; index++)
  12052. {
  12053. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12054. {
  12055. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12056. }
  12057. }
  12058. }
  12059. int setKeyValue(char *key, char *value)
  12060. {
  12061. int isSuccess = NotSupported;
  12062. int check_ascii=0;
  12063. char str[10]={0};
  12064. #ifdef Debug
  12065. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12066. #endif
  12067. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12068. {
  12069. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12070. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12071. {
  12072. strcpy(str, (const char*)value);
  12073. for(int i = 0; str[i]; i++){
  12074. str[i] = tolower(str[i]);
  12075. }
  12076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12077. isSuccess = ConfigurationStatus_Accepted;
  12078. }
  12079. else
  12080. {
  12081. isSuccess = ConfigurationStatus_Rejected;
  12082. }
  12083. }
  12084. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12085. {
  12086. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12088. {
  12089. strcpy(str, (const char*)value);
  12090. for(int i = 0; str[i]; i++){
  12091. str[i] = tolower(str[i]);
  12092. }
  12093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12094. isSuccess = ConfigurationStatus_Accepted;
  12095. //updateSetting("AuthorizationCacheEnabled", (Charger.AuthorizationCacheEnabled?"1":"0"));
  12096. updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12104. {
  12105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12106. {
  12107. strcpy(str, (const char*)value);
  12108. for(int i = 0; str[i]; i++)
  12109. {
  12110. str[i] = tolower(str[i]);
  12111. }
  12112. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12114. isSuccess = ConfigurationStatus_Accepted;
  12115. }
  12116. else
  12117. {
  12118. isSuccess = ConfigurationStatus_Rejected;
  12119. }
  12120. }
  12121. if(strcmp(key, "BlinkRepeat") == 0)
  12122. {
  12123. //Charger.BlinkRepeat = Integer.parseInt(value);
  12124. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12125. {
  12126. check_ascii = value[0];
  12127. if( (check_ascii < 48) || (check_ascii > 57) )
  12128. {
  12129. isSuccess = ConfigurationStatus_Rejected;
  12130. }
  12131. else
  12132. {
  12133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12134. isSuccess = ConfigurationStatus_Accepted;
  12135. }
  12136. }
  12137. else
  12138. {
  12139. isSuccess = ConfigurationStatus_Rejected;
  12140. }
  12141. }
  12142. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12143. {
  12144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12145. {
  12146. check_ascii = value[0];
  12147. if( (check_ascii < 48) || (check_ascii > 57) )
  12148. {
  12149. isSuccess = ConfigurationStatus_Rejected;
  12150. }
  12151. else
  12152. {
  12153. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12154. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12155. isSuccess = ConfigurationStatus_Accepted;
  12156. }
  12157. }
  12158. else
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. }
  12163. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12164. {
  12165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12166. {
  12167. check_ascii = value[0];
  12168. if( (check_ascii < 48) || (check_ascii > 57) )
  12169. {
  12170. isSuccess = ConfigurationStatus_Rejected;
  12171. }
  12172. else
  12173. {
  12174. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. }
  12179. else
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. }
  12184. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12185. {
  12186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12187. {
  12188. check_ascii = value[0];
  12189. if( (check_ascii < 48) || (check_ascii > 57) )
  12190. {
  12191. isSuccess = ConfigurationStatus_Rejected;
  12192. }
  12193. else
  12194. {
  12195. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12196. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12197. isSuccess = ConfigurationStatus_Accepted;
  12198. }
  12199. }
  12200. else
  12201. {
  12202. isSuccess = ConfigurationStatus_Rejected;
  12203. }
  12204. }
  12205. if(strcmp(key, "HeartbeatInterval") == 0)
  12206. {
  12207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12208. {
  12209. check_ascii = value[0];
  12210. if( (check_ascii < 48) || (check_ascii > 57) )
  12211. {
  12212. isSuccess = ConfigurationStatus_Rejected;
  12213. }
  12214. else
  12215. {
  12216. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12218. HeartBeatWaitTime = atoi(value);
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. }
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "LightIntensity") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12230. {
  12231. check_ascii = value[0];
  12232. if( (check_ascii < 48) || (check_ascii > 57) )
  12233. {
  12234. isSuccess = ConfigurationStatus_Rejected;
  12235. }
  12236. else
  12237. {
  12238. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12250. {
  12251. strcpy(str, (const char*)value);
  12252. for(int i = 0; str[i]; i++)
  12253. {
  12254. str[i] = tolower(str[i]);
  12255. }
  12256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12257. isSuccess = ConfigurationStatus_Accepted;
  12258. updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12259. }
  12260. else
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. }
  12265. if(strcmp(key, "LocalPreAuthorize") == 0)
  12266. {
  12267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12268. {
  12269. strcpy(str, (const char*)value);
  12270. for(int i = 0; str[i]; i++)
  12271. {
  12272. str[i] = tolower(str[i]);
  12273. }
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12275. isSuccess = ConfigurationStatus_Accepted;
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12285. {
  12286. check_ascii = value[0];
  12287. if( (check_ascii < 48) || (check_ascii > 57) )
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. else
  12292. {
  12293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12294. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12306. {
  12307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12308. isSuccess = ConfigurationStatus_Accepted;
  12309. }
  12310. else
  12311. {
  12312. isSuccess = ConfigurationStatus_Rejected;
  12313. }
  12314. }
  12315. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12316. {
  12317. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12318. {
  12319. check_ascii = value[0];
  12320. if( (check_ascii < 48) || (check_ascii > 57) )
  12321. {
  12322. isSuccess = ConfigurationStatus_Rejected;
  12323. }
  12324. else
  12325. {
  12326. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12328. isSuccess = ConfigurationStatus_Accepted;
  12329. }
  12330. }
  12331. else
  12332. {
  12333. isSuccess = ConfigurationStatus_Rejected;
  12334. }
  12335. }
  12336. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12337. {
  12338. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12339. {
  12340. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12341. isSuccess = ConfigurationStatus_Accepted;
  12342. }
  12343. else
  12344. {
  12345. isSuccess = ConfigurationStatus_Rejected;
  12346. }
  12347. }
  12348. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12349. {
  12350. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12351. {
  12352. check_ascii = value[0];
  12353. if( (check_ascii < 48) || (check_ascii > 57) )
  12354. {
  12355. isSuccess = ConfigurationStatus_Rejected;
  12356. }
  12357. else
  12358. {
  12359. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. }
  12364. else
  12365. {
  12366. isSuccess = ConfigurationStatus_Rejected;
  12367. }
  12368. }
  12369. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12370. {
  12371. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12372. {
  12373. check_ascii = value[0];
  12374. if( (check_ascii < 48) || (check_ascii > 57) )
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. else
  12379. {
  12380. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12381. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12382. isSuccess = ConfigurationStatus_Accepted;
  12383. }
  12384. }
  12385. else
  12386. {
  12387. isSuccess = ConfigurationStatus_Rejected;
  12388. }
  12389. }
  12390. if(strcmp(key, "MinimumStatusDuration") == 0)
  12391. {
  12392. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12393. {
  12394. check_ascii = value[0];
  12395. if( (check_ascii < 48) || (check_ascii > 57) )
  12396. {
  12397. isSuccess = ConfigurationStatus_Rejected;
  12398. }
  12399. else
  12400. {
  12401. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. else
  12406. {
  12407. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12409. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12410. isSuccess = ConfigurationStatus_Accepted;
  12411. }
  12412. }
  12413. }
  12414. else
  12415. {
  12416. isSuccess = ConfigurationStatus_Rejected;
  12417. }
  12418. }
  12419. if(strcmp(key, "NumberOfConnectors") == 0)
  12420. {
  12421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12422. {
  12423. check_ascii = value[0];
  12424. if( (check_ascii < 48) || (check_ascii > 57) )
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. else
  12429. {
  12430. //Charger.ResetRetries = Integer.parseInt(value);
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. }
  12435. else
  12436. {
  12437. isSuccess = ConfigurationStatus_Rejected;
  12438. }
  12439. }
  12440. if(strcmp(key, "ResetRetries") == 0)
  12441. {
  12442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12443. {
  12444. check_ascii = value[0];
  12445. if( (check_ascii < 48) || (check_ascii > 57) )
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. else
  12450. {
  12451. //Charger.ResetRetries = Integer.parseInt(value);
  12452. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12453. isSuccess = ConfigurationStatus_Accepted;
  12454. }
  12455. }
  12456. else
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. }
  12461. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12462. {
  12463. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12464. {
  12465. strcpy(str, (const char*)value);
  12466. for(int i = 0; str[i]; i++)
  12467. {
  12468. str[i] = tolower(str[i]);
  12469. }
  12470. if(strcmp(str, "notapplicable")== 0)
  12471. {
  12472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12473. isSuccess = ConfigurationStatus_Accepted;
  12474. }
  12475. else if(strcmp(str, "unknown")== 0)
  12476. {
  12477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12478. isSuccess = ConfigurationStatus_Accepted;
  12479. }
  12480. else if(strcmp(str, "rst")== 0)
  12481. {
  12482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12483. isSuccess = ConfigurationStatus_Accepted;
  12484. }
  12485. else if(strcmp(str, "rts")== 0)
  12486. {
  12487. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12488. isSuccess = ConfigurationStatus_Accepted;
  12489. }
  12490. else if(strcmp(str, "srt")== 0)
  12491. {
  12492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12493. isSuccess = ConfigurationStatus_Accepted;
  12494. }
  12495. else if(strcmp(str, "str")== 0)
  12496. {
  12497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12498. isSuccess = ConfigurationStatus_Accepted;
  12499. }
  12500. else if(strcmp(str, "trs")== 0)
  12501. {
  12502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12503. isSuccess = ConfigurationStatus_Accepted;
  12504. }
  12505. else if(strcmp(str, "tsr")== 0)
  12506. {
  12507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12508. isSuccess = ConfigurationStatus_Accepted;
  12509. }
  12510. else
  12511. {
  12512. isSuccess = ConfigurationStatus_Rejected;
  12513. }
  12514. }
  12515. else
  12516. {
  12517. isSuccess = ConfigurationStatus_Rejected;
  12518. }
  12519. }
  12520. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12521. {
  12522. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12523. {
  12524. check_ascii = value[0];
  12525. if( (check_ascii < 48) || (check_ascii > 57) )
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. else
  12530. {
  12531. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12532. isSuccess = ConfigurationStatus_Accepted;
  12533. }
  12534. }
  12535. else
  12536. {
  12537. isSuccess = ConfigurationStatus_Rejected;
  12538. }
  12539. }
  12540. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12541. {
  12542. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12543. {
  12544. strcpy(str, (const char*)value);
  12545. for(int i = 0; str[i]; i++)
  12546. {
  12547. str[i] = tolower(str[i]);
  12548. }
  12549. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12551. isSuccess = ConfigurationStatus_Accepted;
  12552. }
  12553. else
  12554. {
  12555. isSuccess = ConfigurationStatus_Rejected;
  12556. }
  12557. }
  12558. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12559. {
  12560. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12561. {
  12562. strcpy(str, (const char*)value);
  12563. for(int i = 0; str[i]; i++)
  12564. {
  12565. str[i] = tolower(str[i]);
  12566. }
  12567. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12569. isSuccess = ConfigurationStatus_Accepted;
  12570. }
  12571. else
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. }
  12576. if(strcmp(key, "StopTxnAlignedData") == 0)
  12577. {
  12578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12579. {
  12580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12581. isSuccess = ConfigurationStatus_Accepted;
  12582. }
  12583. else
  12584. {
  12585. isSuccess = ConfigurationStatus_Rejected;
  12586. }
  12587. }
  12588. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12589. {
  12590. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12591. {
  12592. check_ascii = value[0];
  12593. if( (check_ascii < 48) || (check_ascii > 57) )
  12594. {
  12595. isSuccess = ConfigurationStatus_Rejected;
  12596. }
  12597. else
  12598. {
  12599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12600. isSuccess = ConfigurationStatus_Accepted;
  12601. }
  12602. }
  12603. else
  12604. {
  12605. isSuccess = ConfigurationStatus_Rejected;
  12606. }
  12607. }
  12608. if(strcmp(key, "StopTxnSampledData") == 0)
  12609. {
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12611. {
  12612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12613. isSuccess = ConfigurationStatus_Accepted;
  12614. }
  12615. else
  12616. {
  12617. isSuccess = ConfigurationStatus_Rejected;
  12618. }
  12619. }
  12620. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12621. {
  12622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12623. {
  12624. check_ascii = value[0];
  12625. if( (check_ascii < 48) || (check_ascii > 57) )
  12626. {
  12627. isSuccess = ConfigurationStatus_Rejected;
  12628. }
  12629. else
  12630. {
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12632. isSuccess = ConfigurationStatus_Accepted;
  12633. }
  12634. }
  12635. else
  12636. {
  12637. isSuccess = ConfigurationStatus_Rejected;
  12638. }
  12639. }
  12640. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12641. {
  12642. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12643. {
  12644. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12645. isSuccess = ConfigurationStatus_Accepted;
  12646. }
  12647. else
  12648. {
  12649. isSuccess = ConfigurationStatus_Rejected;
  12650. }
  12651. }
  12652. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12653. {
  12654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12655. {
  12656. check_ascii = value[0];
  12657. if( (check_ascii < 48) || (check_ascii > 57) )
  12658. {
  12659. isSuccess = ConfigurationStatus_Rejected;
  12660. }
  12661. else
  12662. {
  12663. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12664. isSuccess = ConfigurationStatus_Accepted;
  12665. }
  12666. }
  12667. else
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. }
  12672. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12673. {
  12674. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12675. {
  12676. check_ascii = value[0];
  12677. if( (check_ascii < 48) || (check_ascii > 57) )
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. else
  12682. {
  12683. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12684. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12685. TransactionMessageAttemptsValue = atoi(value);
  12686. isSuccess = ConfigurationStatus_Accepted;
  12687. }
  12688. }
  12689. else
  12690. {
  12691. isSuccess = ConfigurationStatus_Rejected;
  12692. }
  12693. }
  12694. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12695. {
  12696. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12697. {
  12698. check_ascii = value[0];
  12699. if( (check_ascii < 48) || (check_ascii > 57) )
  12700. {
  12701. isSuccess = ConfigurationStatus_Rejected;
  12702. }
  12703. else
  12704. {
  12705. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12706. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12707. TransactionMessageRetryIntervalValue = atoi(value);
  12708. isSuccess = ConfigurationStatus_Accepted;
  12709. }
  12710. }
  12711. else
  12712. {
  12713. isSuccess = ConfigurationStatus_Rejected;
  12714. }
  12715. }
  12716. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12717. {
  12718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12719. {
  12720. strcpy(str, (const char*)value);
  12721. for(int i = 0; str[i]; i++)
  12722. {
  12723. str[i] = tolower(str[i]);
  12724. }
  12725. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12727. isSuccess = ConfigurationStatus_Accepted;
  12728. }
  12729. else
  12730. {
  12731. isSuccess = ConfigurationStatus_Rejected;
  12732. }
  12733. }
  12734. if(strcmp(key, "WebSocketPingInterval") == 0)
  12735. {
  12736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12737. {
  12738. check_ascii = value[0];
  12739. if( (check_ascii < 48) || (check_ascii > 57) )
  12740. {
  12741. isSuccess = ConfigurationStatus_Rejected;
  12742. }
  12743. else
  12744. {
  12745. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12746. isSuccess = ConfigurationStatus_Accepted;
  12747. }
  12748. }
  12749. else
  12750. {
  12751. isSuccess = ConfigurationStatus_Rejected;
  12752. }
  12753. }
  12754. #if 0
  12755. //For OCPP Test Case
  12756. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12757. {
  12758. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12759. {
  12760. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12761. isSuccess = ConfigurationStatus_Accepted;
  12762. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12763. }
  12764. else
  12765. {
  12766. isSuccess = ConfigurationStatus_Rejected;
  12767. }
  12768. }
  12769. #endif
  12770. #if 1
  12771. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12772. {
  12773. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12774. {
  12775. strcpy(str, (const char*)value);
  12776. for(int i = 0; str[i]; i++)
  12777. {
  12778. str[i] = tolower(str[i]);
  12779. }
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12781. isSuccess = ConfigurationStatus_Accepted;
  12782. updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12783. }
  12784. else
  12785. {
  12786. isSuccess = ConfigurationStatus_Rejected;
  12787. }
  12788. }
  12789. #endif
  12790. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12791. {
  12792. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12793. {
  12794. check_ascii = value[0];
  12795. if( (check_ascii < 48) || (check_ascii > 57) )
  12796. {
  12797. isSuccess = ConfigurationStatus_Rejected;
  12798. }
  12799. else
  12800. {
  12801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12802. isSuccess = ConfigurationStatus_Accepted;
  12803. }
  12804. }
  12805. else
  12806. {
  12807. isSuccess = ConfigurationStatus_Rejected;
  12808. }
  12809. }
  12810. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12811. {
  12812. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12813. {
  12814. check_ascii = value[0];
  12815. if( (check_ascii < 48) || (check_ascii > 57) )
  12816. {
  12817. isSuccess = ConfigurationStatus_Rejected;
  12818. }
  12819. else
  12820. {
  12821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12822. isSuccess = ConfigurationStatus_Accepted;
  12823. }
  12824. }
  12825. else
  12826. {
  12827. isSuccess = ConfigurationStatus_Rejected;
  12828. }
  12829. }
  12830. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12831. {
  12832. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12833. {
  12834. strcpy(str, (const char*)value);
  12835. for(int i = 0; str[i]; i++)
  12836. {
  12837. str[i] = tolower(str[i]);
  12838. }
  12839. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12840. isSuccess = ConfigurationStatus_Accepted;
  12841. }
  12842. else
  12843. {
  12844. isSuccess = ConfigurationStatus_Rejected;
  12845. }
  12846. }
  12847. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12848. {
  12849. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12850. {
  12851. check_ascii = value[0];
  12852. if( (check_ascii < 48) || (check_ascii > 57) )
  12853. {
  12854. isSuccess = ConfigurationStatus_Rejected;
  12855. }
  12856. else
  12857. {
  12858. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12859. isSuccess = ConfigurationStatus_Accepted;
  12860. }
  12861. }
  12862. else
  12863. {
  12864. isSuccess = ConfigurationStatus_Rejected;
  12865. }
  12866. }
  12867. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12868. {
  12869. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12870. {
  12871. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12872. isSuccess = ConfigurationStatus_Accepted;
  12873. }
  12874. else
  12875. {
  12876. isSuccess = ConfigurationStatus_Rejected;
  12877. }
  12878. }
  12879. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12880. {
  12881. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12882. {
  12883. check_ascii = value[0];
  12884. if( (check_ascii < 48) || (check_ascii > 57) )
  12885. {
  12886. isSuccess = ConfigurationStatus_Rejected;
  12887. }
  12888. else
  12889. {
  12890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12891. isSuccess = ConfigurationStatus_Accepted;
  12892. }
  12893. }
  12894. else
  12895. {
  12896. isSuccess = ConfigurationStatus_Rejected;
  12897. }
  12898. }
  12899. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12900. {
  12901. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12902. {
  12903. strcpy(str, (const char*)value);
  12904. for(int i = 0; str[i]; i++)
  12905. {
  12906. str[i] = tolower(str[i]);
  12907. }
  12908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12909. isSuccess = ConfigurationStatus_Accepted;
  12910. }
  12911. else
  12912. {
  12913. isSuccess = ConfigurationStatus_Rejected;
  12914. }
  12915. }
  12916. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12917. {
  12918. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12919. {
  12920. check_ascii = value[0];
  12921. if( (check_ascii < 48) || (check_ascii > 57) )
  12922. {
  12923. isSuccess = ConfigurationStatus_Rejected;
  12924. }
  12925. else
  12926. {
  12927. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12928. isSuccess = ConfigurationStatus_Accepted;
  12929. }
  12930. }
  12931. else
  12932. {
  12933. isSuccess = ConfigurationStatus_Rejected;
  12934. }
  12935. }
  12936. return isSuccess;
  12937. }
  12938. int updateSetting(char *key, char *value)
  12939. {
  12940. mtrace();
  12941. int isSuccess = FALSE;
  12942. char string[1000]={0}, buffer[1000]={0};
  12943. char strtemp[50]={0};
  12944. char sstr[50]={ 0 };//sstr[200]={ 0 };
  12945. int pos, c = 0;
  12946. char *loc;
  12947. int pos1=0;
  12948. FILE *f = fopen("/var/www/settings1", "r");
  12949. if(f == NULL)
  12950. {
  12951. #ifdef Debug
  12952. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  12953. #endif
  12954. return isSuccess;
  12955. }
  12956. fseek(f, 0, SEEK_END);
  12957. long fsize = ftell(f);
  12958. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  12959. fread(string, 1, fsize, f);
  12960. fclose(f);
  12961. string[fsize] = 0;
  12962. loc = strstr(string, key);
  12963. if(loc != NULL)
  12964. {
  12965. DEBUG_INFO("key exist!\n");
  12966. pos = loc - string-1;
  12967. f = fopen("/var/www/settings1", "w");
  12968. strncpy(buffer, string, pos);
  12969. fprintf(f, "%s", buffer);
  12970. memset(sstr ,0, sizeof(sstr) );
  12971. c = 0;
  12972. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  12973. {
  12974. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  12975. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12976. c++;
  12977. }
  12978. sstr[c] = '\0';
  12979. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  12980. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  12981. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  12982. memset(buffer ,0, sizeof(buffer) );
  12983. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  12984. //printf("buffer=%s",buffer);
  12985. fprintf(f, "%s", buffer);
  12986. fclose(f);
  12987. }
  12988. else
  12989. {
  12990. printf("key not exist!\n");
  12991. f = fopen("/var/www/settings1", "w+");
  12992. fputs(string, f);
  12993. fseek(f, -1, SEEK_CUR);
  12994. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  12995. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  12996. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  12997. fclose(f);
  12998. }
  12999. isSuccess = TRUE;
  13000. return isSuccess;
  13001. }
  13002. int TransactionMessageAttemptsGet(void)
  13003. {
  13004. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13005. }
  13006. int FirstHeartBeatResponse(void)
  13007. {
  13008. return FirstHeartBeat;
  13009. }
  13010. int TransactionMessageRetryIntervalGet(void)
  13011. {
  13012. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13013. }
  13014. #define SA struct sockaddr
  13015. #define MAXBUF 1024
  13016. //static int m_socket_data;
  13017. //static int sockfd;
  13018. int ReadHttpStatus(int sock){
  13019. //char c;
  13020. char buff[1024]="",*ptr=buff+1;
  13021. int bytes_received, status;
  13022. DEBUG_INFO("Begin Response ..\n");
  13023. while((bytes_received = recv(sock, ptr, 1, 0))){
  13024. if(bytes_received==-1){
  13025. perror("ReadHttpStatus");
  13026. exit(1);
  13027. }
  13028. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13029. ptr++;
  13030. }
  13031. *ptr=0;
  13032. ptr=buff+1;
  13033. sscanf(ptr,"%*s %d ", &status);
  13034. DEBUG_INFO("%s\n",ptr);
  13035. DEBUG_INFO("status=%d\n",status);
  13036. DEBUG_INFO("End Response ..\n");
  13037. return (bytes_received>0)?status:0;
  13038. }
  13039. //the only filed that it parsed is 'Content-Length'
  13040. int ParseHeader(int sock){
  13041. //char c;
  13042. char buff[1024]="",*ptr=buff+4;
  13043. int bytes_received;
  13044. DEBUG_INFO("Begin HEADER ..\n");
  13045. while((bytes_received = recv(sock, ptr, 1, 0))){
  13046. if(bytes_received==-1){
  13047. perror("Parse Header");
  13048. exit(1);
  13049. }
  13050. if(
  13051. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13052. (ptr[-1]=='\r') && (*ptr=='\n' )
  13053. ) break;
  13054. ptr++;
  13055. }
  13056. *ptr=0;
  13057. ptr=buff+4;
  13058. //printf("%s",ptr);
  13059. if(bytes_received){
  13060. ptr=strstr(ptr,"Content-Length:");
  13061. if(ptr){
  13062. sscanf(ptr,"%*s %d",&bytes_received);
  13063. }else
  13064. bytes_received=-1; //unknown size
  13065. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13066. }
  13067. DEBUG_INFO("End HEADER ..\n");
  13068. return bytes_received ;
  13069. }
  13070. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13071. {
  13072. char rmFileCmd[100]={0};
  13073. char FilePath[100]={0};
  13074. char ftpbuf[200];
  13075. int systemresult;
  13076. //DEBUG_INFO("filename=%s\n",filename);
  13077. //DEBUG_INFO("url=%s\n",url);
  13078. sprintf(FilePath,"/mnt/%s",filename);
  13079. if((access(FilePath,F_OK))!=-1)
  13080. {
  13081. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13082. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13083. system(rmFileCmd);
  13084. }
  13085. memset(ftpbuf, 0, sizeof(ftpbuf));
  13086. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13087. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13088. systemresult = system(ftpbuf);
  13089. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13090. if(systemresult != 0)
  13091. {
  13092. DEBUG_INFO("http DownLoad error!\n");
  13093. return FALSE;
  13094. }
  13095. return TRUE;
  13096. }
  13097. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13098. {
  13099. char rmFileCmd[100]={0};
  13100. char FilePath[100]={0};
  13101. char ftpbuf[200];
  13102. int systemresult;
  13103. //char temp[100];
  13104. #if 0
  13105. struct hostent* server;
  13106. char *IPbuffer;
  13107. server = gethostbyname(location);
  13108. // To convert an Internet network
  13109. // address into ASCII string
  13110. IPbuffer = inet_ntoa(*((struct in_addr*)
  13111. server->h_addr_list[0]));
  13112. #endif
  13113. sprintf(FilePath,"/mnt/%s",filename);
  13114. if((access(FilePath,F_OK))!=-1)
  13115. {
  13116. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13117. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13118. system(rmFileCmd);
  13119. }
  13120. memset(ftpbuf, 0, sizeof(ftpbuf));
  13121. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13122. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13123. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13124. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13125. systemresult = system(ftpbuf);
  13126. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13127. if(systemresult != 0)
  13128. {
  13129. printf("wget error!\n");
  13130. return FALSE;
  13131. }
  13132. return TRUE;
  13133. }
  13134. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13135. {
  13136. char rmFileCmd[100]={0};
  13137. char FilePath[100]={0};
  13138. char ftpbuf[200];
  13139. char filenametemp[60]={0};
  13140. int systemresult;
  13141. //DEBUG_INFO("filename=%s\n",filename);
  13142. //DEBUG_INFO("url=%s\n",url);
  13143. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13144. if((access(FilePath,F_OK))!=-1)
  13145. {
  13146. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13147. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13148. system(rmFileCmd);
  13149. }
  13150. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13151. if(fp == NULL)
  13152. {
  13153. DEBUG_INFO("log is NULL\n");
  13154. return FALSE;
  13155. }
  13156. else
  13157. {
  13158. fprintf(fp, "%s\n", url);
  13159. sscanf(filename, "%*2[.]%s", filenametemp);
  13160. fprintf(fp, "%s\n", filenametemp);
  13161. fclose(fp);
  13162. }
  13163. memset(ftpbuf, 0, sizeof(ftpbuf));
  13164. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13165. systemresult = system(ftpbuf);
  13166. DEBUG_INFO("systemresult=%d\n",systemresult);
  13167. if(systemresult != 0)
  13168. {
  13169. DEBUG_INFO("http upload error!\n");
  13170. return FALSE;
  13171. }
  13172. return TRUE;
  13173. }
  13174. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13175. {
  13176. struct hostent* server;
  13177. char *IPbuffer;
  13178. char ftpbuf[200];
  13179. int systemresult;
  13180. // To retrieve host information
  13181. server = gethostbyname(location);
  13182. // To convert an Internet network
  13183. // address into ASCII string
  13184. IPbuffer = inet_ntoa(*((struct in_addr*)
  13185. server->h_addr_list[0]));
  13186. memset(ftpbuf, 0, sizeof(ftpbuf));
  13187. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13188. /* format : ftpput -u username -p passwd IP target source*/
  13189. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13190. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13191. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13192. systemresult = system(ftpbuf);
  13193. DEBUG_INFO("systemresult=%d\n",systemresult);
  13194. if(systemresult != 0)
  13195. {
  13196. DEBUG_INFO("ftpput error!\n");
  13197. return FALSE;
  13198. }
  13199. return TRUE;
  13200. }
  13201. int SettingChargingRecord(int target, int transactionId)
  13202. {
  13203. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13204. {
  13205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13206. {
  13207. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13208. {
  13209. addBuff(target, transactionId, 0);
  13210. return TRUE;
  13211. }
  13212. }
  13213. for (int index = 0; index < CCS_QUANTITY; index++)
  13214. {
  13215. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13216. {
  13217. addBuff(target, transactionId, 0);
  13218. return TRUE;
  13219. }
  13220. }
  13221. for (int index = 0; index < GB_QUANTITY; index++)
  13222. {
  13223. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13224. {
  13225. addBuff(target, transactionId, 0);
  13226. return TRUE;
  13227. }
  13228. }
  13229. }
  13230. else
  13231. {
  13232. for (int index = 0; index < AC_QUANTITY; index++)
  13233. {
  13234. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13235. {
  13236. addBuff(target, transactionId, 0);
  13237. return TRUE;
  13238. }
  13239. }
  13240. }
  13241. return FALSE;
  13242. }
  13243. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13244. {
  13245. int isSuccess = FALSE;
  13246. //char *query = NULL;
  13247. sqlite3_stmt *stmt;
  13248. int rc; // return code
  13249. char str[20];
  13250. sprintf(str,"%d",user_id);
  13251. 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 */
  13252. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13253. rc = sqlite3_step(stmt); /* 3 */
  13254. if (rc != SQLITE_DONE) {
  13255. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13256. goto out;
  13257. }
  13258. sqlite3_finalize(stmt);
  13259. // free(query);
  13260. out:
  13261. //----------------------
  13262. // close SQLite database
  13263. //----------------------
  13264. sqlite3_close(db);
  13265. printf("database closed.\n");
  13266. return isSuccess;
  13267. }
  13268. /**
  13269. * Place the contents of the specified file into a memory buffer
  13270. *
  13271. * @param[in] filename The path and name of the file to read
  13272. * @param[out] filebuffer A pointer to the contents in memory
  13273. * @return status 0 success, 1 on failure
  13274. */
  13275. int get_file_contents(const char* filename, char** outbuffer) {
  13276. FILE* file = NULL;
  13277. long filesize;
  13278. const int blocksize = 1;
  13279. size_t readsize;
  13280. char* filebuffer;
  13281. // Open the file
  13282. file = fopen(filename, "r");
  13283. if (NULL == file)
  13284. {
  13285. printf("'%s' not opened\n", filename);
  13286. exit(EXIT_FAILURE);
  13287. }
  13288. // Determine the file size
  13289. fseek(file, 0, SEEK_END);
  13290. filesize = ftell(file);
  13291. rewind (file);
  13292. // Allocate memory for the file contents
  13293. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13294. *outbuffer = filebuffer;
  13295. if (filebuffer == NULL)
  13296. {
  13297. fputs ("malloc out-of-memory", stderr);
  13298. exit(EXIT_FAILURE);
  13299. }
  13300. // Read in the file
  13301. readsize = fread(filebuffer, blocksize, filesize, file);
  13302. if (readsize != filesize)
  13303. {
  13304. fputs ("didn't read file completely",stderr);
  13305. exit(EXIT_FAILURE);
  13306. }
  13307. // Clean exit
  13308. fclose(file);
  13309. return EXIT_SUCCESS;
  13310. }
  13311. static int selectSqlCount = 0;
  13312. static int callback(void *data, int argc, char **argv, char **azColName){
  13313. int i;
  13314. //printf("%s: ", (const char*)data);
  13315. selectSqlCount = argc;
  13316. for(i = 0; i<argc; i++){
  13317. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13318. }
  13319. //printf("\n");
  13320. return 0;
  13321. }
  13322. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13323. //int i;
  13324. //printf("%s:\n", (const char*)data);
  13325. localversion = argv[5] ? atoi(argv[5]) : 0;
  13326. //printf("localversion=%d\n", localversion);
  13327. return 0;
  13328. }
  13329. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13330. //int i;
  13331. //printf("%s:\n", (const char*)data);
  13332. //idTag
  13333. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13334. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13335. //parentIdTag
  13336. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13337. //expir_date
  13338. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13339. //status
  13340. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13341. //version
  13342. idTagQuery.listVersionInt = atoi(argv[5]);
  13343. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13344. return 0;
  13345. }
  13346. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13347. #if 0
  13348. int i;
  13349. //printf("%s:\n", (const char*)data);
  13350. for(i=0; i<argc; i++){
  13351. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13352. }
  13353. //printf("");
  13354. #endif
  13355. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13356. // printf("localversion=%d\n", localversion);
  13357. return 0;
  13358. }
  13359. /** sqlite3_exec的回调。
  13360. *
  13361. * 向控制台打印查询的结果。
  13362. *
  13363. * @param in data 传递给回调函数的数据。
  13364. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13365. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13366. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13367. * @return 状态码。
  13368. */
  13369. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13370. {
  13371. for (int i = 0; i < n_columns; i++)
  13372. {
  13373. DEBUG_INFO("%s/t", col_values[i]);
  13374. }
  13375. DEBUG_INFO("/n");
  13376. return 0;
  13377. }
  13378. void OCPP_getListVerion()
  13379. {
  13380. int rc = 0;
  13381. // const char* data = "Callback function called";
  13382. char sql[100];
  13383. char zErrMsg[100];
  13384. memset(sql, 0, 100);
  13385. memset(zErrMsg, 0, 100);
  13386. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13387. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13388. /* Execute SQL statement */
  13389. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13390. DEBUG_INFO("rc=%d\n",rc);
  13391. if( rc != SQLITE_OK ){
  13392. DEBUG_INFO("SQL error: %s", zErrMsg);
  13393. //sqlite3_free(zErrMsg);
  13394. }
  13395. }
  13396. void OCPP_getIdTag(char idTag[])
  13397. {
  13398. int rc = 0;
  13399. // const char* data = "Callback function called";
  13400. char sql[100];
  13401. char zErrMsg[100];
  13402. memset(sql, 0, 100);
  13403. memset(zErrMsg, 0, 100);
  13404. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13405. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13406. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13407. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13408. /* Execute SQL statement */
  13409. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13410. if( rc != SQLITE_OK ){
  13411. DEBUG_INFO("SQL error: %s", zErrMsg);
  13412. //sqlite3_free(zErrMsg);
  13413. }
  13414. //return ver;
  13415. }
  13416. void OCPP_get_TableAuthlocalAllData(void)
  13417. {
  13418. int rc = 0;
  13419. // const char* data = "Callback function called";
  13420. char sql[100];
  13421. char zErrMsg[100];
  13422. memset(sql, 0, 100);
  13423. memset(zErrMsg, 0, 100);
  13424. sprintf(sql,"select * from ocpp_auth_local ");
  13425. /* Execute SQL statement */
  13426. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13427. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13428. if( rc != SQLITE_OK ){
  13429. DEBUG_INFO("SQL error: %s", zErrMsg);
  13430. //sqlite3_free(zErrMsg);
  13431. }
  13432. //return ver;
  13433. }
  13434. int OCPP_cleanLocalList()
  13435. {
  13436. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13437. char *errMsg = 0;
  13438. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13439. if (SQLITE_OK != rc)
  13440. {
  13441. DEBUG_INFO("%s\n",errMsg);
  13442. return FALSE;
  13443. }
  13444. else
  13445. {
  13446. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13447. }
  13448. return TRUE;
  13449. }
  13450. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13451. {
  13452. int isSuccess = FALSE;
  13453. int ret = 0;
  13454. //const char* data = "Callback function called";
  13455. char sql[300];
  13456. char zErrMsg[200];
  13457. memset(sql, 0, 300);
  13458. memset(zErrMsg, 0, 200);
  13459. 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);
  13460. //* Execute SQL statement */
  13461. //zErrMsg = 0;
  13462. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13463. if( ret != SQLITE_OK ){
  13464. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13465. // free(zErrMsg);
  13466. // free(sql);
  13467. return isSuccess;
  13468. }
  13469. memset(sql, 0, 300);
  13470. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13471. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13472. if( ret != SQLITE_OK ){
  13473. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13474. // free(zErrMsg);
  13475. // free(sql);
  13476. return isSuccess;
  13477. }
  13478. // DEBUG_INFO("successfully Insert records created\n");
  13479. isSuccess = TRUE;
  13480. return isSuccess;
  13481. }
  13482. void OCPP_deleteIdTag(char idTag[])
  13483. {
  13484. //int ver = 0;
  13485. //int isSuccess = FALSE;
  13486. int rc = 0;
  13487. char sql[100];
  13488. char zErrMsg[100];
  13489. memset(sql, 0, 100);
  13490. memset(zErrMsg, 0, 100);
  13491. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13492. //* Execute SQL statement */
  13493. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13494. if( rc != SQLITE_OK ){
  13495. DEBUG_INFO("SQL error: %s", zErrMsg);
  13496. //sqlite3_free(zErrMsg);
  13497. }
  13498. }
  13499. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13500. {
  13501. int isSuccess = FALSE;
  13502. int ret = 0;
  13503. const char* data = "Callback function called";
  13504. char sql[200];
  13505. char zErrMsg[100];
  13506. memset(sql, 0, 200);
  13507. memset(zErrMsg, 0, 100);
  13508. //* selectFromTable */
  13509. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13510. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13511. //* Execute SQL statement */
  13512. selectSqlCount = 0;
  13513. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13514. if( ret != SQLITE_OK ){
  13515. printf("Error SQL: %s\n", zErrMsg);
  13516. }
  13517. printf("successfully select operation done\n");
  13518. memset(sql, 0, 200);
  13519. memset(zErrMsg, 0, 100);
  13520. if(selectSqlCount == 0)
  13521. {
  13522. //Insert
  13523. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13524. 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);
  13525. DEBUG_INFO("sql:%s\n", sql);
  13526. //* Execute SQL statement */
  13527. //zErrMsg = 0;
  13528. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13529. if( ret != SQLITE_OK ){
  13530. printf("SQL error: %s\n", zErrMsg);
  13531. return isSuccess;
  13532. }
  13533. DEBUG_INFO("successfully Insert records created\n");
  13534. isSuccess = TRUE;
  13535. }
  13536. else
  13537. {
  13538. //Update
  13539. //* Create merged SQL statement */
  13540. 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);
  13541. /* Execute SQL statement */
  13542. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13543. if( ret != SQLITE_OK ){
  13544. printf("SQL error: %s\n", zErrMsg);
  13545. //sqlite3_free(zErrMsg);
  13546. //sqlite3_free(sql);
  13547. return isSuccess;
  13548. }
  13549. DEBUG_INFO("Successfully operation done \n");
  13550. isSuccess = TRUE;
  13551. }
  13552. return isSuccess;
  13553. }
  13554. int GetOcppServerURL()
  13555. {
  13556. int result = FALSE;
  13557. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13558. memset(OcppHost, 0, sizeof(OcppHost));
  13559. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13560. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13561. {
  13562. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13563. #if 1
  13564. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13565. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13566. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13567. #endif
  13568. #if 0
  13569. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13570. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13571. OcppProtocol, OcppHost, OcppTempPath);
  13572. OcppPort = 443;
  13573. #endif
  13574. result = TRUE;
  13575. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13576. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13577. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13578. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13579. goto End;
  13580. }
  13581. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13582. {
  13583. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13584. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13585. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13586. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13587. result = TRUE;
  13588. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13589. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13590. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13591. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13592. goto End;
  13593. }
  13594. else
  13595. {
  13596. strcpy(OcppHost,"");
  13597. }
  13598. End:
  13599. return result;
  13600. }
  13601. int GetOcppPath()
  13602. {
  13603. int result = FALSE;
  13604. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13605. {
  13606. if(OcppTempPath == NULL)
  13607. {
  13608. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13609. }
  13610. else
  13611. {
  13612. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13613. }
  13614. result = TRUE;
  13615. goto End;
  13616. }
  13617. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13618. {
  13619. if(OcppTempPath == NULL)
  13620. {
  13621. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13622. }
  13623. else
  13624. {
  13625. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13626. }
  13627. result = TRUE;
  13628. goto End;
  13629. }
  13630. else
  13631. {
  13632. strcpy(OcppPath,"");
  13633. }
  13634. End:
  13635. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13636. return result;
  13637. }
  13638. int GetOcppPort()
  13639. {
  13640. return OcppPort;
  13641. }
  13642. int GetOcppConnStatus(void)
  13643. {
  13644. return ShmOCPP16Data->OcppConnStatus;
  13645. }
  13646. void SetOcppConnStatus(uint8_t status)
  13647. {
  13648. ShmOCPP16Data->OcppConnStatus = status;
  13649. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13650. }
  13651. int GetHeartBeatWithNOResponse(void)
  13652. {
  13653. return HeartBeatWithNOResponse;
  13654. }
  13655. void SetHeartBeatWithNOResponse(void)
  13656. {
  13657. HeartBeatWithNOResponse = 0;
  13658. }
  13659. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13660. /*
  13661. src 源字串的首地址(buf的地址)
  13662. separator 指定的分割字元
  13663. dest 接收子字串的陣列
  13664. num 分割後子字串的個數
  13665. */
  13666. char *pNext;
  13667. int count = 0;
  13668. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13669. return;
  13670. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13671. return;
  13672. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13673. while(pNext != NULL) {
  13674. *dest++ = pNext;
  13675. ++count;
  13676. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13677. }
  13678. *num = count;
  13679. }
  13680. int GetTransactionId(int gunindex, unsigned char idTag[])
  13681. {
  13682. char ch;
  13683. FILE *fptr1;
  13684. int temptransactionId;
  13685. char str[100]={0};
  13686. temptransactionId = 0;
  13687. /*------ Read the file ----------------*/
  13688. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13689. if (!fptr1)
  13690. {
  13691. //printf(" File not found or unable to open the input file!!\n");
  13692. return temptransactionId;
  13693. }
  13694. ch=fgetc(fptr1);
  13695. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13696. rewind(fptr1);
  13697. if(ch!=EOF)
  13698. {
  13699. // printf("%c",ch);
  13700. while (fgets(str, 100, fptr1) != NULL)
  13701. {
  13702. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13703. if(str[0]=='\0')
  13704. {
  13705. break;
  13706. }
  13707. char *revbuf[8] = {0}; //存放分割後的子字串
  13708. int num = 0;//分割後子字串的個數
  13709. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13710. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13711. {
  13712. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13713. {
  13714. temptransactionId = atoi(revbuf[2]);
  13715. break;
  13716. }
  13717. }
  13718. }
  13719. }
  13720. fclose(fptr1);
  13721. /*------- End of reading ---------------*/
  13722. return temptransactionId;
  13723. }
  13724. void SetTransactionIdZero(int transactionId)
  13725. {
  13726. //TransactionId[gunindex] = 0;
  13727. char ch;
  13728. FILE *fptr1, *fptr2;
  13729. int temptransactionId = 0;
  13730. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13731. printf("\n Delete a specific line from a file :\n");
  13732. printf("-----------------------------------------\n");
  13733. //scanf("%s",fname);
  13734. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13735. if (!fptr1)
  13736. {
  13737. //printf(" File not found or unable to open the input file!!\n");
  13738. return ;
  13739. }
  13740. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13741. if (!fptr2)
  13742. {
  13743. printf("Unable to open a temporary file to write!!\n");
  13744. fclose(fptr1);
  13745. return ;
  13746. }
  13747. ch=fgetc(fptr1);
  13748. //printf(" Now the content of the file %s is : \n",fname);
  13749. rewind(fptr1);
  13750. if(ch!=EOF)
  13751. {
  13752. // copy all contents to the temporary file except the specific line
  13753. while (fgets(str, 100, fptr1) != NULL)
  13754. {
  13755. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13756. if(str[0]=='\0')
  13757. {
  13758. break;
  13759. }
  13760. char *revbuf[8] = {0}; //存放分割後的子字串
  13761. int num = 0;//分割後子字串的個數
  13762. strcpy(strtemp, str);
  13763. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13764. if(revbuf[2][0] != '\0')
  13765. {
  13766. temptransactionId = atoi(revbuf[2]);
  13767. if(transactionId != temptransactionId)
  13768. {
  13769. fprintf(fptr2, "%s", strtemp);
  13770. }
  13771. }
  13772. }
  13773. }
  13774. fclose(fptr1);
  13775. fclose(fptr2);
  13776. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13777. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13778. printf("\n Delete a specific line from a file End\n");
  13779. printf("-----------------------------------------\n");
  13780. /*------ Read the file ----------------*/
  13781. }
  13782. int InternetDisconnect(void)
  13783. {
  13784. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13785. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13786. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13787. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13788. }
  13789. void GetChargingProfileRequest(int gunindex)
  13790. {
  13791. mtrace();
  13792. //int connectorIdInt, durationInt;
  13793. //char chargingRateUnitStr[4]={0};
  13794. int tempdurationInt = 0;
  13795. int tempchargingProfileId = 0;
  13796. int tempstackLevel = 0;
  13797. int temptransactionId = 0;
  13798. float tempminChargingRateFloat = 0.0;
  13799. char tempchargingProfilePurposeStr[24]={0};
  13800. char tempchargingProfileKindStr[12]={0};
  13801. char temprecurrencyKindStr[8]={0};
  13802. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13803. char tempvalidToStr[28]={0};
  13804. int tempStartPeriodInt = 0;
  13805. float tempLimitInt = 0.0;//0.1;
  13806. int tempNumberPhasesInt=0;
  13807. char fname[200];
  13808. //char comfirmstr[20];
  13809. float MinChargingRate =0.0;
  13810. double diff_t;
  13811. struct tm tp;
  13812. FILE *fptr1;//, *fptr2;
  13813. int c = 0;
  13814. char * pch;
  13815. char *loc;
  13816. char sstr[200]={ 0 };
  13817. int n_chargingProfile = 0;
  13818. int n_SchedulePeriods = 0;
  13819. char SchedulePeriodList[10][200]={0};
  13820. char sLineWord[1600]={0};
  13821. char word[1000]={0};
  13822. int confirmPeriods = 0;
  13823. struct StructProfile ChargePointMaxProfile;
  13824. struct StructProfile TxDefaultProfile;
  13825. struct StructProfile TxProfile;
  13826. struct StructProfile TxDefaultProfiletemp[2]={0};
  13827. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13828. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13829. struct StructChargingProfile TxProfile_TEMP={0};
  13830. int TxDefaultProfileFileIsNull=FALSE;
  13831. int ChargePointMaxProfileIsNull=FALSE;
  13832. int TxProfileIsNull=FALSE;
  13833. // int CompositeSceduleIndex = 0;
  13834. char ChargePointMaxProfileScheduleStr[30]={0};
  13835. char TxDefaultProfileScheduleStr[30]={0};
  13836. char TxProfileScheduleStr[30]={0};
  13837. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13838. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13839. memset(&TxProfile,0,sizeof(struct StructProfile));
  13840. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13841. DEBUG_INFO("GetChargingProfileRequest\n");
  13842. //*****************************ChargePointMaxProfile******************************************/
  13843. strcpy(fname, ChargePointMaxProfile_JSON);
  13844. ChargePointMaxProfileIsNull=TRUE;
  13845. DEBUG_INFO("test 1\n");
  13846. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13847. {
  13848. fptr1 = fopen(fname, "r");
  13849. int c;
  13850. c = fgetc(fptr1);
  13851. //DEBUG_INFO("c:%d\n",c);
  13852. rewind(fptr1);
  13853. if(c == EOF)
  13854. {
  13855. DEBUG_INFO("\n End of file reached.");
  13856. ChargePointMaxProfileIsNull=TRUE;
  13857. fclose(fptr1);
  13858. }
  13859. else
  13860. {
  13861. DEBUG_INFO("test 2\n");
  13862. ChargePointMaxProfileIsNull=FALSE;
  13863. while(fscanf(fptr1, "%s", word) != EOF)
  13864. {
  13865. if(strcmp(word, "chargingProfileId") == 0)
  13866. {
  13867. n_chargingProfile = n_chargingProfile + 1;
  13868. }
  13869. }
  13870. rewind(fptr1);
  13871. //search Charging Profile Element
  13872. int i = 0;
  13873. int j = 0;
  13874. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  13875. //***********chargingProfileId**************/
  13876. c = 0;
  13877. loc = strstr(sLineWord, "chargingProfileId");
  13878. //DEBUG_INFO("loc=%s\n",loc);
  13879. memset(sstr ,0, sizeof(sstr) );
  13880. if(loc != NULL)
  13881. {
  13882. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  13883. {
  13884. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  13885. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13886. c++;
  13887. }
  13888. sstr[c] = '\0';
  13889. tempchargingProfileId = atoi(sstr);
  13890. }
  13891. else
  13892. {
  13893. tempchargingProfileId = 0;
  13894. }
  13895. //***********stackLevel**************/
  13896. c = 0;
  13897. loc = strstr(sLineWord, "stackLevel");
  13898. //DEBUG_INFO("loc=%s\n",loc);
  13899. memset(sstr ,0, sizeof(sstr) );
  13900. if(loc != NULL)
  13901. {
  13902. while (loc[2+strlen("stackLevel")+c] != '\"')
  13903. {
  13904. sstr[c] = loc[2+strlen("stackLevel")+c];
  13905. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13906. c++;
  13907. }
  13908. sstr[c] = '\0';
  13909. tempstackLevel = atoi(sstr);
  13910. }
  13911. else
  13912. {
  13913. tempstackLevel = 0;
  13914. }
  13915. //***********chargingProfilePurpose **************/
  13916. c = 0;
  13917. loc = strstr(sLineWord, "chargingProfilePurpose");
  13918. //DEBUG_INFO("loc=%s\n",loc);
  13919. memset(sstr ,0, sizeof(sstr) );
  13920. if(loc != NULL)
  13921. {
  13922. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  13923. {
  13924. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  13925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13926. c++;
  13927. }
  13928. sstr[c] = '\0';
  13929. strcpy(tempchargingProfilePurposeStr,sstr);
  13930. }
  13931. else
  13932. {
  13933. strcpy(tempchargingProfilePurposeStr,"");
  13934. }
  13935. //***********chargingProfileKind **************/
  13936. c = 0;
  13937. loc = strstr(sLineWord, "chargingProfileKind");
  13938. //DEBUG_INFO("loc=%s\n",loc);
  13939. memset(sstr ,0, sizeof(sstr) );
  13940. if(loc != NULL)
  13941. {
  13942. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  13943. {
  13944. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  13945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13946. c++;
  13947. }
  13948. sstr[c] = '\0';
  13949. strcpy(tempchargingProfileKindStr,sstr);
  13950. }
  13951. else
  13952. {
  13953. strcpy(tempchargingProfileKindStr,"");
  13954. }
  13955. //***********recurrencyKind **************/
  13956. c = 0;
  13957. loc = strstr(sLineWord, "recurrencyKind");
  13958. //DEBUG_INFO("loc=%s\n",loc);
  13959. memset(sstr ,0, sizeof(sstr) );
  13960. if(loc != NULL)
  13961. {
  13962. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  13963. {
  13964. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  13965. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13966. c++;
  13967. }
  13968. sstr[c] = '\0';
  13969. strcpy(temprecurrencyKindStr,sstr);
  13970. }
  13971. else
  13972. {
  13973. strcpy(temprecurrencyKindStr,"");
  13974. }
  13975. //***********validFrom**************/
  13976. c = 0;
  13977. loc = strstr(sLineWord, "validFrom");
  13978. //DEBUG_INFO("loc=%s\n",loc);
  13979. memset(sstr ,0, sizeof(sstr) );
  13980. if(loc != NULL)
  13981. {
  13982. while (loc[3+strlen("validFrom")+c] != '\"')
  13983. {
  13984. sstr[c] = loc[3+strlen("validFrom")+c];
  13985. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13986. c++;
  13987. }
  13988. sstr[c] = '\0';
  13989. strcpy(tempvalidFromStr,sstr);
  13990. }
  13991. else
  13992. {
  13993. strcpy(tempvalidFromStr,"");
  13994. }
  13995. //***********validTo **************/
  13996. c = 0;
  13997. loc = strstr(sLineWord, "validTo");
  13998. //DEBUG_INFO("loc=%s\n",loc);
  13999. memset(sstr ,0, sizeof(sstr) );
  14000. if(loc != NULL)
  14001. {
  14002. while (loc[3+strlen("validTo")+c] != '\"')
  14003. {
  14004. sstr[c] = loc[3+strlen("validTo")+c];
  14005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14006. c++;
  14007. }
  14008. sstr[c] = '\0';
  14009. strcpy(tempvalidToStr,sstr);
  14010. }
  14011. else
  14012. {
  14013. strcpy(tempvalidToStr,"");
  14014. }
  14015. //***********validFrom**************/
  14016. c = 0;
  14017. loc = strstr(sLineWord, "validFrom");
  14018. if(loc != NULL)
  14019. {
  14020. memset(sstr ,0, sizeof(sstr) );
  14021. while (loc[3+strlen("validFrom")+c] != '\"')
  14022. {
  14023. sstr[c] = loc[3+strlen("validFrom")+c];
  14024. c++;
  14025. }
  14026. sstr[c] = '\0';
  14027. strcpy(tempvalidFromStr,sstr);
  14028. }
  14029. else
  14030. {
  14031. strcpy(tempvalidFromStr,"");
  14032. }
  14033. //***********validTo **************/
  14034. c = 0;
  14035. loc = strstr(sLineWord, "validTo");
  14036. if(loc != NULL)
  14037. {
  14038. memset(sstr ,0, sizeof(sstr) );
  14039. while (loc[3+strlen("validTo")+c] != '\"')
  14040. {
  14041. sstr[c] = loc[3+strlen("validTo")+c];
  14042. c++;
  14043. }
  14044. sstr[c] = '\0';
  14045. strcpy(tempvalidToStr,sstr);
  14046. }
  14047. else
  14048. {
  14049. strcpy(tempvalidToStr,"");
  14050. }
  14051. //***********duration**************/
  14052. c = 0;
  14053. loc = strstr(sLineWord, "duration");
  14054. if(loc != NULL)
  14055. {
  14056. memset(sstr ,0, sizeof(sstr) );
  14057. while (loc[2+strlen("duration")+c] != ',')
  14058. {
  14059. sstr[c] = loc[2+strlen("duration")+c];
  14060. c++;
  14061. }
  14062. sstr[c] = '\0';
  14063. tempdurationInt = atoi(sstr);
  14064. }
  14065. else
  14066. {
  14067. tempdurationInt = 0;
  14068. }
  14069. //**********startSchedule**********/
  14070. c = 0;
  14071. loc = strstr(sLineWord, "startSchedule");
  14072. if(loc != NULL)
  14073. {
  14074. memset(sstr ,0, sizeof(sstr) );
  14075. while (loc[3+strlen("startSchedule")+c] != '\"')
  14076. {
  14077. sstr[c] = loc[3+strlen("startSchedule")+c];
  14078. c++;
  14079. }
  14080. sstr[c] = '\0';
  14081. strcpy(tempstartScheduleStr, sstr);
  14082. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14083. }
  14084. else
  14085. {
  14086. strcpy(tempstartScheduleStr, "");
  14087. strcpy(ChargePointMaxProfileScheduleStr, "");
  14088. }
  14089. //**********chargingRateUnit**********/
  14090. c = 0;
  14091. loc = strstr(sLineWord, "chargingRateUnit");
  14092. memset(sstr ,0, sizeof(sstr) );
  14093. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14094. {
  14095. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14096. c++;
  14097. }
  14098. sstr[c] = '\0';
  14099. strcpy(tempchargingRateUnitStr, sstr);
  14100. //**********minChargingRate*******/
  14101. c = 0;
  14102. loc = strstr(sLineWord, "minChargingRate");
  14103. if(loc != NULL)
  14104. {
  14105. memset(sstr ,0, sizeof(sstr) );
  14106. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14107. {
  14108. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14109. c++;
  14110. }
  14111. sstr[c] = '\0';
  14112. tempminChargingRateFloat = atof(sstr);
  14113. }
  14114. else
  14115. {
  14116. tempminChargingRateFloat = 0.0;
  14117. }
  14118. //
  14119. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14120. tp.tm_isdst = -1;
  14121. time_t utc = mktime(&tp);
  14122. time_t t = time(NULL);
  14123. diff_t = difftime(t, utc);
  14124. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14125. //parsing strings to words
  14126. i = 0;
  14127. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14128. loc = loc+3+strlen("chargingSchedulePeriod");
  14129. pch = strtok(loc ,"{");
  14130. while (pch != NULL)
  14131. {
  14132. strcpy(SchedulePeriodList[i], pch);
  14133. pch = strtok (NULL, "{");
  14134. i = i + 1;
  14135. }
  14136. n_SchedulePeriods = i;
  14137. for(int i=0;i<n_SchedulePeriods;i++)
  14138. {
  14139. //*************startPeriod****************/
  14140. c = 0;
  14141. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14142. memset(sstr ,0, sizeof(sstr) );
  14143. while (loc[strlen("startPeriod")+2+c] != ',')
  14144. {
  14145. sstr[c] = loc[strlen("startPeriod")+2+c];
  14146. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14147. c++;
  14148. }
  14149. sstr[c] = '\0';
  14150. tempStartPeriodInt = atoi(sstr);
  14151. //*************limit****************/
  14152. c = 0;
  14153. loc = strstr(SchedulePeriodList[i], "limit");
  14154. memset(sstr ,0, sizeof(sstr) );
  14155. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14156. {
  14157. sstr[c] = loc[strlen("limit")+2+c];
  14158. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14159. c++;
  14160. }
  14161. sstr[c] = '\0';
  14162. tempLimitInt = atof(sstr);
  14163. //*************numberPhases****************/
  14164. c = 0;
  14165. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14166. memset(sstr ,0, sizeof(sstr) );
  14167. if(loc != NULL)
  14168. {
  14169. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14170. {
  14171. sstr[c] = loc[strlen("numberPhases")+2+c];
  14172. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14173. c++;
  14174. }
  14175. sstr[c] = '\0';
  14176. tempNumberPhasesInt = atoi(sstr);
  14177. }
  14178. else
  14179. {
  14180. tempNumberPhasesInt = 0;
  14181. }
  14182. if(j == 0)
  14183. {
  14184. ChargePointMaxProfile.Duration = tempdurationInt;
  14185. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14186. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14187. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14188. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14189. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14190. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14191. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14192. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14193. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14194. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14195. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14196. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14197. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14198. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14199. }
  14200. }
  14201. if(MinChargingRate < tempminChargingRateFloat)
  14202. {
  14203. MinChargingRate = tempminChargingRateFloat;
  14204. }
  14205. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14206. if(confirmPeriods < n_SchedulePeriods)
  14207. {
  14208. confirmPeriods = n_SchedulePeriods;
  14209. }
  14210. j = j + 1;
  14211. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14212. fclose(fptr1);
  14213. }// end else
  14214. }// the end of access file ChargePointMaxProfile
  14215. DEBUG_INFO("test 3\n");
  14216. //****************************TxDefaultProfile************************************************/
  14217. memset(fname, 0, sizeof fname);
  14218. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14219. TxDefaultProfileFileIsNull=TRUE;
  14220. if((access(fname,F_OK))!=-1)
  14221. {
  14222. fptr1 = fopen(fname, "r");
  14223. c = 0;
  14224. c = fgetc(fptr1);
  14225. //DEBUG_INFO("c:%d\n",c);
  14226. rewind(fptr1);
  14227. if(c == EOF)
  14228. {
  14229. DEBUG_INFO("\n End of file reached.");
  14230. TxDefaultProfileFileIsNull=TRUE;
  14231. fclose(fptr1);
  14232. }
  14233. else
  14234. {
  14235. TxDefaultProfileFileIsNull=FALSE;
  14236. while(fscanf(fptr1, "%s", word) != EOF)
  14237. {
  14238. if(strcmp(word, "chargingProfileId") == 0)
  14239. {
  14240. n_chargingProfile = n_chargingProfile + 1;
  14241. }
  14242. }
  14243. rewind(fptr1);
  14244. //search Charging Profile Element
  14245. int i = 0;
  14246. int j = 0;
  14247. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14248. {
  14249. #if 0
  14250. //***********connectorId****************/
  14251. c = 0;
  14252. loc = strstr(sLineWord, "connectorId");
  14253. memset(sstr ,0, sizeof(sstr) );
  14254. while (loc[strlen("connectorId")+2+c] != ',')
  14255. {
  14256. sstr[c] = loc[strlen("connectorId")+2+c];
  14257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14258. c++;
  14259. }
  14260. sstr[c] = '\0';
  14261. tempconnectorIdInt = atoi(sstr);
  14262. #endif
  14263. //***********chargingProfileId**************/
  14264. c = 0;
  14265. loc = strstr(sLineWord, "chargingProfileId");
  14266. //DEBUG_INFO("loc=%s\n",loc);
  14267. memset(sstr ,0, sizeof(sstr) );
  14268. if(loc != NULL)
  14269. {
  14270. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14271. {
  14272. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14273. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14274. c++;
  14275. }
  14276. sstr[c] = '\0';
  14277. tempchargingProfileId = atoi(sstr);
  14278. }
  14279. else
  14280. {
  14281. tempchargingProfileId = 0;
  14282. }
  14283. //***********stackLevel**************/
  14284. c = 0;
  14285. loc = strstr(sLineWord, "stackLevel");
  14286. //DEBUG_INFO("loc=%s\n",loc);
  14287. memset(sstr ,0, sizeof(sstr) );
  14288. if(loc != NULL)
  14289. {
  14290. while (loc[2+strlen("stackLevel")+c] != '\"')
  14291. {
  14292. sstr[c] = loc[2+strlen("stackLevel")+c];
  14293. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14294. c++;
  14295. }
  14296. sstr[c] = '\0';
  14297. tempstackLevel = atoi(sstr);
  14298. }
  14299. else
  14300. {
  14301. tempstackLevel = 0;
  14302. }
  14303. //***********chargingProfilePurpose **************/
  14304. c = 0;
  14305. loc = strstr(sLineWord, "chargingProfilePurpose");
  14306. //DEBUG_INFO("loc=%s\n",loc);
  14307. memset(sstr ,0, sizeof(sstr) );
  14308. if(loc != NULL)
  14309. {
  14310. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14311. {
  14312. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14314. c++;
  14315. }
  14316. sstr[c] = '\0';
  14317. strcpy(tempchargingProfilePurposeStr,sstr);
  14318. }
  14319. else
  14320. {
  14321. strcpy(tempchargingProfilePurposeStr,"");
  14322. }
  14323. //***********chargingProfileKind **************/
  14324. c = 0;
  14325. loc = strstr(sLineWord, "chargingProfileKind");
  14326. //DEBUG_INFO("loc=%s\n",loc);
  14327. memset(sstr ,0, sizeof(sstr) );
  14328. if(loc != NULL)
  14329. {
  14330. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14331. {
  14332. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14333. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14334. c++;
  14335. }
  14336. sstr[c] = '\0';
  14337. strcpy(tempchargingProfileKindStr,sstr);
  14338. }
  14339. else
  14340. {
  14341. strcpy(tempchargingProfileKindStr,"");
  14342. }
  14343. //***********recurrencyKind **************/
  14344. c = 0;
  14345. loc = strstr(sLineWord, "recurrencyKind");
  14346. //DEBUG_INFO("loc=%s\n",loc);
  14347. memset(sstr ,0, sizeof(sstr) );
  14348. if(loc != NULL)
  14349. {
  14350. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14351. {
  14352. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14353. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14354. c++;
  14355. }
  14356. sstr[c] = '\0';
  14357. strcpy(temprecurrencyKindStr,sstr);
  14358. }
  14359. else
  14360. {
  14361. strcpy(temprecurrencyKindStr,"");
  14362. }
  14363. //***********validFrom**************/
  14364. c = 0;
  14365. loc = strstr(sLineWord, "validFrom");
  14366. if(loc != NULL)
  14367. {
  14368. memset(sstr ,0, sizeof(sstr) );
  14369. while (loc[3+strlen("validFrom")+c] != '\"')
  14370. {
  14371. sstr[c] = loc[3+strlen("validFrom")+c];
  14372. c++;
  14373. }
  14374. sstr[c] = '\0';
  14375. strcpy(tempvalidFromStr,sstr);
  14376. }
  14377. else
  14378. {
  14379. strcpy(tempvalidFromStr,"");
  14380. }
  14381. //***********validTo **************/
  14382. c = 0;
  14383. loc = strstr(sLineWord, "validTo");
  14384. if(loc != NULL)
  14385. {
  14386. memset(sstr ,0, sizeof(sstr) );
  14387. while (loc[3+strlen("validTo")+c] != '\"')
  14388. {
  14389. sstr[c] = loc[3+strlen("validTo")+c];
  14390. c++;
  14391. }
  14392. sstr[c] = '\0';
  14393. strcpy(tempvalidToStr,sstr);
  14394. }
  14395. else
  14396. {
  14397. strcpy(tempvalidToStr,"");
  14398. }
  14399. //***********duration**************/
  14400. c = 0;
  14401. loc = strstr(sLineWord, "duration");
  14402. if(loc != NULL)
  14403. {
  14404. memset(sstr ,0, sizeof(sstr) );
  14405. while (loc[2+strlen("duration")+c] != ',')
  14406. {
  14407. sstr[c] = loc[2+strlen("duration")+c];
  14408. c++;
  14409. }
  14410. sstr[c] = '\0';
  14411. tempdurationInt = atoi(sstr);
  14412. }
  14413. else
  14414. {
  14415. tempdurationInt = 0;
  14416. }
  14417. //**********startSchedule**********/
  14418. c = 0;
  14419. loc = strstr(sLineWord, "startSchedule");
  14420. if(loc != NULL)
  14421. {
  14422. memset(sstr ,0, sizeof(sstr) );
  14423. while (loc[3+strlen("startSchedule")+c] != '\"')
  14424. {
  14425. sstr[c] = loc[3+strlen("startSchedule")+c];
  14426. c++;
  14427. }
  14428. sstr[c] = '\0';
  14429. strcpy(tempstartScheduleStr, sstr);
  14430. strcpy(TxDefaultProfileScheduleStr, sstr);
  14431. }
  14432. else
  14433. {
  14434. strcpy(tempstartScheduleStr, "");
  14435. strcpy(TxDefaultProfileScheduleStr, "");
  14436. }
  14437. //**********chargingRateUnit**********/
  14438. c = 0;
  14439. loc = strstr(sLineWord, "chargingRateUnit");
  14440. memset(sstr ,0, sizeof(sstr) );
  14441. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14442. {
  14443. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14444. c++;
  14445. }
  14446. sstr[c] = '\0';
  14447. strcpy(tempchargingRateUnitStr, sstr);
  14448. //**********minChargingRate*******/
  14449. c = 0;
  14450. loc = strstr(sLineWord, "minChargingRate");
  14451. if(loc != NULL)
  14452. {
  14453. memset(sstr ,0, sizeof(sstr) );
  14454. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14455. {
  14456. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14457. c++;
  14458. }
  14459. sstr[c] = '\0';
  14460. tempminChargingRateFloat = atof(sstr);
  14461. }
  14462. else
  14463. {
  14464. tempminChargingRateFloat = 0.0;
  14465. }
  14466. //
  14467. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14468. tp.tm_isdst = -1;
  14469. time_t utc = mktime(&tp);
  14470. time_t t = time(NULL);
  14471. diff_t = difftime(t, utc);
  14472. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14473. //parsing strings to words
  14474. i = 0;
  14475. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14476. loc = loc+3+strlen("chargingSchedulePeriod");
  14477. pch = strtok(loc ,"{");
  14478. while (pch != NULL)
  14479. {
  14480. strcpy(SchedulePeriodList[i], pch);
  14481. pch = strtok (NULL, "{");
  14482. i = i + 1;
  14483. }
  14484. n_SchedulePeriods = i;
  14485. for(int i=0;i<n_SchedulePeriods;i++)
  14486. {
  14487. //*************startPeriod****************/
  14488. c = 0;
  14489. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14490. memset(sstr ,0, sizeof(sstr) );
  14491. while (loc[strlen("startPeriod")+2+c] != ',')
  14492. {
  14493. sstr[c] = loc[strlen("startPeriod")+2+c];
  14494. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14495. c++;
  14496. }
  14497. sstr[c] = '\0';
  14498. tempStartPeriodInt = atoi(sstr);
  14499. //*************limit****************/
  14500. c = 0;
  14501. loc = strstr(SchedulePeriodList[i], "limit");
  14502. memset(sstr ,0, sizeof(sstr) );
  14503. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14504. {
  14505. sstr[c] = loc[strlen("limit")+2+c];
  14506. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14507. c++;
  14508. }
  14509. sstr[c] = '\0';
  14510. tempLimitInt = atof(sstr);
  14511. //*************numberPhases****************/
  14512. c = 0;
  14513. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14514. memset(sstr ,0, sizeof(sstr) );
  14515. if(loc != NULL)
  14516. {
  14517. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14518. {
  14519. sstr[c] = loc[strlen("numberPhases")+2+c];
  14520. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14521. c++;
  14522. }
  14523. sstr[c] = '\0';
  14524. tempNumberPhasesInt = atoi(sstr);
  14525. }
  14526. else
  14527. {
  14528. tempNumberPhasesInt = 0;
  14529. }
  14530. if(j == 0)
  14531. {
  14532. TxDefaultProfile.Duration = tempdurationInt;
  14533. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14534. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14535. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14536. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14537. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14538. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14539. TxDefaultProfile_TEMP.TransactionId = 0;
  14540. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14541. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14542. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14543. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14544. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14545. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14546. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14547. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14548. }
  14549. else
  14550. {
  14551. //other stack level charging Profile
  14552. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14553. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14554. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14555. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14556. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14557. }
  14558. }
  14559. if(MinChargingRate < tempminChargingRateFloat)
  14560. {
  14561. MinChargingRate = tempminChargingRateFloat;
  14562. }
  14563. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14564. if(confirmPeriods < n_SchedulePeriods)
  14565. confirmPeriods = n_SchedulePeriods;
  14566. j = j + 1;
  14567. }
  14568. fclose(fptr1);
  14569. //Stacking Charging Profiles
  14570. for(int l=0; l <(j-1) ;l++)
  14571. {
  14572. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14573. {
  14574. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14575. {
  14576. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14577. {
  14578. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14579. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14580. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14581. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14582. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14583. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14584. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14585. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14586. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14587. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14588. }
  14589. else
  14590. {
  14591. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14592. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14593. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14594. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14595. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14596. }
  14597. }
  14598. }
  14599. }//end of Stacking Charging Profiles
  14600. }// end else
  14601. }// the end of ACCESS TxDefaultProfile
  14602. //****************************TxProfile************************************************/
  14603. memset(fname, 0, sizeof fname);
  14604. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14605. TxProfileIsNull=TRUE;
  14606. if((access(fname,F_OK))!=-1)
  14607. {
  14608. fptr1 = fopen(fname, "r");
  14609. c = 0;
  14610. c = fgetc(fptr1);
  14611. //DEBUG_INFO("c:%d\n",c);
  14612. rewind(fptr1);
  14613. if(c == EOF)
  14614. {
  14615. DEBUG_INFO("\n End of file reached.");
  14616. TxProfileIsNull=TRUE;
  14617. fclose(fptr1);
  14618. }
  14619. else
  14620. {
  14621. TxProfileIsNull=FALSE;
  14622. while(fscanf(fptr1, "%s", word) != EOF)
  14623. {
  14624. if(strcmp(word, "chargingProfileId") == 0)
  14625. {
  14626. n_chargingProfile = n_chargingProfile + 1;
  14627. }
  14628. }
  14629. rewind(fptr1);
  14630. //search Charging Profile Element
  14631. int i= 0;
  14632. int j= 0;
  14633. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14634. #if 0
  14635. /***********connectorId****************/
  14636. c = 0;
  14637. loc = strstr(sLineWord, "connectorId");
  14638. memset(sstr ,0, sizeof(sstr) );
  14639. while (loc[strlen("connectorId")+2+c] != ',')
  14640. {
  14641. sstr[c] = loc[strlen("connectorId")+2+c];
  14642. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14643. c++;
  14644. }
  14645. sstr[c] = '\0';
  14646. tempconnectorIdInt = atoi(sstr);
  14647. #endif
  14648. //***********chargingProfileId**************/
  14649. c = 0;
  14650. loc = strstr(sLineWord, "chargingProfileId");
  14651. memset(sstr ,0, sizeof(sstr) );
  14652. if(loc != NULL)
  14653. {
  14654. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14655. {
  14656. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14657. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14658. c++;
  14659. }
  14660. sstr[c] = '\0';
  14661. tempchargingProfileId = atoi(sstr);
  14662. }
  14663. else
  14664. {
  14665. tempchargingProfileId = 0;
  14666. }
  14667. //***********transactionId **************/
  14668. c = 0;
  14669. loc = strstr(sLineWord, "transactionId");
  14670. //DEBUG_INFO("loc=%s\n",loc);
  14671. memset(sstr ,0, sizeof(sstr) );
  14672. if(loc != NULL)
  14673. {
  14674. while (loc[2+strlen("transactionId")+c] != '\"')
  14675. {
  14676. sstr[c] = loc[2+strlen("transactionId")+c];
  14677. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14678. c++;
  14679. }
  14680. sstr[c] = '\0';
  14681. temptransactionId = atoi(sstr);
  14682. }
  14683. else
  14684. {
  14685. temptransactionId = 0;
  14686. }
  14687. //***********stackLevel**************/
  14688. c = 0;
  14689. loc = strstr(sLineWord, "stackLevel");
  14690. //DEBUG_INFO("loc=%s\n",loc);
  14691. memset(sstr ,0, sizeof(sstr) );
  14692. if(loc != NULL)
  14693. {
  14694. while (loc[2+strlen("stackLevel")+c] != '\"')
  14695. {
  14696. sstr[c] = loc[2+strlen("stackLevel")+c];
  14697. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14698. c++;
  14699. }
  14700. sstr[c] = '\0';
  14701. tempstackLevel = atoi(sstr);
  14702. }
  14703. else
  14704. {
  14705. tempstackLevel = 0;
  14706. }
  14707. //***********chargingProfilePurpose **************/
  14708. c = 0;
  14709. loc = strstr(sLineWord, "chargingProfilePurpose");
  14710. //DEBUG_INFO("loc=%s\n",loc);
  14711. memset(sstr ,0, sizeof(sstr) );
  14712. if(loc != NULL)
  14713. {
  14714. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14715. {
  14716. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14717. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14718. c++;
  14719. }
  14720. sstr[c] = '\0';
  14721. strcpy(tempchargingProfilePurposeStr,sstr);
  14722. }
  14723. else
  14724. {
  14725. strcpy(tempchargingProfilePurposeStr,"");
  14726. }
  14727. //***********chargingProfileKind **************/
  14728. c = 0;
  14729. loc = strstr(sLineWord, "chargingProfileKind");
  14730. //DEBUG_INFO("loc=%s\n",loc);
  14731. memset(sstr ,0, sizeof(sstr) );
  14732. if(loc != NULL)
  14733. {
  14734. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14735. {
  14736. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14737. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14738. c++;
  14739. }
  14740. sstr[c] = '\0';
  14741. strcpy(tempchargingProfileKindStr,sstr);
  14742. }
  14743. else
  14744. {
  14745. strcpy(tempchargingProfileKindStr,"");
  14746. }
  14747. //***********recurrencyKind **************/
  14748. c = 0;
  14749. loc = strstr(sLineWord, "recurrencyKind");
  14750. //DEBUG_INFO("loc=%s\n",loc);
  14751. memset(sstr ,0, sizeof(sstr) );
  14752. if(loc != NULL)
  14753. {
  14754. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14755. {
  14756. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14757. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14758. c++;
  14759. }
  14760. sstr[c] = '\0';
  14761. strcpy(temprecurrencyKindStr,sstr);
  14762. }
  14763. else
  14764. {
  14765. strcpy(temprecurrencyKindStr,"");
  14766. }
  14767. //***********validFrom**************/
  14768. c = 0;
  14769. loc = strstr(sLineWord, "validFrom");
  14770. if(loc != NULL)
  14771. {
  14772. memset(sstr ,0, sizeof(sstr) );
  14773. while (loc[3+strlen("validFrom")+c] != '\"')
  14774. {
  14775. sstr[c] = loc[3+strlen("validFrom")+c];
  14776. c++;
  14777. }
  14778. sstr[c] = '\0';
  14779. strcpy(tempvalidFromStr,sstr);
  14780. }
  14781. else
  14782. {
  14783. strcpy(tempvalidFromStr,"");
  14784. }
  14785. //***********validTo**************/
  14786. c = 0;
  14787. loc = strstr(sLineWord, "validTo");
  14788. if(loc != NULL)
  14789. {
  14790. memset(sstr ,0, sizeof(sstr) );
  14791. while (loc[3+strlen("validTo")+c] != '\"')
  14792. {
  14793. sstr[c] = loc[3+strlen("validTo")+c];
  14794. c++;
  14795. }
  14796. sstr[c] = '\0';
  14797. strcpy(tempvalidToStr,sstr);
  14798. }
  14799. else
  14800. {
  14801. strcpy(tempvalidToStr,"");
  14802. }
  14803. //***********duration**************/
  14804. c = 0;
  14805. loc = strstr(sLineWord, "duration");
  14806. //DEBUG_INFO("loc=%s\n",loc);
  14807. memset(sstr ,0, sizeof(sstr) );
  14808. if(loc != NULL)
  14809. {
  14810. while (loc[2+strlen("duration")+c] != '\"')
  14811. {
  14812. sstr[c] = loc[2+strlen("duration")+c];
  14813. c++;
  14814. }
  14815. sstr[c] = '\0';
  14816. tempdurationInt = atoi(sstr);
  14817. }
  14818. else
  14819. {
  14820. tempdurationInt = 0;
  14821. }
  14822. //**********startSchedule**********/
  14823. c = 0;
  14824. loc = strstr(sLineWord, "startSchedule");
  14825. if(loc != NULL)
  14826. {
  14827. memset(sstr ,0, sizeof(sstr) );
  14828. while (loc[3+strlen("startSchedule")+c] != '\"')
  14829. {
  14830. sstr[c] = loc[3+strlen("startSchedule")+c];
  14831. c++;
  14832. }
  14833. sstr[c] = '\0';
  14834. strcpy(tempstartScheduleStr, sstr);
  14835. strcpy(TxProfileScheduleStr, sstr);
  14836. }
  14837. else
  14838. {
  14839. strcpy(tempstartScheduleStr, "");
  14840. strcpy(TxProfileScheduleStr, "");
  14841. }
  14842. //**********chargingRateUnit**********/
  14843. c = 0;
  14844. loc = strstr(sLineWord, "chargingRateUnit");
  14845. memset(sstr ,0, sizeof(sstr) );
  14846. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14847. {
  14848. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14849. c++;
  14850. }
  14851. sstr[c] = '\0';
  14852. strcpy(tempchargingRateUnitStr, sstr);
  14853. //**********minChargingRate*******/
  14854. c = 0;
  14855. loc = strstr(sLineWord, "minChargingRate");
  14856. if(loc != NULL)
  14857. {
  14858. memset(sstr ,0, sizeof(sstr) );
  14859. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14860. {
  14861. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14862. c++;
  14863. }
  14864. sstr[c] = '\0';
  14865. tempminChargingRateFloat = atof(sstr);
  14866. }
  14867. else
  14868. {
  14869. tempminChargingRateFloat = 0.0;
  14870. }
  14871. //
  14872. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14873. tp.tm_isdst = -1;
  14874. time_t utc = mktime(&tp);
  14875. time_t t = time(NULL);
  14876. diff_t = difftime(t, utc);
  14877. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14878. //parsing strings to words
  14879. i = 0;
  14880. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14881. loc = loc+3+strlen("chargingSchedulePeriod");
  14882. pch = strtok(loc ,"{");
  14883. while (pch != NULL)
  14884. {
  14885. strcpy(SchedulePeriodList[i], pch);
  14886. pch = strtok (NULL, "{");
  14887. i = i + 1;
  14888. }
  14889. n_SchedulePeriods = i;
  14890. for(int i=0;i<n_SchedulePeriods;i++)
  14891. {
  14892. //*************startPeriod****************/
  14893. c = 0;
  14894. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14895. memset(sstr ,0, sizeof(sstr) );
  14896. while (loc[strlen("startPeriod")+2+c] != ',')
  14897. {
  14898. sstr[c] = loc[strlen("startPeriod")+2+c];
  14899. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14900. c++;
  14901. }
  14902. sstr[c] = '\0';
  14903. tempStartPeriodInt = atoi(sstr);
  14904. //*************limit****************/
  14905. c = 0;
  14906. loc = strstr(SchedulePeriodList[i], "limit");
  14907. memset(sstr ,0, sizeof(sstr) );
  14908. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14909. {
  14910. sstr[c] = loc[strlen("limit")+2+c];
  14911. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14912. c++;
  14913. }
  14914. sstr[c] = '\0';
  14915. tempLimitInt = atof(sstr);
  14916. //*************numberPhases****************/
  14917. c = 0;
  14918. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14919. memset(sstr ,0, sizeof(sstr) );
  14920. if(loc != NULL)
  14921. {
  14922. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14923. {
  14924. sstr[c] = loc[strlen("numberPhases")+2+c];
  14925. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14926. c++;
  14927. }
  14928. sstr[c] = '\0';
  14929. tempNumberPhasesInt = atoi(sstr);
  14930. }
  14931. else
  14932. {
  14933. tempNumberPhasesInt = 0;
  14934. }
  14935. //TxProfile.Duration = durationInt;
  14936. TxProfile.TotalPeriod = n_SchedulePeriods;
  14937. TxProfile.Period[i].Limit = tempLimitInt;
  14938. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14939. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14940. }
  14941. if(MinChargingRate < tempminChargingRateFloat)
  14942. {
  14943. MinChargingRate = tempminChargingRateFloat;
  14944. }
  14945. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14946. if(confirmPeriods < n_SchedulePeriods)
  14947. confirmPeriods = n_SchedulePeriods;
  14948. if(j == 0)
  14949. {
  14950. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14951. TxProfile_TEMP.StackLevel = tempstackLevel;
  14952. TxProfile_TEMP.TransactionId = 0;
  14953. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14954. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14955. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14956. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14957. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14958. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14959. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14960. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14961. }
  14962. }
  14963. fclose(fptr1);
  14964. }
  14965. }// the end of ACCESS TxProfile
  14966. //-----------------------------------------------CompositeSchedule--------------------------//
  14967. int period=0;
  14968. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  14969. {
  14970. //TxProfile
  14971. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  14972. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  14973. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  14974. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  14975. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  14976. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  14977. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  14978. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  14979. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  14980. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  14981. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  14982. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  14983. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  14984. for(int k=0; k < TxProfile.TotalPeriod;k++)
  14985. {
  14986. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  14987. {
  14988. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14989. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14990. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14991. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  14992. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  14993. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  14994. period = period + 1;
  14995. }
  14996. else
  14997. {
  14998. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  14999. {
  15000. }
  15001. else
  15002. {
  15003. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15004. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15005. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15006. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15007. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15008. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15009. period = period + 1;
  15010. }
  15011. }
  15012. }
  15013. struct tm tp;
  15014. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15015. tp.tm_isdst = -1;
  15016. time_t utc = mktime(&tp);
  15017. time_t t = time(NULL);
  15018. double diff_f = difftime(t, utc);
  15019. int diff_i;// = (int)diff_f;
  15020. int quotient; // = diff_i / 86400;//86400 seconds/day
  15021. if(diff_f >= 0)
  15022. {
  15023. diff_i = (int)diff_f;
  15024. quotient = diff_i / 86400;//86400 seconds/day
  15025. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15026. {
  15027. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15028. {
  15029. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15030. {
  15031. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15032. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15033. }
  15034. else
  15035. {
  15036. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15037. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15038. }
  15039. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15040. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15041. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15042. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15043. period = period + 1;
  15044. }
  15045. }
  15046. }// end of if(diff_f >= 0)
  15047. }
  15048. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15049. {
  15050. //TxDefaultProfile
  15051. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15052. struct tm tp;
  15053. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15054. tp.tm_isdst = -1;
  15055. time_t utc = mktime(&tp);
  15056. time_t t = time(NULL);
  15057. double diff_f = difftime(t, utc);
  15058. int diff_i;// = (int)diff_f;
  15059. int quotient; // = diff_i / 86400;//86400 seconds/day
  15060. int remainder;
  15061. //---- Define StartSchedule----/
  15062. struct tm *gtime;
  15063. time_t now;
  15064. char buf[28];
  15065. //---Read the current system time---/
  15066. time(&now);
  15067. //---Convert the system time to GMT (now UTC)---/
  15068. gtime = gmtime(&now);
  15069. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15070. if(diff_f >= 0)
  15071. {
  15072. diff_i = (int)diff_f;
  15073. quotient = diff_i / 86400;//86400 seconds/day
  15074. remainder = diff_i % 86400;
  15075. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15076. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15077. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15078. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15079. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15080. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15081. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15082. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15083. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15084. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15085. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15086. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15087. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15088. {
  15089. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15090. {
  15091. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15092. {
  15093. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15094. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15095. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15096. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15097. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15098. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15099. period = period + 1;
  15100. }
  15101. else
  15102. {
  15103. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15104. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15105. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15106. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15107. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15108. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15109. period = period + 1;
  15110. }
  15111. }
  15112. }
  15113. } // end of diff_f >= 0
  15114. }
  15115. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15116. {
  15117. //TxDefaultProfile
  15118. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15119. struct tm tp;
  15120. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15121. tp.tm_isdst = -1;
  15122. time_t utc = mktime(&tp);
  15123. time_t t = time(NULL);
  15124. double diff_f = difftime(t, utc);
  15125. int diff_i;// = (int)diff_f;
  15126. int quotient; // = diff_i / 86400;//86400 seconds/day
  15127. int remainder;
  15128. //---- Define StartSchedule----/
  15129. struct tm *gtime;
  15130. time_t now;
  15131. char buf[28];
  15132. //---Read the current system time---/
  15133. time(&now);
  15134. //---Convert the system time to GMT (now UTC)---/
  15135. gtime = gmtime(&now);
  15136. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15137. if(diff_f >= 0)
  15138. {
  15139. diff_i = (int)diff_f;
  15140. quotient = diff_i / 86400;//86400 seconds/day
  15141. remainder = diff_i % 86400;
  15142. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15143. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15144. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15145. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15146. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15147. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15148. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15149. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15150. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15151. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15152. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15153. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15154. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15155. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15156. {
  15157. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15158. {
  15159. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15160. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15161. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15162. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15163. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15164. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15165. period = period + 1;
  15166. }
  15167. }
  15168. } //end of diff_f >= 0
  15169. }
  15170. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15171. {
  15172. //ChargePointMaxProfile
  15173. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15174. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15175. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15176. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15177. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15178. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15179. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15180. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15181. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15182. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15183. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15184. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15185. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15186. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15187. {
  15188. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15189. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15190. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15191. period = period + 1;
  15192. }
  15193. }
  15194. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15195. {
  15196. //TxProfile Daily
  15197. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15198. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15199. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15200. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15201. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15202. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15203. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15204. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15205. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15206. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15207. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15208. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15209. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15210. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15211. {
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15213. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15214. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15215. }
  15216. }
  15217. confirmPeriods = period;
  15218. if(confirmPeriods != 0)
  15219. {
  15220. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15221. 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,"
  15222. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15223. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15224. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15225. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15226. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15227. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15228. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15229. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15230. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15231. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15232. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15233. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15234. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15235. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15238. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15239. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15240. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15241. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15242. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15243. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15244. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15245. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15246. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15247. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15248. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15249. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15250. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15251. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15252. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15253. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15254. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15255. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15256. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15257. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15258. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15259. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15260. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15261. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15262. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15263. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15264. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15265. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15266. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15267. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15268. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15269. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15270. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15271. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15272. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15273. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15274. }
  15275. }
  15276. void storeTempStopTransaction(int gun_index)
  15277. {
  15278. //int result = FAIL;
  15279. //char message[1500]={0};
  15280. char guid[37]={0};
  15281. int tempIndex = 0;
  15282. //char tempdata[65]={0};
  15283. //int idx_sample=0;
  15284. DEBUG_ERROR("sendStopTransactionRequest \n");
  15285. memset(queuedata, 0, sizeof(queuedata));
  15286. //ENERGY_ACTIVE_IMPORT_REGISTER
  15287. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15288. if(gunType[gun_index] == 'J')
  15289. {
  15290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15291. {
  15292. tempIndex = ((gun_index==2) ? 1: 0);
  15293. }
  15294. else
  15295. {
  15296. tempIndex = gun_index;
  15297. }
  15298. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15299. {
  15300. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15301. {
  15302. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  15303. }
  15304. }// END OF CHAdeMO_QUANTITY
  15305. }
  15306. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15307. {
  15308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15309. {
  15310. tempIndex = ((gun_index==2) ? 1: 0);
  15311. }
  15312. else
  15313. {
  15314. tempIndex = gun_index;
  15315. }
  15316. for (int index = 0; index < CCS_QUANTITY; index++)
  15317. {
  15318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15319. {
  15320. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  15321. }
  15322. }// END OF CCS_QUANTITY
  15323. }
  15324. else if(gunType[gun_index] == 'G')
  15325. {
  15326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15327. {
  15328. tempIndex = ((gun_index==2) ? 1: 0);
  15329. }
  15330. else
  15331. {
  15332. tempIndex = gun_index;
  15333. }
  15334. for (int index = 0; index < GB_QUANTITY; index++)
  15335. {
  15336. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15337. {
  15338. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  15339. }
  15340. }// END OF GB_QUANTITY
  15341. }
  15342. else
  15343. {
  15344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15345. {
  15346. tempIndex = 2;
  15347. }
  15348. else
  15349. {
  15350. tempIndex = gun_index;
  15351. }
  15352. for (int index = 0; index < AC_QUANTITY; index++)
  15353. {
  15354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15355. {
  15356. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15357. }
  15358. }// END OF AC_QUANTITY
  15359. }
  15360. //Stop Transaction Time
  15361. struct timeval tmnow;
  15362. struct tm *tm;
  15363. char buf[28];//, usec_buf[6];
  15364. gettimeofday(&tmnow, NULL);
  15365. time_t t;
  15366. t = time(NULL);
  15367. /*UTC time and date*/
  15368. tm = gmtime(&t);
  15369. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15371. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15372. random_uuid(guid);
  15373. /***********************************transactionData******************************************************/
  15374. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15376. //=================================
  15377. // Transaction_Begin
  15378. //=================================
  15379. // Energy.Active.Export.Interval
  15380. //idx_sample=0;
  15381. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15384. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  15385. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15386. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15387. {
  15388. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15389. }
  15390. else
  15391. {
  15392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15393. }
  15394. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15395. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15396. //=================================
  15397. // Transaction_End
  15398. //=================================
  15399. //Current.Export
  15400. //idx_sample=1;
  15401. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15402. if(gunType[gun_index] == 'J')
  15403. {
  15404. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15405. {
  15406. tempIndex = ((gun_index==2) ? 1: 0);
  15407. }
  15408. else
  15409. {
  15410. tempIndex = gun_index;
  15411. }
  15412. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15413. {
  15414. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15415. {
  15416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15417. }
  15418. }// End of for CHAdeMO_QUANTITY
  15419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15420. }
  15421. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15422. {
  15423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15424. {
  15425. tempIndex = ((gun_index==2) ? 1: 0);
  15426. }
  15427. else
  15428. {
  15429. tempIndex = gun_index;
  15430. }
  15431. for (int index = 0; index < CCS_QUANTITY; index++)
  15432. {
  15433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15434. {
  15435. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15436. }
  15437. }// End of for CCS_QUANTITY
  15438. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15439. }
  15440. else if(gunType[gun_index] == 'G')
  15441. {
  15442. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15443. {
  15444. tempIndex = ((gun_index==2) ? 1: 0);
  15445. }
  15446. else
  15447. {
  15448. tempIndex = gun_index;
  15449. }
  15450. for (int index = 0; index < GB_QUANTITY; index++)
  15451. {
  15452. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15453. {
  15454. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15455. }
  15456. }// End of for GB_QUANTITY
  15457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15458. }
  15459. else
  15460. {
  15461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15462. {
  15463. tempIndex = 2;
  15464. }
  15465. else
  15466. {
  15467. tempIndex = gun_index;
  15468. }
  15469. for (int index = 0; index < AC_QUANTITY; index++)
  15470. {
  15471. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15472. {
  15473. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15474. }
  15475. }// End of for AC_QUANTITY
  15476. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15477. }
  15478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15480. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15481. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15484. //Energy.Active.Export.Interval
  15485. //idx_sample=2;
  15486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15487. if(gunType[gun_index] == 'J')
  15488. {
  15489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15490. {
  15491. tempIndex = ((gun_index==2) ? 1: 0);
  15492. }
  15493. else
  15494. {
  15495. tempIndex = gun_index;
  15496. }
  15497. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15498. {
  15499. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15500. {
  15501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15502. }
  15503. }// END OF CHAdeMO_QUANTITY
  15504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15505. }
  15506. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15507. {
  15508. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15509. {
  15510. tempIndex = ((gun_index==2) ? 1: 0);
  15511. }
  15512. else
  15513. {
  15514. tempIndex = gun_index;
  15515. }
  15516. for (int index = 0; index < CCS_QUANTITY; index++)
  15517. {
  15518. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15519. {
  15520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15521. }
  15522. }// END OF CCS_QUANTITY
  15523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15524. }
  15525. else if(gunType[gun_index] == 'G')
  15526. {
  15527. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15528. {
  15529. tempIndex = ((gun_index==2) ? 1: 0);
  15530. }
  15531. else
  15532. {
  15533. tempIndex = gun_index;
  15534. }
  15535. for (int index = 0; index < GB_QUANTITY; index++)
  15536. {
  15537. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15538. {
  15539. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15540. }
  15541. }// END OF GB_QUANTITY
  15542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15543. }
  15544. else
  15545. {
  15546. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15547. {
  15548. tempIndex = 2;
  15549. }
  15550. else
  15551. {
  15552. tempIndex = gun_index;
  15553. }
  15554. for (int index = 0; index < AC_QUANTITY; index++)
  15555. {
  15556. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15557. {
  15558. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15559. }
  15560. }// END OF AC_QUANTITY
  15561. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15562. }
  15563. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15564. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15565. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15566. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15567. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15569. //Power.Active.Export
  15570. //idx_sample=3;
  15571. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15572. if(gunType[gun_index] == 'J')
  15573. {
  15574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15575. {
  15576. tempIndex = ((gun_index==2) ? 1: 0);
  15577. }
  15578. else
  15579. {
  15580. tempIndex = gun_index;
  15581. }
  15582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15583. {
  15584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15585. {
  15586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15587. }
  15588. } // End for CHAdeMO_QUANTITY
  15589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15590. }
  15591. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15592. {
  15593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15594. {
  15595. tempIndex = ((gun_index==2) ? 1: 0);
  15596. }
  15597. else
  15598. {
  15599. tempIndex = gun_index;
  15600. }
  15601. for (int index = 0; index < CCS_QUANTITY; index++)
  15602. {
  15603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15604. {
  15605. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15606. }
  15607. } // END for CCS_QUANTITY
  15608. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15609. }
  15610. else if(gunType[gun_index] == 'G')
  15611. {
  15612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15613. {
  15614. tempIndex = ((gun_index==2) ? 1: 0);
  15615. }
  15616. else
  15617. {
  15618. tempIndex = gun_index;
  15619. }
  15620. for (int index = 0; index < GB_QUANTITY; index++)
  15621. {
  15622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15623. {
  15624. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15625. }
  15626. }// END for GB_QUANTITY
  15627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15628. }
  15629. else
  15630. {
  15631. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15632. {
  15633. tempIndex = 2;
  15634. }
  15635. else
  15636. {
  15637. tempIndex = gun_index;
  15638. }
  15639. for (int index = 0; index < AC_QUANTITY; index++)
  15640. {
  15641. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15642. {
  15643. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15644. }
  15645. } // END for AC_QUANTITY
  15646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15647. }
  15648. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15649. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15650. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15651. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15652. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15654. //Voltage
  15655. //idx_sample=4;
  15656. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15657. if(gunType[gun_index] == 'J')
  15658. {
  15659. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15660. {
  15661. tempIndex = ((gun_index==2) ? 1: 0);
  15662. }
  15663. else
  15664. {
  15665. tempIndex = gun_index;
  15666. }
  15667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15668. {
  15669. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15670. {
  15671. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15672. }
  15673. } // END OF FOR CHAdeMO_QUANTITY
  15674. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15675. }
  15676. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15677. {
  15678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15679. {
  15680. tempIndex = ((gun_index==2) ? 1: 0);
  15681. }
  15682. else
  15683. {
  15684. tempIndex = gun_index;
  15685. }
  15686. for (int index = 0; index < CCS_QUANTITY; index++)
  15687. {
  15688. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15689. {
  15690. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15691. }
  15692. } // END OF FOR CCS_QUANTITY
  15693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15694. }
  15695. else if(gunType[gun_index] == 'G')
  15696. {
  15697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15698. {
  15699. tempIndex = ((gun_index==2) ? 1: 0);
  15700. }
  15701. else
  15702. {
  15703. tempIndex = gun_index;
  15704. }
  15705. for (int index = 0; index < GB_QUANTITY; index++)
  15706. {
  15707. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15708. {
  15709. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15710. }
  15711. } // END OF FOR GB_QUANTITY
  15712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15713. }
  15714. else
  15715. {
  15716. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15717. {
  15718. tempIndex = 2;
  15719. }
  15720. else
  15721. {
  15722. tempIndex = gun_index;
  15723. }
  15724. for (int index = 0; index < AC_QUANTITY; index++)
  15725. {
  15726. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15727. {
  15728. 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
  15729. }
  15730. } // END OF FOR AC_QUANTITY
  15731. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15732. }
  15733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15734. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15736. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15739. //SoC
  15740. //idx_sample=5;
  15741. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15742. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15743. {
  15744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15745. {
  15746. tempIndex = ((gun_index==2) ? 1: 0);
  15747. }
  15748. else
  15749. {
  15750. tempIndex = gun_index;
  15751. }
  15752. if(gunType[gun_index] == 'J')
  15753. {
  15754. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15755. {
  15756. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15757. {
  15758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15759. }
  15760. }
  15761. }
  15762. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15763. {
  15764. for (int index = 0; index < CCS_QUANTITY; index++)
  15765. {
  15766. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15767. {
  15768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15769. }
  15770. }
  15771. }
  15772. else if(gunType[gun_index] == 'G')
  15773. {
  15774. for (int index = 0; index < GB_QUANTITY; index++)
  15775. {
  15776. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15777. {
  15778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15779. }
  15780. }
  15781. }
  15782. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15788. } // END FOR DC CASE
  15789. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15790. {
  15791. 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\"}]}]}]"
  15792. ,MESSAGE_TYPE_CALL
  15793. ,guid
  15794. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15795. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15796. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15798. ,"PowerLoss"
  15799. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15806. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15807. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15808. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15809. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15811. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15812. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15842. );
  15843. }
  15844. else
  15845. {
  15846. 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\"}]}]}]"
  15847. ,MESSAGE_TYPE_CALL
  15848. ,guid
  15849. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15850. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15851. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15853. ,"PowerLoss"
  15854. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15890. );
  15891. }
  15892. // Check File "TempStopTransaction" Exist
  15893. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  15894. {
  15895. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  15896. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  15897. }
  15898. else
  15899. {
  15900. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  15901. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  15902. if(log == NULL)
  15903. {
  15904. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  15905. return ;
  15906. }
  15907. else
  15908. {
  15909. fclose(log);
  15910. }
  15911. }
  15912. //Add TempStopTransaction | Update TempStopTransaction
  15913. // open file for writing
  15914. FILE *outfile;
  15915. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  15916. DEBUG_INFO("data=%s\n",queuedata);
  15917. fputs(queuedata, outfile);
  15918. fputs("\n", outfile);
  15919. fclose (outfile);
  15920. }
  15921. void checkTempStopTransaction(int gun_index)
  15922. {
  15923. FILE *fptr1;
  15924. char ch;
  15925. char str[1200]={0};
  15926. char guid[37]={0};
  15927. char tempdata[65]={0};
  15928. //=====================================================
  15929. // Check InternetConn 0: disconnected, 1: connected
  15930. //====================================================
  15931. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  15932. {
  15933. DEBUG_INFO("\n offline now !!!\n");
  15934. return;
  15935. }
  15936. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  15937. if (!fptr1)
  15938. {
  15939. //printf(" File not found or unable to open the input file!!\n");
  15940. return ;
  15941. }
  15942. ch=fgetc(fptr1);
  15943. //printf(" Now the content of the file %s is : \n",fname);
  15944. rewind(fptr1);
  15945. if(ch!=EOF)
  15946. {
  15947. // copy all contents to the temporary file except the specific line
  15948. while (fgets(str, 1200, fptr1) != NULL)
  15949. {
  15950. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15951. if(str[0]=='\0')
  15952. {
  15953. break;
  15954. }
  15955. random_uuid(guid);
  15956. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  15957. if(hashmap_operation(0, guid, tempdata) == 1)
  15958. {
  15959. DEBUG_INFO("StopTransaction mapitem pass\n");
  15960. }
  15961. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  15962. memset(str,0,sizeof str);
  15963. }
  15964. }
  15965. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15966. fclose(fptr1);
  15967. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  15968. }
  15969. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  15970. {
  15971. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  15972. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  15973. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  15974. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  15975. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  15976. }
  15977. int GetWebSocketPingInterval(void)
  15978. {
  15979. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  15980. }
  15981. int GetServerSign(void)
  15982. {
  15983. return server_sign;
  15984. }
  15985. void SetServerSign(int value)
  15986. {
  15987. server_sign = value;
  15988. }
  15989. int GetBootNotificationInterval(void)
  15990. {
  15991. return BootNotificationInterval;
  15992. }
  15993. int GetInternetConn(void)
  15994. {
  15995. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15996. }
  15997. void InitialSystemValue(void)
  15998. {
  15999. int connectorIndex = 0;
  16000. //int valueASCII = 0;
  16001. server_cycle_Status = 120;
  16002. gunTotalNumber=0;
  16003. SystemInitial = 0;
  16004. localversion=0;
  16005. BootNotificationInterval = 0;
  16006. authorizeRetryTimes = 0;
  16007. GunStatusInterval = 10;
  16008. TransactionMessageAttemptsValue = 0;
  16009. TransactionMessageRetryIntervalValue = 0;
  16010. //Hear Beat
  16011. HeartBeatWithNOResponse = 0;
  16012. HeartBeatCountPerHour = 0;
  16013. HeartBeatWaitTime = 10;
  16014. FirstHeartBeat = 0;
  16015. FirmwareStatusNotificationStatus = 3; // Idle
  16016. DiagnosticsStatusNotificationStatus = 0; // Idle
  16017. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16018. memset(statusModeChage, 0, sizeof(statusModeChage));
  16019. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16020. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16021. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16022. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16023. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16024. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16025. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16026. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16027. memset(gunType, 0, sizeof(gunType));
  16028. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16029. {
  16030. //check connector / socket type (index: 8, 9, 10)
  16031. for(int index=7; index <10 ; index++)
  16032. {
  16033. if(index != 8)
  16034. {
  16035. // DC Connector
  16036. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16037. {
  16038. SystemInitial = SystemInitial + 1;
  16039. gunTotalNumber = gunTotalNumber + 1;
  16040. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16041. connectorIndex = connectorIndex + 1;
  16042. }
  16043. }
  16044. else
  16045. {
  16046. // AC Connector
  16047. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16048. {
  16049. SystemInitial = SystemInitial + 1;
  16050. gunTotalNumber = gunTotalNumber + 1;
  16051. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16052. connectorIndex = connectorIndex + 1;
  16053. }
  16054. }
  16055. }
  16056. //DEBUG_INFO("DC ...\n");
  16057. }
  16058. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16059. {
  16060. //check connector / socket type (index: 8, 9, 10)
  16061. for(int index=7; index <10 ; index++)
  16062. {
  16063. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16064. {
  16065. SystemInitial = SystemInitial + 1;
  16066. gunTotalNumber = gunTotalNumber + 1;
  16067. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16068. connectorIndex = connectorIndex + 1;
  16069. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16070. }
  16071. }
  16072. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16073. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16074. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16075. //DEBUG_INFO("AC ...\n");
  16076. }
  16077. //Status && ConnectorPlugIn Setting
  16078. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16079. {
  16080. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16081. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16082. }
  16083. for (int index = 0; index < CCS_QUANTITY; index++)
  16084. {
  16085. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16086. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16087. }
  16088. for (int index = 0; index < GB_QUANTITY; index++)
  16089. {
  16090. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16091. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16092. }
  16093. for (int index = 0; index < AC_QUANTITY; index++)
  16094. {
  16095. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16096. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16097. }
  16098. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16099. {
  16100. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16101. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16102. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16103. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16104. }
  16105. // Charger PRE_SYS_MODE
  16106. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16107. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16108. clientTime.Heartbeat=time((time_t*)NULL);
  16109. sleep(1);
  16110. }
  16111. void LWS_Send(char * str)
  16112. {
  16113. //=====================================================
  16114. // Check InternetConn 0: disconnected, 1: connected
  16115. //====================================================
  16116. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16117. {
  16118. DEBUG_INFO("\n offline now !!!\n");
  16119. return;
  16120. }
  16121. pthread_mutex_lock(&lock);
  16122. memset(SendBuffer,0,SendBufLen);
  16123. sprintf((char *)SendBuffer, "%s", str);
  16124. pthread_mutex_unlock(&lock);
  16125. lws_callback_on_writable(wsi_client);
  16126. lws_service(context, 10000);//timeout_ms
  16127. }