MessageHandler.c 675 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809
  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. extern char StartTransactionIdTagTemp[20];
  113. static int OcppPort=0;
  114. //===============================
  115. // OCPP sign variable
  116. //===============================
  117. static int server_sign = FALSE;
  118. int server_pending = FALSE;
  119. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  120. static int BootNotificationInterval = 0;
  121. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  122. //===============================
  123. // OCPP auth variable
  124. //===============================
  125. static int authorizeRetryTimes = 0; //number of Retry times
  126. //===============================
  127. // OCPP StartTransaction transactionId variables
  128. //===============================
  129. //static int TransactionId[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  130. //===============================
  131. // OCPP other variables
  132. //===============================
  133. //int isUpdateRequest = FALSE;
  134. static int HeartBeatWaitTime = 10;
  135. static int FirstHeartBeat = 0;
  136. static int FirmwareStatusNotificationStatus = 3; // Idle
  137. static int DiagnosticsStatusNotificationStatus = 0; // Idle
  138. static char CurrentChargingProfileScheduleStr[30]={0};
  139. //========================================
  140. // OCPP status/previous related variables
  141. //========================================
  142. static int GunStatusInterval = 10;
  143. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  144. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  145. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  146. static int GbPreviousSystemStatus[GB_QUANTITY];
  147. static int AcPreviousSystemStatus[AC_QUANTITY];
  148. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  149. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  150. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  151. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  152. static int TransactionMessageAttemptsValue = 0;
  153. static int TransactionMessageRetryIntervalValue = 0;
  154. static int TempMeterValueInterval = 0;
  155. static struct OCPPAuthLocalElemet
  156. {
  157. int listVersionInt;
  158. char idTagstr[20];
  159. char parentIdTag[20];
  160. char expiryDate[30];
  161. char idTagstatus[16];
  162. }idTagQuery;
  163. //=============================================
  164. // OCPP HeartBeat Response Not Receive Counts
  165. //============================================
  166. static int HeartBeatWithNOResponse = 0;
  167. static int HeartBeatCountPerHour = 0;
  168. extern struct lws *wsi_client;
  169. extern struct lws_context *context;
  170. extern unsigned char SendBuffer[4096];
  171. extern int SendBufLen;
  172. extern char *random_uuid( char buf[37] );
  173. extern void split(char **arr, char *str, const char *del);
  174. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  175. extern int GetTransactionQueueNum(void);
  176. extern pthread_mutex_t mutex1;
  177. extern struct Charger_Info Charger;
  178. extern sqlite3 *db;
  179. int TransactionMessageAttemptsGet(void);
  180. int TransactionMessageRetryIntervalGet(void);
  181. int GetOcppConnStatus(void);
  182. void SetOcppConnStatus(uint8_t status);
  183. int updateSetting(char *key, char *value);
  184. int setKeyValue(char *key, char *value);
  185. void OCPP_get_TableAuthlocalAllData(void);
  186. void processUnkownKey(void);
  187. struct StructOCPPMeterValue
  188. {
  189. unsigned char TimeStamp[28];
  190. struct StructSampledValue SampledValue[10];
  191. };
  192. struct ClientTime
  193. {
  194. unsigned int Heartbeat;
  195. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  196. unsigned int StartTransaction;
  197. unsigned int StopTransaction;
  198. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  199. }clientTime;
  200. typedef union
  201. {
  202. //Operations Initiated by Central System
  203. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  204. struct
  205. {
  206. //CsMsgValue[0]
  207. unsigned char StatusNotificationReq :1; //bit 0,
  208. unsigned char StatusNotificationConf :1; //bit 0,
  209. unsigned char :6; //bit 2~7
  210. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  211. }CpinitiateMsg;
  212. CpinitiateMsg cpinitateMsg;
  213. //==========================================
  214. // Init all Enumeration & Mapping String
  215. //==========================================
  216. /*ChargePointErrorCode*/
  217. typedef enum {
  218. ConnectorLockFailure,
  219. EVCommunicationError,
  220. GroundFailure,
  221. HighTemperature,
  222. InternalError,
  223. LocalListConflict,
  224. NoError,
  225. OtherError,
  226. OverCurrentFailure,
  227. OverVoltage,
  228. PowerMeterFailure,
  229. PowerSwitchFailure,
  230. ReaderFailure,
  231. ResetFailure,
  232. UnderVoltage,
  233. WeakSignal
  234. } ChargePointErrorCode;
  235. #if 0
  236. static char *ChargePointErrorCodeStr[] = {
  237. MACROSTR(ConnectorLockFailure),
  238. MACROSTR(EVCommunicationError),
  239. MACROSTR(GroundFailure),
  240. MACROSTR(HighTemperature),
  241. MACROSTR(InternalError),
  242. MACROSTR(LocalListConflict),
  243. MACROSTR(NoError),
  244. MACROSTR(OtherError),
  245. MACROSTR(OverCurrentFailure),
  246. MACROSTR(OverVoltage),
  247. MACROSTR(PowerMeterFailure),
  248. MACROSTR(PowerSwitchFailure),
  249. MACROSTR(ReaderFailure),
  250. MACROSTR(ResetFailure),
  251. MACROSTR(UnderVoltage),
  252. MACROSTR(WeakSignal)
  253. };
  254. #endif
  255. /*ChargePointStatus*/
  256. typedef enum {
  257. Available =0,
  258. Preparing,
  259. Charging,
  260. SuspendedEVSE,
  261. SuspendedEV,
  262. Finishing,
  263. Reserved,
  264. Unavailable,
  265. Faulted
  266. } ChargePointStatus;
  267. static char * ChargePointStatusStr[] = {
  268. MACROSTR(Available),
  269. MACROSTR(Preparing),
  270. MACROSTR(Charging),
  271. MACROSTR(SuspendedEVSE),
  272. MACROSTR(SuspendedEV),
  273. MACROSTR(Finishing),
  274. MACROSTR(Reserved),
  275. MACROSTR(Unavailable),
  276. MACROSTR(Faulted)
  277. };
  278. /*AvailabilityType*/
  279. typedef enum {
  280. RegistrationStatus_Accepted,
  281. RegistrationStatus_Pending,
  282. RegistrationStatus_Rejected
  283. } RegistrationStatus;
  284. static char *RegistrationStatusStr[] = {
  285. MACROSTR(Accepted),
  286. MACROSTR(Pending),
  287. MACROSTR(Rejected)
  288. };
  289. /*AvailabilityType*/
  290. typedef enum {
  291. Inoperative,
  292. Operative
  293. } AvailabilityType;
  294. static char *AvailabilityTypeStr[] = {
  295. MACROSTR(Inoperative),
  296. MACROSTR(Operative)
  297. };
  298. /*AvailabilityStatus*/
  299. typedef enum {
  300. Accepted,
  301. Rejected,
  302. Scheduled
  303. } AvailabilityStatus;
  304. static char *AvailabilityStatusStr[] = {
  305. MACROSTR(Accepted),
  306. MACROSTR(Rejected),
  307. MACROSTR(Scheduled)
  308. };
  309. /*ConfigurationStatus*/
  310. typedef enum {
  311. ConfigurationStatus_Accepted,
  312. ConfigurationStatus_Rejected,
  313. RebootRequired,
  314. NotSupported
  315. } ConfigurationStatus;
  316. static char *ConfigurationStatusStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(RebootRequired),
  320. MACROSTR(NotSupported)
  321. };
  322. /*ClearCacheStatus*/
  323. typedef enum {
  324. ClearCacheStatus_Accepted,
  325. ClearCacheStatus_Rejected
  326. } ClearCacheStatus;
  327. static char *ClearCacheStatusStr[] = {
  328. MACROSTR(Accepted),
  329. MACROSTR(Rejected)
  330. };
  331. /*ChargingProfilePurposeType*/
  332. typedef enum {
  333. ChargePointMaxProfile,
  334. TxDefaultProfile,
  335. TxProfile
  336. } ChargingProfilePurposeType;
  337. static char *ChargingProfilePurposeTypeStr[] = {
  338. MACROSTR(ChargePointMaxProfile),
  339. MACROSTR(TxDefaultProfile),
  340. MACROSTR(TxProfile)
  341. };
  342. /*ChargingProfileStatus*/
  343. typedef enum {
  344. ChargingProfileStatus_Accepted,
  345. ChargingProfileStatus_Rejected,
  346. ChargingProfileStatus_NotSupported
  347. } ChargingProfileStatus;
  348. static char *ChargingProfileStatusStr[] = {
  349. MACROSTR(Accepted),
  350. MACROSTR(Rejected),
  351. MACROSTR(NotSupported)
  352. };
  353. /*ClearChargingProfileStatus*/
  354. typedef enum {
  355. ClearChargingProfileStatus_Accepted,
  356. ClearChargingProfileStatus_Unknown
  357. } ClearChargingProfileStatus;
  358. static char *ClearChargingProfileStatusStr[] = {
  359. MACROSTR(Accepted),
  360. MACROSTR(Unknown)
  361. };
  362. /*GetCompositeScheduleStatus*/
  363. typedef enum {
  364. GetCompositeScheduleStatus_Accepted,
  365. GetCompositeScheduleStatus_Rejected
  366. } GetCompositeScheduleStatus;
  367. static char *GetCompositeScheduleStatusStr[] = {
  368. MACROSTR(Accepted),
  369. MACROSTR(Rejected)
  370. };
  371. /*ChargingRateUnitType*/
  372. typedef enum {
  373. ChargingRateUnitType_W,
  374. ChargingRateUnitType_A
  375. } ChargingRateUnitType;
  376. /*AuthorizationStatus*/
  377. typedef enum {
  378. AuthorizationStatus_Accepted ,
  379. AuthorizationStatus_Blocked ,
  380. AuthorizationStatus_Expired ,
  381. AuthorizationStatus_Invalid ,
  382. AuthorizationStatus_ConcurrentTx
  383. } AuthorizationStatus;
  384. /*UpdateType*/
  385. typedef enum {
  386. Differential ,
  387. Full
  388. } UpdateType;
  389. static char *UpdateTypeStr[] = {
  390. MACROSTR(Differential),
  391. MACROSTR(Full)
  392. };
  393. /*UpdateStatus*/
  394. typedef enum {
  395. UpdateStatus_Accepted ,
  396. UpdateStatus_Failed ,
  397. UpdateStatus_NotSupported ,
  398. UpdateStatus_VersionMismatch
  399. } UpdateStatus;
  400. static char *UpdateStatusStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Failed),
  403. MACROSTR(NotSupported),
  404. MACROSTR(VersionMismatch)
  405. };
  406. /*RemoteStartStopStatus*/
  407. typedef enum {
  408. RemoteStartStopStatus_Accepted,
  409. RemoteStartStopStatus_Rejected
  410. } RemoteStartStopStatus;
  411. static char *RemoteStartStopStatusStr[] = {
  412. MACROSTR(Accepted),
  413. MACROSTR(Rejected)
  414. };
  415. /*ReservationStatus*/
  416. typedef enum {
  417. ReservationStatus_Accepted,
  418. ReservationStatus_Faulted,
  419. ReservationStatus_Occupied,
  420. ReservationStatus_Rejected,
  421. ReservationStatus_Unavailable
  422. } ReservationStatus;
  423. static char *ReservationStatusStr[] = {
  424. MACROSTR(Accepted),
  425. MACROSTR(Faulted),
  426. MACROSTR(Occupied),
  427. MACROSTR(Rejected),
  428. MACROSTR(Unavailable)
  429. };
  430. /*ResetType*/
  431. typedef enum {
  432. Hard,
  433. Soft
  434. } ResetType;
  435. static char *ResetTypeStr[] = {
  436. MACROSTR(Hard),
  437. MACROSTR(Soft)
  438. };
  439. /*ResetStatus*/
  440. typedef enum {
  441. ResetStatus_Accepted,
  442. ResetStatus_Rejected
  443. } ResetStatus;
  444. static char *ResetStatusStr[] = {
  445. MACROSTR(Accepted),
  446. MACROSTR(Rejected)
  447. };
  448. /*DiagnosticsStatus*/
  449. typedef enum {
  450. DiagnosticsStatus_Idle,
  451. DiagnosticsStatus_Uploaded,
  452. DiagnosticsStatus_UploadFailed,
  453. DiagnosticsStatus_Uploading
  454. } DiagnosticsStatus;
  455. static char * DiagnosticsStatusStr[] = {
  456. MACROSTR(Idle),
  457. MACROSTR(Uploaded),
  458. MACROSTR(UploadFailed),
  459. MACROSTR(Uploading)
  460. };
  461. /*FirmwareStatus*/
  462. typedef enum {
  463. FirmwareStatus_Downloaded,
  464. FirmwareStatus_DownloadFailed,
  465. FirmwareStatus_Downloading,
  466. FirmwareStatus_Idle,
  467. FirmwareStatus_InstallationFailed,
  468. FirmwareStatus_Installing,
  469. FirmwareStatus_Installed
  470. } FirmwareStatus;
  471. static char * FirmwareStatusStr[] = {
  472. MACROSTR(Downloaded),
  473. MACROSTR(DownloadFailed),
  474. MACROSTR(Downloading),
  475. MACROSTR(Idle),
  476. MACROSTR(InstallationFailed),
  477. MACROSTR(Installing),
  478. MACROSTR(Installed)
  479. };
  480. /*MessageTrigger*/
  481. typedef enum {
  482. BootNotification,
  483. DiagnosticsStatusNotification,
  484. FirmwareStatusNotification,
  485. Heartbeat,
  486. MeterValues,
  487. StatusNotification
  488. } MessageTrigger;
  489. static char * MessageTriggerStr[] = {
  490. MACROSTR(BootNotification),
  491. MACROSTR(DiagnosticsStatusNotification),
  492. MACROSTR(FirmwareStatusNotification),
  493. MACROSTR(Heartbeat),
  494. MACROSTR(MeterValues),
  495. MACROSTR(StatusNotification)
  496. };
  497. /*TriggerMessageStatus*/
  498. typedef enum {
  499. TriggerMessageStatus_Accepted ,
  500. TriggerMessageStatus_Rejected ,
  501. TriggerMessageStatus_NotImplemented
  502. } TriggerMessageStatus;
  503. static char * TriggerMessageStatusStr[] = {
  504. MACROSTR(Accepted),
  505. MACROSTR(Rejected),
  506. MACROSTR(NotImplemented)
  507. };
  508. /*UnlockStatus*/
  509. typedef enum {
  510. Unlocked,
  511. UnlockFailed,
  512. UnlockStatus_NotSupported
  513. } UnlockStatus;
  514. static char * UnlockStatusStr[] = {
  515. MACROSTR(Unlocked),
  516. MACROSTR(UnlockFailed),
  517. MACROSTR(NotSupported)
  518. };
  519. /*StopTransactionReason*/
  520. typedef enum {
  521. EmergencyStop,
  522. EVDisconnected,
  523. HardReset,
  524. Local,
  525. Other,
  526. PowerLoss,
  527. Reboot,
  528. Remote,
  529. SoftReset,
  530. UnlockCommand,
  531. DeAuthorized
  532. } StopTransactionReason;
  533. #if 0
  534. static char * StopTransactionReasonStr[] = {
  535. MACROSTR(EmergencyStop),
  536. MACROSTR(EVDisconnected),
  537. MACROSTR(HardReset),
  538. MACROSTR(Local),
  539. MACROSTR(Other),
  540. MACROSTR(PowerLoss),
  541. MACROSTR(Reboot),
  542. MACROSTR(Remote),
  543. MACROSTR(SoftReset),
  544. MACROSTR(UnlockCommand),
  545. MACROSTR(DeAuthorized)
  546. };
  547. #endif
  548. /*CancelReservationStatus*/
  549. typedef enum {
  550. CancelReservationStatus_Accepted,
  551. CancelReservationStatus_Rejected
  552. } CancelReservationStatus;
  553. static char * CancelReservationStatusStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected)
  556. };
  557. /*ReadingContext*/
  558. typedef enum {
  559. ReadingContext_Interruption_Begin,
  560. ReadingContext_Interruption_End,
  561. ReadingContext_Other,
  562. ReadingContext_Sample_Clock,
  563. ReadingContext_Sample_Periodic ,
  564. ReadingContext_Transaction_Begin ,
  565. ReadingContext_Transaction_End,
  566. ReadingContext_Trigger
  567. } ReadingContext;
  568. static char * ReadingContextStr[] = {
  569. MACROSTR(Interruption.Begin),
  570. MACROSTR(Interruption.End),
  571. MACROSTR(Other),
  572. MACROSTR(Sample.Clock),
  573. MACROSTR(Sample.Periodic),
  574. MACROSTR(Transaction.Begin),
  575. MACROSTR(Transaction.End),
  576. MACROSTR(Trigger)
  577. };
  578. /*ValueFormat*/
  579. typedef enum {
  580. Raw,
  581. SignedData
  582. } ValueFormat;
  583. static char * ValueFormatStr[] = {
  584. MACROSTR(Raw),
  585. MACROSTR(SignedData)
  586. };
  587. /*Measurand*/
  588. typedef enum {
  589. Current_Export ,
  590. Current_Import,
  591. Current_Offered,
  592. Energy_Active_Export_Register,
  593. Energy_Active_Import_Register,
  594. Energy_Reactive_Export_Register,
  595. Energy_Reactive_Import_Register,
  596. Energy_Active_Export_Interval,
  597. Energy_Active_Import_Interval,
  598. Energy_Reactive_Export_Interval,
  599. Energy_Reactive_Import_Interval,
  600. Frequency,
  601. Power_Active_Export ,
  602. Power_Active_Import,
  603. Power_Factor,
  604. Power_Offered,
  605. Power_Reactive_Export,
  606. Power_Reactive_Import,
  607. RPM,
  608. SoC,
  609. Temperature ,
  610. Voltage
  611. } Measurand;
  612. static char * MeasurandStr[] = {
  613. MACROSTR(Current.Export),
  614. MACROSTR(Current.Import),
  615. MACROSTR(Current.Offered),
  616. MACROSTR(Energy.Active.Export.Register),
  617. MACROSTR(Energy.Active.Import.Register),
  618. MACROSTR(Energy.Reactive.Export.Register),
  619. MACROSTR(Energy.Reactive.Import.Register),
  620. MACROSTR(Energy.Active.Export.Interval),
  621. MACROSTR(Energy.Active.Import.Interval),
  622. MACROSTR(Energy.Reactive.Export.Interval),
  623. MACROSTR(Energy.Reactive.Import.Interval),
  624. MACROSTR(Frequency),
  625. MACROSTR(Power.Active.Export),
  626. MACROSTR(Power.Active.Import),
  627. MACROSTR(Power.Factor),
  628. MACROSTR(Power.Offered),
  629. MACROSTR(Power.Reactive.ExportMACROSTR),
  630. MACROSTR(Power.Reactive.Import),
  631. MACROSTR(RPM),
  632. MACROSTR(SoC),
  633. MACROSTR(Temperature),
  634. MACROSTR(Voltage)
  635. };
  636. /*Location*/
  637. typedef enum {
  638. Location_Body,
  639. Location_Cable,
  640. Location_EV,
  641. Location_Inlet ,
  642. Location_Outlet
  643. } Location;
  644. static char * LocationStr[] = {
  645. MACROSTR(Body),
  646. MACROSTR(Cable),
  647. MACROSTR(EV),
  648. MACROSTR(Inlet),
  649. MACROSTR(Outlet)
  650. };
  651. /*Phase*/
  652. typedef enum {
  653. L1,
  654. L2,
  655. L3,
  656. N,
  657. L1_N,
  658. L2_N,
  659. L3_N,
  660. L1_L2,
  661. L2_L3,
  662. L3_L1
  663. } Phase;
  664. static char * PhaseStr[] = {
  665. MACROSTR(L1),
  666. MACROSTR(L2),
  667. MACROSTR(L3),
  668. MACROSTR(N),
  669. MACROSTR(L1-N),
  670. MACROSTR(L2-N),
  671. MACROSTR(L3-N),
  672. MACROSTR(L1-L2),
  673. MACROSTR(L2-L3),
  674. MACROSTR(L3-L1)
  675. };
  676. /*UnitOfMeasure*/
  677. typedef enum {
  678. UnitOfMeasure_Wh,
  679. UnitOfMeasure_kWh ,
  680. UnitOfMeasure_varh ,
  681. UnitOfMeasure_kvarh ,
  682. UnitOfMeasure_W ,
  683. UnitOfMeasure_kW ,
  684. UnitOfMeasure_VA ,
  685. UnitOfMeasure_kVA ,
  686. UnitOfMeasure_var ,
  687. UnitOfMeasure_kvar ,
  688. UnitOfMeasure_A ,
  689. UnitOfMeasure_V ,
  690. UnitOfMeasure_Celsius ,
  691. UnitOfMeasure_Fahrenheit ,
  692. UnitOfMeasure_K ,
  693. UnitOfMeasure_Percent
  694. } UnitOfMeasure;
  695. static char * UnitOfMeasureStr[] = {
  696. MACROSTR(Wh),
  697. MACROSTR(kWh),
  698. MACROSTR(varh),
  699. MACROSTR(kvarh),
  700. MACROSTR(W),
  701. MACROSTR(kW),
  702. MACROSTR(VA),
  703. MACROSTR(kVA),
  704. MACROSTR(var),
  705. MACROSTR(kvar),
  706. MACROSTR(A),
  707. MACROSTR(V),
  708. MACROSTR(Celsius),
  709. MACROSTR(Fahrenheit),
  710. MACROSTR(K),
  711. MACROSTR(Percent)
  712. };
  713. #if 0
  714. /*Configuration enum*/
  715. enum CoreProfile {
  716. AllowOfflineTxForUnknownId=0,
  717. AuthorizationCacheEnabled,
  718. AuthorizeRemoteTxRequests,
  719. BlinkRepeat,
  720. ClockAlignedDataInterval,
  721. ConnectionTimeOut,
  722. GetConfigurationMaxKeys,
  723. HeartbeatInterval,
  724. LightIntensity,
  725. LocalAuthorizeOffline,
  726. LocalPreAuthorize,
  727. MaxEnergyOnInvalidId,
  728. MeterValuesAlignedData,
  729. MeterValuesAlignedDataMaxLength,
  730. MeterValuesSampledData,
  731. MeterValuesSampledDataMaxLength,
  732. MeterValueSampleInterval,
  733. MinimumStatusDuration,
  734. NumberOfConnectors,
  735. ResetRetries,
  736. ConnectorPhaseRotation,
  737. ConnectorPhaseRotationMaxLength,
  738. StopTransactionOnEVSideDisconnect,
  739. StopTransactionOnInvalidId,
  740. StopTxnAlignedData,
  741. StopTxnAlignedDataMaxLength,
  742. StopTxnSampledData,
  743. StopTxnSampledDataMaxLength,
  744. SupportedFeatureProfiles,
  745. SupportedFeatureProfilesMaxLength,
  746. TransactionMessageAttempts,
  747. TransactionMessageRetryInterval,
  748. UnlockConnectorOnEVSideDisconnect,
  749. WebSocketPingInterval,
  750. _CoreProfile_CNT
  751. };
  752. #endif
  753. enum LocalAuthListManagementProfile{
  754. LocalAuthListEnabled=0,
  755. LocalAuthListMaxLength,
  756. SendLocalListMaxLength,
  757. _LocalAuthListManagementProfile_CNT
  758. };
  759. enum ReservationProfile{
  760. ReserveConnectorZeroSupported
  761. };
  762. enum SmartChargingProfile{
  763. ChargeProfileMaxStackLevel,
  764. ChargingScheduleAllowedChargingRateUnit,
  765. ChargingScheduleMaxPeriods,
  766. ConnectorSwitch3to1PhaseSupported,
  767. MaxChargingProfilesInstalled
  768. };
  769. enum ChargerSystemStatus{
  770. ChargerSystemStatus_Booting,
  771. ChargerSystemStatus_Idle,
  772. ChargerSystemStatus_Authorizing,
  773. ChargerSystemStatus_Preparing,
  774. ChargerSystemStatus_Charging,
  775. ChargerSystemStatus_Terminating,
  776. ChargerSystemStatus_Alarm,
  777. ChargerSystemStatus_Fault
  778. };
  779. enum GetConfigurationKey {
  780. GetConfiguration_AllowOfflineTxForUnknownId=0,
  781. GetConfiguration_AuthorizationCacheEnabled,
  782. GetConfiguration_AuthorizeRemoteTxRequests,
  783. GetConfiguration_BlinkRepeat,
  784. GetConfiguration_ClockAlignedDataInterval,
  785. GetConfiguration_ConnectionTimeOut,
  786. GetConfiguration_GetConfigurationMaxKeys,
  787. GetConfiguration_HeartbeatInterval,
  788. GetConfiguration_LightIntensity,
  789. GetConfiguration_LocalAuthorizeOffline,
  790. GetConfiguration_LocalPreAuthorize,
  791. GetConfiguration_MaxEnergyOnInvalidId,
  792. GetConfiguration_MeterValuesAlignedData,
  793. GetConfiguration_MeterValuesAlignedDataMaxLength,
  794. GetConfiguration_MeterValuesSampledData,
  795. GetConfiguration_MeterValuesSampledDataMaxLength,
  796. GetConfiguration_MeterValueSampleInterval,
  797. GetConfiguration_MinimumStatusDuration,
  798. GetConfiguration_NumberOfConnectors,
  799. GetConfiguration_ResetRetries,
  800. GetConfiguration_ConnectorPhaseRotation,
  801. GetConfiguration_ConnectorPhaseRotationMaxLength,
  802. GetConfiguration_StopTransactionOnEVSideDisconnect,
  803. GetConfiguration_StopTransactionOnInvalidId,
  804. GetConfiguration_StopTxnAlignedData,
  805. GetConfiguration_StopTxnAlignedDataMaxLength,
  806. GetConfiguration_StopTxnSampledData,
  807. GetConfiguration_StopTxnSampledDataMaxLength,
  808. GetConfiguration_SupportedFeatureProfiles,
  809. GetConfiguration_SupportedFeatureProfilesMaxLength,
  810. GetConfiguration_TransactionMessageAttempts,
  811. GetConfiguration_TransactionMessageRetryInterval,
  812. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  813. GetConfiguration_WebSocketPingInterval,
  814. GetConfiguration_LocalAuthListEnabled,
  815. GetConfiguration_LocalAuthListMaxLength,
  816. GetConfiguration_SendLocalListMaxLength,
  817. GetConfiguration_ReserveConnectorZeroSupported,
  818. GetConfiguration_ChargeProfileMaxStackLevel,
  819. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  820. GetConfiguration_ChargingScheduleMaxPeriods,
  821. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  822. GetConfiguration_MaxChargingProfilesInstalled,
  823. };
  824. //GetConfiguration Array
  825. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  826. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  827. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  828. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  829. //==========================================
  830. // Init all share memory
  831. //==========================================
  832. int InitShareMemory()
  833. {
  834. int result = PASS;
  835. int MeterSMId;
  836. //creat ShmSysConfigAndInfo
  837. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  838. {
  839. #ifdef SystemLogMessage
  840. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  841. #endif
  842. result = FAIL;
  843. }
  844. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  845. {
  846. #ifdef SystemLogMessage
  847. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  848. #endif
  849. result = FAIL;
  850. }
  851. else
  852. {}
  853. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  854. {
  855. #ifdef SystemLogMessage
  856. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  857. #endif
  858. result = FAIL;
  859. }
  860. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  861. {
  862. #ifdef SystemLogMessage
  863. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  864. #endif
  865. result = FAIL;
  866. }
  867. else
  868. {}
  869. //creat ShmPsuData
  870. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  871. {
  872. #ifdef SystemLogMessage
  873. DEBUG_ERROR("shmget ShmPsuData NG\n");
  874. #endif
  875. result = FAIL;
  876. }
  877. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  878. {
  879. #ifdef SystemLogMessage
  880. DEBUG_ERROR("shmat ShmPsuData NG\n");
  881. #endif
  882. result = FAIL;
  883. }
  884. else
  885. {}
  886. //creat ShmOCPP16Data
  887. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  888. {
  889. #ifdef SystemLogMessage
  890. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  891. #endif
  892. result = FAIL;
  893. }
  894. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  895. {
  896. #ifdef SystemLogMessage
  897. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  898. #endif
  899. result = FAIL;
  900. }
  901. else
  902. {}
  903. /****************************** For Initial Settings************************************************/
  904. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  905. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  906. // allocate Configuration memory address
  907. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  908. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  909. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  910. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  911. //offline MeterValue Interval
  912. TempMeterValueInterval = 0;
  913. return result;
  914. }
  915. int ProcessShareMemory()
  916. {
  917. if(InitShareMemory() == FAIL)
  918. {
  919. #ifdef SystemLogMessage
  920. DEBUG_ERROR("InitShareMemory NG\n");
  921. #endif
  922. if(ShmStatusCodeData!=NULL)
  923. {
  924. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  925. }
  926. sleep(5);
  927. return FAIL;
  928. }
  929. return PASS;
  930. }
  931. //---------------------common routine---------------------------//
  932. char * stringtrim( char * s )
  933. {
  934. char * p1 = s;
  935. char * p2 = s;
  936. while(*p1 != '\0')
  937. {
  938. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  939. {
  940. if(*p1 != ',')
  941. {
  942. p1 ++;
  943. }
  944. else
  945. {
  946. break;
  947. }
  948. }
  949. if(*p1 != ',')
  950. {
  951. * p2 ++ = *p1 ++;
  952. //printf("p2=%s\n",p2);
  953. }
  954. else
  955. {
  956. break;
  957. }
  958. }
  959. *p2 = '\0';
  960. return (s);
  961. }
  962. char * stringtrimspace( char * s )
  963. {
  964. char * p1 = s;
  965. char * p2 = s;
  966. while(*p1 != '\0')
  967. {
  968. while(*p1 == ' ') //while(*p1 == ' ' || *p1 == '\t' || *p1 == '\n' || *p1 == '\r')
  969. {
  970. p1 ++;
  971. }
  972. * p2 ++ = *p1 ++;
  973. //printf("p2=%s\n",p2);
  974. }
  975. *p2 = '\0';
  976. return (s);
  977. }
  978. int isOFFline(void)
  979. {
  980. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  981. {
  982. if(TempMeterValueInterval >= 2 )
  983. {
  984. TempMeterValueInterval = 0;
  985. return TRUE;
  986. }
  987. else
  988. {
  989. TempMeterValueInterval = TempMeterValueInterval+ 1;
  990. return FALSE;
  991. }
  992. }
  993. else
  994. {
  995. return FALSE;
  996. }
  997. }
  998. //---------------------------------------------
  999. // new:
  1000. // enum SYSTEM_STATUS
  1001. // {
  1002. // SYS_MODE_BOOTING = 0,
  1003. // SYS_MODE_IDLE = 1,
  1004. // SYS_MODE_AUTHORIZING = 2,
  1005. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  1006. // SYS_MODE_REASSIGN = 4,
  1007. // SYS_MODE_PREPARING = 5,
  1008. // SYS_MODE_PREPARE_FOR_EV = 6,
  1009. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  1010. // SYS_MODE_CHARGING = 8,
  1011. // SYS_MODE_TERMINATING = 9,
  1012. // SYS_MODE_COMPLETE = 10,
  1013. // SYS_MODE_ALARM = 11,
  1014. // SYS_MODE_FAULT = 12,
  1015. // SYS_MODE_RESERVATION = 13,
  1016. // SYS_MODE_BOOKING = 14,
  1017. // SYS_MODE_MAINTAIN = 15,
  1018. // SYS_MODE_DEBUG = 16,
  1019. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  1020. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  1021. // SYS_MODE_UPDATE = 19
  1022. // };
  1023. //
  1024. //
  1025. //-----------------------------------------
  1026. void CheckSystemValue(void)
  1027. {
  1028. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  1029. //int IdleModeCnt = 0;
  1030. char filenmae[100]={0};
  1031. char str[100]={0};
  1032. //===============================
  1033. // send Heartbeat
  1034. //===============================
  1035. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1036. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  1037. {
  1038. clientTime.Heartbeat=time((time_t*)NULL);
  1039. if(server_sign == TRUE)
  1040. {
  1041. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  1042. }
  1043. else
  1044. {
  1045. HeartBeatWaitTime = 10;
  1046. }
  1047. }
  1048. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  1049. {
  1050. DEBUG_INFO("Heartbeat !!!\n");
  1051. //parameter for test
  1052. sendHeartbeatRequest(0);
  1053. //==============================================
  1054. // Reset Waiting Time
  1055. //==============================================
  1056. clientTime.Heartbeat=time((time_t*)NULL);
  1057. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  1058. }
  1059. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  1060. {
  1061. //===============================
  1062. // CSU Trigger Reset Conf
  1063. //===============================
  1064. if((server_sign == TRUE) &&(ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  1065. {
  1066. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  1067. if(strcmp((const char *)ShmOCPP16Data->Reset.Type, "Soft") == 0)
  1068. {
  1069. server_sign = FALSE;
  1070. }
  1071. }
  1072. //===============================
  1073. // CSU Trigger Authorize Request
  1074. //===============================
  1075. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  1076. {
  1077. sendAuthorizeRequest(0);
  1078. authorizeRetryTimes = authorizeRetryTimes + 1;
  1079. if(authorizeRetryTimes < 3)
  1080. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1081. }
  1082. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  1083. {
  1084. authorizeRetryTimes = 0;
  1085. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  1086. server_sign = FALSE;
  1087. }
  1088. 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))
  1089. {
  1090. sendAuthorizeRequest(0);
  1091. }
  1092. //===============================
  1093. // CSU Trigger Smart Charging Profilw
  1094. //===============================
  1095. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  1096. {
  1097. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  1098. GetChargingProfileRequest(gun_index);
  1099. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  1100. }
  1101. //==============================================
  1102. // Charger start transaction
  1103. //==============================================
  1104. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  1105. {
  1106. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  1107. sendStartTransactionRequest(gun_index);
  1108. clientTime.StartTransaction = time((time_t*)NULL);
  1109. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1110. }
  1111. //==============================================
  1112. // Charger stop transaction
  1113. //==============================================
  1114. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  1115. {
  1116. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  1117. sendStopTransactionRequest(gun_index);
  1118. clientTime.StopTransaction = time((time_t*)NULL);
  1119. }
  1120. //==============================================
  1121. // Charger status report
  1122. //==============================================
  1123. //--- Check Mode Change ---//
  1124. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1125. if(gunType[gun_index] == 'J')
  1126. {
  1127. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1128. {
  1129. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  1130. {
  1131. 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]*/ )
  1132. {
  1133. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1134. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  1135. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  1136. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1137. statusModeChage[gun_index] = TRUE;
  1138. }
  1139. #if 1 // for TempStopTransaction
  1140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1141. {
  1142. checkTempStopTransaction(gun_index);
  1143. }
  1144. #endif
  1145. }
  1146. }
  1147. }
  1148. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1149. {
  1150. for (int index = 0; index < CCS_QUANTITY; index++)
  1151. {
  1152. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  1153. {
  1154. 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]*/ )
  1155. {
  1156. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1157. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  1158. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  1159. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1160. statusModeChage[gun_index] = TRUE;
  1161. }
  1162. #if 1 // for TempStopTransaction
  1163. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1164. {
  1165. checkTempStopTransaction(gun_index);
  1166. }
  1167. #endif
  1168. }
  1169. }
  1170. }
  1171. else if(gunType[gun_index] == 'G')
  1172. {
  1173. for (int index = 0; index < GB_QUANTITY; index++)
  1174. {
  1175. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  1176. {
  1177. 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]*/ )
  1178. {
  1179. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1180. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  1181. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  1182. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1183. statusModeChage[gun_index] = TRUE;
  1184. }
  1185. #if 1 // for TempStopTransaction
  1186. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1187. {
  1188. checkTempStopTransaction(gun_index);
  1189. }
  1190. #endif
  1191. }
  1192. }
  1193. }
  1194. else
  1195. {
  1196. for (int index = 0; index < AC_QUANTITY; index++)
  1197. {
  1198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  1199. {
  1200. 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]*/ )
  1201. {
  1202. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1203. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  1204. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  1205. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  1206. statusModeChage[gun_index] = TRUE;
  1207. }
  1208. #if 1 // for TempStopTransaction
  1209. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  1210. {
  1211. checkTempStopTransaction(gun_index);
  1212. }
  1213. #endif
  1214. }
  1215. }// END
  1216. }
  1217. if(((SystemInitial > 0)&& (server_sign == TRUE))||
  1218. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) ||
  1219. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index)))
  1220. || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1)&&((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))))
  1221. {
  1222. if(SystemInitial > 0)
  1223. SystemInitial = SystemInitial -1;
  1224. sendStatusNotificationRequest(gun_index);
  1225. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  1226. statusModeChage[gun_index] = FALSE;
  1227. DEBUG_INFO("SystemInitial=%d !!!\n",SystemInitial);
  1228. //DEBUG_INFO("difftime(time((time_t*)NULL), clientTime.Heartbeat)=%d !!!\n",difftime(time((time_t*)NULL), clientTime.Heartbeat));
  1229. //DEBUG_INFO("HeartBeatWaitTime=%d !!!\n",HeartBeatWaitTime);
  1230. //DEBUG_INFO("ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval=%d !!!\n",ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  1231. }
  1232. //==============================================
  1233. // Meter report
  1234. //==============================================
  1235. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  1236. {
  1237. DEBUG_INFO("Sent Meter Value\n");
  1238. //check Transaction active
  1239. if(gunType[gun_index] == 'J')
  1240. {
  1241. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1242. {
  1243. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1244. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1245. {
  1246. meterValueSend[gun_index] =1;
  1247. }
  1248. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1249. {
  1250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1251. if((access(filenmae,F_OK))!=-1)
  1252. {
  1253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1254. sprintf(str,"rm -f %s",filenmae);
  1255. system(str);
  1256. }
  1257. }
  1258. }// End for CHAdeMO
  1259. }
  1260. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1261. {
  1262. for (int index = 0; index < CCS_QUANTITY; index++)
  1263. {
  1264. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1265. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1266. {
  1267. meterValueSend[gun_index] =1;
  1268. }
  1269. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1270. {
  1271. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1272. if((access(filenmae,F_OK))!=-1)
  1273. {
  1274. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1275. sprintf(str,"rm -f %s",filenmae);
  1276. system(str);
  1277. }
  1278. }
  1279. } // End for CCS
  1280. }
  1281. else if(gunType[gun_index] == 'G')
  1282. {
  1283. for (int index = 0; index < GB_QUANTITY; index++)
  1284. {
  1285. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1286. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1287. {
  1288. meterValueSend[gun_index] =1;
  1289. }
  1290. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1291. {
  1292. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1293. if((access(filenmae,F_OK))!=-1)
  1294. {
  1295. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1296. sprintf(str,"rm -f %s",filenmae);
  1297. system(str);
  1298. }
  1299. }
  1300. }// End for GB
  1301. }
  1302. else
  1303. {
  1304. for (int index = 0; index < AC_QUANTITY; index++)
  1305. {
  1306. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  1307. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  1308. {
  1309. meterValueSend[gun_index] =1;
  1310. }
  1311. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  1312. {
  1313. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  1314. if((access(filenmae,F_OK))!=-1)
  1315. {
  1316. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  1317. sprintf(str,"rm -f %s",filenmae);
  1318. system(str);
  1319. }
  1320. }
  1321. }//End for AC
  1322. }
  1323. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  1324. if(meterValueSend[gun_index] == 1)
  1325. {
  1326. sendMeterValuesRequest(gun_index);
  1327. #if 1 // for TempStopTransaction
  1328. storeTempStopTransaction(gun_index);
  1329. #endif
  1330. }
  1331. }
  1332. //==============================================
  1333. // Check Connector reserved
  1334. //==============================================
  1335. //===============================
  1336. // Check if Reserve is expired
  1337. //===============================
  1338. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  1339. {
  1340. double diff_t;
  1341. struct tm tp;
  1342. // current time
  1343. time_t t = time(NULL);
  1344. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  1345. tp.tm_isdst = -1;
  1346. time_t utc = mktime(&tp);
  1347. diff_t = difftime(utc, t);
  1348. if(diff_t <= 0)
  1349. {
  1350. DEBUG_INFO("reserve expired !!! \n");
  1351. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  1352. }
  1353. }//END OF Check if Reserve is expired
  1354. //==========================================
  1355. // csu trigger FirmwareStatusNotificationReq
  1356. //==========================================
  1357. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  1358. {
  1359. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  1360. }
  1361. //==========================================
  1362. // csu trigger CancelReservationConf
  1363. //==========================================
  1364. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  1365. {
  1366. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  1367. }
  1368. //==========================================
  1369. // csu trigger ChangeAvailabilityConf
  1370. //==========================================
  1371. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  1372. {
  1373. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  1374. }
  1375. //==========================================
  1376. // csu trigger UnlockConnectorConf
  1377. //==========================================
  1378. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  1379. {
  1380. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  1381. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  1382. }
  1383. //==========================================
  1384. // csu trigger ReserveNowConf
  1385. //==========================================
  1386. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  1387. {
  1388. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  1389. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  1390. }
  1391. //==========================================
  1392. // csu trigger DataTransferReq
  1393. //==========================================
  1394. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  1395. {
  1396. sendDataTransferRequest(gun_index);
  1397. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  1398. }
  1399. }
  1400. }
  1401. //==========================================
  1402. // send request routine
  1403. //==========================================
  1404. int sendAuthorizeRequest(int gun_index)
  1405. {
  1406. mtrace();
  1407. int result = FAIL;
  1408. char message[100]={0};
  1409. char guid[37];
  1410. char tempdata[65]={0};
  1411. DEBUG_INFO("sendAuthorizeRequest \n");
  1412. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  1413. //Local Authorize
  1414. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  1415. {
  1416. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  1417. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1418. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  1419. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  1420. result = PASS;
  1421. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1422. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1423. authorizeRetryTimes = 0;
  1424. return result;
  1425. }
  1426. 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))||
  1427. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  1428. {
  1429. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1430. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  1431. {
  1432. if(strcmp(idTagQuery.idTagstr,"") == 0)
  1433. {
  1434. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  1435. }
  1436. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  1437. {
  1438. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  1439. }
  1440. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  1441. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  1442. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1443. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  1444. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1445. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1446. authorizeRetryTimes = 0;
  1447. return result;
  1448. }
  1449. else
  1450. {
  1451. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  1452. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  1453. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1454. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  1455. result = PASS;
  1456. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1457. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  1458. authorizeRetryTimes = 0;
  1459. return result;
  1460. }
  1461. }
  1462. //initailize struct Authorize
  1463. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  1464. //get data from shared memory
  1465. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1466. random_uuid(guid);
  1467. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  1468. LWS_Send(message);
  1469. sprintf(tempdata, "Authorize,%d", gun_index);
  1470. if(hashmap_operation(0, guid, tempdata) == 1)
  1471. {
  1472. result = PASS;
  1473. DEBUG_ERROR("Authorize mapItem pass\n");
  1474. }
  1475. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  1476. return result;
  1477. }
  1478. int sendBootNotificationRequest(void)
  1479. {
  1480. mtrace();
  1481. int result = FAIL;
  1482. char message[500]={0}, payload[700]={0};
  1483. char guid[37]={0};
  1484. char tempdata[65]={0};
  1485. int IsGunCharging = FALSE;
  1486. //check Transaction active
  1487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1488. {
  1489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1490. {
  1491. IsGunCharging = TRUE;
  1492. }
  1493. }
  1494. for (int index = 0; index < CCS_QUANTITY; index++)
  1495. {
  1496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1497. {
  1498. IsGunCharging = TRUE;
  1499. }
  1500. }
  1501. for (int index = 0; index < GB_QUANTITY; index++)
  1502. {
  1503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1504. {
  1505. IsGunCharging = TRUE;
  1506. }
  1507. }
  1508. for (int index = 0; index < AC_QUANTITY; index++)
  1509. {
  1510. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1511. {
  1512. IsGunCharging = TRUE;
  1513. }
  1514. }
  1515. if(IsGunCharging == TRUE)
  1516. {
  1517. server_sign = TRUE;
  1518. return result;
  1519. }
  1520. // Fill BootNotification fields
  1521. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  1522. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  1523. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  1524. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1525. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  1526. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  1527. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  1528. #if 0
  1529. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\",\"meterSerialNumber\":\"%s\",\"meterType\":\"%s\"} ",
  1530. ShmOCPP16Data->ChargeBoxId
  1531. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1532. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1533. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1534. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1535. ,ShmOCPP16Data->BootNotification.CpIccid
  1536. ,ShmOCPP16Data->BootNotification.CpImsi
  1537. ,ShmOCPP16Data->BootNotification.CpMeterSerialNumber
  1538. ,ShmOCPP16Data->BootNotification.CpMeterType);
  1539. #endif
  1540. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  1541. ShmOCPP16Data->ChargeBoxId
  1542. ,ShmSysConfigAndInfo->SysConfig.ModelName
  1543. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  1544. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  1545. ,ShmOCPP16Data->BootNotification.CpFwVersion
  1546. ,ShmOCPP16Data->BootNotification.CpIccid
  1547. ,ShmOCPP16Data->BootNotification.CpImsi);
  1548. random_uuid(guid);
  1549. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  1550. LWS_Send(message);
  1551. sprintf(tempdata, "BootNotification,0");
  1552. 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*/)
  1553. {
  1554. result = PASS;
  1555. }
  1556. memset(queuedata, 0, sizeof(queuedata));
  1557. strcpy(queuedata,message);
  1558. return result;
  1559. }
  1560. int sendDataTransferRequest(int gun_index)
  1561. {
  1562. mtrace();
  1563. char message[1000]={0};
  1564. char guid[37]={0};
  1565. char tempdata[65]={0};
  1566. int result = FAIL;
  1567. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  1568. random_uuid(guid);
  1569. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  1570. MESSAGE_TYPE_CALL,
  1571. guid,
  1572. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  1573. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  1574. ShmOCPP16Data->DataTransfer[gun_index].Data);
  1575. LWS_Send(message);
  1576. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  1577. 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*/)
  1578. {
  1579. result = PASS;
  1580. DEBUG_ERROR("DataTransfer mapItem pass\n");
  1581. }
  1582. return result;
  1583. }
  1584. int sendDiagnosticsStatusNotificationRequest(char *status)
  1585. {
  1586. mtrace();
  1587. int result = FAIL;
  1588. char message[110]={0};
  1589. char guid[37]={0};
  1590. char tempdata[65]={0};
  1591. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  1592. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  1593. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  1594. random_uuid(guid);
  1595. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  1596. LWS_Send(message);
  1597. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  1598. if(hashmap_operation(0, guid, tempdata) == 1)
  1599. {
  1600. result = PASS;
  1601. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  1602. }
  1603. //#ifdef SystemLogMessage
  1604. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  1605. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1606. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  1607. //#endif
  1608. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  1609. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  1610. //record status
  1611. if(strcmp(status,"Idle")==0)
  1612. {
  1613. DiagnosticsStatusNotificationStatus = 0;
  1614. }
  1615. else if(strcmp(status,"Uploaded")==0)
  1616. {
  1617. DiagnosticsStatusNotificationStatus = 1;
  1618. }
  1619. else if(strcmp(status,"UploadFailed")==0)
  1620. {
  1621. DiagnosticsStatusNotificationStatus = 2;
  1622. }
  1623. else if(strcmp(status,"Uploading")==0)
  1624. {
  1625. DiagnosticsStatusNotificationStatus = 3;
  1626. }
  1627. return result;
  1628. }
  1629. int sendFirmwareStatusNotificationRequest(char *status)
  1630. {
  1631. mtrace();
  1632. int result = FAIL;
  1633. char message[110]={0};
  1634. char guid[37]={0};
  1635. char tempdata[65]={0};
  1636. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  1637. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  1638. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  1639. random_uuid(guid);
  1640. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  1641. LWS_Send(message);
  1642. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  1643. 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*/)
  1644. {
  1645. result = PASS;
  1646. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  1647. }
  1648. //#ifdef SystemLogMessage
  1649. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  1650. //DEBUG_INFO("Message: %s\n", SendBuffer);
  1651. //#endif
  1652. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  1653. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  1654. //record status
  1655. if(strcmp(status,"Downloaded")==0)
  1656. {
  1657. FirmwareStatusNotificationStatus = 0;
  1658. }
  1659. else if(strcmp(status,"DownloadFailed")==0)
  1660. {
  1661. FirmwareStatusNotificationStatus = 1;
  1662. }
  1663. else if(strcmp(status,"Downloading")==0)
  1664. {
  1665. FirmwareStatusNotificationStatus = 2;
  1666. }
  1667. else if(strcmp(status,"Idle")==0)
  1668. {
  1669. FirmwareStatusNotificationStatus = 3;
  1670. }
  1671. else if(strcmp(status,"InstallationFailed")==0)
  1672. {
  1673. FirmwareStatusNotificationStatus = 4;
  1674. }
  1675. else if(strcmp(status,"Installing")==0)
  1676. {
  1677. FirmwareStatusNotificationStatus = 5;
  1678. }
  1679. else if(strcmp(status,"Installed")==0)
  1680. {
  1681. FirmwareStatusNotificationStatus = 6;
  1682. }
  1683. return result;
  1684. }
  1685. int sendHeartbeatRequest(int gun_index)
  1686. {
  1687. mtrace();
  1688. int result = FAIL;
  1689. char message[80]={0};
  1690. char guid[37]={0};
  1691. char tempdata[65]={0};
  1692. random_uuid(guid);
  1693. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  1694. , MESSAGE_TYPE_CALL
  1695. , guid );
  1696. LWS_Send(message);
  1697. sprintf(tempdata, "Heartbeat,%d", 0);
  1698. 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*/)
  1699. {
  1700. result = PASS;
  1701. //DEBUG_ERROR("Heartbeat mapItem pass\n");
  1702. }
  1703. return result;
  1704. }
  1705. int sendStartTransactionRequest(int gun_index)
  1706. {
  1707. mtrace();
  1708. int result = FAIL;
  1709. char message[250]={0};
  1710. char guid[37]={0};
  1711. struct timeval tmnow;
  1712. struct tm *tm;
  1713. char buf[28];//, usec_buf[6];
  1714. char tempdata[65]={0};
  1715. int tempIndex = 0;
  1716. DEBUG_INFO("sendStartTransactionRequest...");
  1717. gettimeofday(&tmnow, NULL);
  1718. time_t t;
  1719. t = time(NULL);
  1720. /*UTC time and date*/
  1721. tm = gmtime(&t);
  1722. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1723. #if 0 // remove temporally
  1724. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1725. strcat(buf,".");
  1726. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1727. strcat(buf,usec_buf);
  1728. #endif
  1729. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  1730. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  1731. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  1732. // clear StartTransaction Response
  1733. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  1734. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  1735. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  1736. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  1737. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1738. if(gunType[gun_index] == 'J')
  1739. {
  1740. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1741. {
  1742. tempIndex = ((gun_index==2) ? 1: 0);
  1743. }
  1744. else
  1745. {
  1746. tempIndex = gun_index;
  1747. }
  1748. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1749. {
  1750. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  1751. {
  1752. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  1753. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  1754. }
  1755. }
  1756. }
  1757. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1758. {
  1759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1760. {
  1761. tempIndex = ((gun_index==2) ? 1: 0);
  1762. }
  1763. else
  1764. {
  1765. tempIndex = gun_index;
  1766. }
  1767. for (int index = 0; index < CCS_QUANTITY; index++)
  1768. {
  1769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1770. {
  1771. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  1772. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  1773. }
  1774. }
  1775. }
  1776. else if(gunType[gun_index] == 'G')
  1777. {
  1778. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1779. {
  1780. tempIndex = ((gun_index==2) ? 1: 0);
  1781. }
  1782. else
  1783. {
  1784. tempIndex = gun_index;
  1785. }
  1786. for (int index = 0; index < GB_QUANTITY; index++)
  1787. {
  1788. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1789. {
  1790. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  1791. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1798. {
  1799. tempIndex = 2;
  1800. }
  1801. else
  1802. {
  1803. tempIndex = gun_index;
  1804. }
  1805. for (int index = 0; index < AC_QUANTITY; index++)
  1806. {
  1807. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1808. {
  1809. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  1810. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  1811. }
  1812. }
  1813. }
  1814. random_uuid(guid);
  1815. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  1816. , MESSAGE_TYPE_CALL
  1817. , guid
  1818. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  1819. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  1820. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  1821. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  1822. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  1823. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  1824. 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*/)
  1825. {
  1826. result = PASS;
  1827. }
  1828. strcpy(queuedata, message);
  1829. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  1830. if(GetTransactionQueueNum() == 1)
  1831. {
  1832. LWS_Send(message);
  1833. }
  1834. return result;
  1835. }
  1836. int sendStatusNotificationRequest(int gun_index)
  1837. {
  1838. mtrace();
  1839. int result = FAIL;
  1840. char message[600]={0};
  1841. char guid[37];
  1842. int currentStatus = 0;
  1843. struct timeval tmnow;
  1844. struct tm *tm;
  1845. char buf[28];//, usec_buf[6];
  1846. char tempdata[65]={0};
  1847. int tempIndex = 0;
  1848. gettimeofday(&tmnow, NULL);
  1849. time_t t;
  1850. t = time(NULL);
  1851. /*UTC time and date*/
  1852. tm = gmtime(&t);
  1853. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  1854. #if 0 // remove temporally
  1855. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  1856. strcat(buf,".");
  1857. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  1858. strcat(buf,usec_buf);
  1859. #endif
  1860. printf("%s",buf);
  1861. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  1862. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  1863. // it's option
  1864. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  1865. /*
  1866. enum _SYSTEM_STATUS
  1867. {
  1868. S_BOOTING = 0,
  1869. S_IDLE, = 1
  1870. S_AUTHORIZING, =2
  1871. S_REASSIGN_CHECK, =3
  1872. S_REASSIGN, =4
  1873. S_PRECHARGE, =5
  1874. S_PREPARING_FOR_EV, =6
  1875. S_PREPARING_FOR_EVSE, =7
  1876. S_CHARGING, =8
  1877. S_TERMINATING, =9
  1878. S_COMPLETE, =10
  1879. S_ALARM, =11
  1880. S_FAULT =12
  1881. }
  1882. */
  1883. //check Transaction active
  1884. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  1885. if(gunType[gun_index] == 'J')
  1886. {
  1887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1888. {
  1889. tempIndex = ((gun_index==2) ? 1: 0);
  1890. }
  1891. else
  1892. {
  1893. tempIndex = gun_index;
  1894. }
  1895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1896. {
  1897. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1898. {
  1899. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  1900. {
  1901. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  1902. {
  1903. currentStatus = 1; //OCPP Status: Preparing
  1904. }
  1905. else
  1906. {
  1907. currentStatus = 0; //OCPP Status: Available
  1908. }
  1909. }
  1910. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1911. {
  1912. currentStatus = 1; //OCPP Status: Preparing
  1913. }
  1914. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1915. {
  1916. currentStatus = 2; //OCPP Status: Charging
  1917. }
  1918. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1919. {
  1920. currentStatus = 5; //OCPP Status: Finishing
  1921. }
  1922. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  1923. {
  1924. currentStatus = 4; //OCPP Status: SuspendedEV
  1925. }
  1926. 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
  1927. {
  1928. currentStatus = 7; //OCPP Status: Unavailable
  1929. }
  1930. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  1931. {
  1932. currentStatus = 8; //OCPP Status: Faulted
  1933. }
  1934. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1935. {
  1936. currentStatus = 6; //OCPP Status: Reserved
  1937. }
  1938. } //end of the same index
  1939. }//end of for CHAdeMO_QUANTITY
  1940. }
  1941. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  1942. {
  1943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1944. {
  1945. tempIndex = ((gun_index==2) ? 1: 0);
  1946. }
  1947. else
  1948. {
  1949. tempIndex = gun_index;
  1950. }
  1951. for (int index = 0; index < CCS_QUANTITY; index++)
  1952. {
  1953. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1954. {
  1955. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  1956. {
  1957. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  1958. {
  1959. currentStatus = 1; //OCPP Status: Preparing
  1960. }
  1961. else
  1962. {
  1963. currentStatus = 0; //OCPP Status: Available
  1964. }
  1965. }
  1966. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  1967. {
  1968. currentStatus = 1; //OCPP Status: Preparing
  1969. }
  1970. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  1971. {
  1972. currentStatus = 2; //OCPP Status: Charging
  1973. }
  1974. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  1975. {
  1976. currentStatus = 5; //OCPP Status: Finishing
  1977. }
  1978. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  1979. {
  1980. currentStatus = 4; //OCPP Status: SuspendedEV
  1981. }
  1982. 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
  1983. {
  1984. currentStatus = 7; //OCPP Status : Unavailable
  1985. }
  1986. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  1987. {
  1988. currentStatus = 8; //OCPP Status: Faulted
  1989. }
  1990. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  1991. {
  1992. currentStatus = 6; //OCPP Status: Reserved
  1993. }
  1994. } //end of the same index
  1995. } // end of for CCS_QUANTITY
  1996. }
  1997. else if(gunType[gun_index] == 'G')
  1998. {
  1999. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2000. {
  2001. tempIndex = ((gun_index==2) ? 1: 0);
  2002. }
  2003. else
  2004. {
  2005. tempIndex = gun_index;
  2006. }
  2007. for (int index = 0; index < GB_QUANTITY; index++)
  2008. {
  2009. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2010. {
  2011. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  2012. {
  2013. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2014. {
  2015. currentStatus = 1; //OCPP Status: Preparing
  2016. }
  2017. else
  2018. {
  2019. currentStatus = 0; //OCPP Status: Available
  2020. }
  2021. }
  2022. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  2023. {
  2024. currentStatus = 1; //OCPP Status: Preparing
  2025. }
  2026. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2027. {
  2028. currentStatus = 2; //OCPP Status: Charging
  2029. }
  2030. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  2031. {
  2032. currentStatus = 5; //OCPP Status: Finishing
  2033. }
  2034. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2035. {
  2036. currentStatus = 4; //OCPP Status: SuspendedEV
  2037. }
  2038. 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
  2039. {
  2040. currentStatus = 7; //OCPP Status: Unavailable
  2041. }
  2042. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  2043. {
  2044. currentStatus = 8; //OCPP Status: Faulted
  2045. }
  2046. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2047. {
  2048. currentStatus = 6; //OCPP Status: Reserved
  2049. }
  2050. } //end of the same index
  2051. } // end of for GB_QUANTITY
  2052. }
  2053. else
  2054. {
  2055. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2056. {
  2057. tempIndex = 2;
  2058. }
  2059. else
  2060. {
  2061. tempIndex = gun_index;
  2062. }
  2063. for (int index = 0; index < AC_QUANTITY; index++)
  2064. {
  2065. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2066. {
  2067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  2068. {
  2069. 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))
  2070. {
  2071. currentStatus = 1; //OCPP Status: Preparing
  2072. }
  2073. else
  2074. {
  2075. currentStatus = 0; //OCPP Status: Available
  2076. }
  2077. }
  2078. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  2079. {
  2080. currentStatus = 1; //OCPP Status: Preparing
  2081. }
  2082. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  2083. {
  2084. currentStatus = 2; //OCPP Status: Charging
  2085. }
  2086. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  2087. {
  2088. currentStatus = 5; //OCPP Status: Finishing
  2089. }
  2090. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  2091. {
  2092. currentStatus = 4; //OCPP Status: SuspendedEV
  2093. }
  2094. 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
  2095. {
  2096. currentStatus = 7; //OCPP Status: Unavailable
  2097. }
  2098. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  2099. {
  2100. currentStatus = 8; //OCPP Status: Faulted
  2101. }
  2102. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  2103. {
  2104. currentStatus = 6; //OCPP Status: Reserved
  2105. }
  2106. }//end of the same index
  2107. }//end of for AC_QUANTITY
  2108. }
  2109. //it's option
  2110. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  2111. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  2112. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  2113. random_uuid(guid);
  2114. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  2115. , MESSAGE_TYPE_CALL
  2116. , guid
  2117. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  2118. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  2119. , ShmOCPP16Data->StatusNotification[gun_index].Info
  2120. , ShmOCPP16Data->StatusNotification[gun_index].Status
  2121. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  2122. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  2123. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  2124. LWS_Send(message);
  2125. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  2126. 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*/)
  2127. {
  2128. //DEBUG_ERROR("statusNotification mapitem pass");
  2129. result = PASS;
  2130. }
  2131. return result;
  2132. }
  2133. int sendStopTransactionRequest(int gun_index)
  2134. {
  2135. mtrace();
  2136. int result = FAIL;
  2137. //char message[1500]={0};
  2138. char guid[37]={0};
  2139. char tempdata[65]={0};
  2140. int tempIndex = 0;
  2141. //int idx_sample=0;
  2142. DEBUG_ERROR("sendStopTransactionRequest \n");
  2143. memset(queuedata, 0, sizeof(queuedata));
  2144. //ENERGY_ACTIVE_IMPORT_REGISTER
  2145. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2146. if(gunType[gun_index] == 'J')
  2147. {
  2148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2149. {
  2150. tempIndex = ((gun_index==2) ? 1: 0);
  2151. }
  2152. else
  2153. {
  2154. tempIndex = gun_index;
  2155. }
  2156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2157. {
  2158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2159. {
  2160. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  2161. }
  2162. }// END OF CHAdeMO_QUANTITY
  2163. }
  2164. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2165. {
  2166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2167. {
  2168. tempIndex = ((gun_index==2) ? 1: 0);
  2169. }
  2170. else
  2171. {
  2172. tempIndex = gun_index;
  2173. }
  2174. for (int index = 0; index < CCS_QUANTITY; index++)
  2175. {
  2176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2177. {
  2178. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  2179. }
  2180. }// END OF CCS_QUANTITY
  2181. }
  2182. else if(gunType[gun_index] == 'G')
  2183. {
  2184. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2185. {
  2186. tempIndex = ((gun_index==2) ? 1: 0);
  2187. }
  2188. else
  2189. {
  2190. tempIndex = gun_index;
  2191. }
  2192. for (int index = 0; index < GB_QUANTITY; index++)
  2193. {
  2194. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2195. {
  2196. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  2197. }
  2198. }// END OF GB_QUANTITY
  2199. }
  2200. else
  2201. {
  2202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2203. {
  2204. tempIndex = 2;
  2205. }
  2206. else
  2207. {
  2208. tempIndex = gun_index;
  2209. }
  2210. for (int index = 0; index < AC_QUANTITY; index++)
  2211. {
  2212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2213. {
  2214. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  2215. }
  2216. }// END OF AC_QUANTITY
  2217. }
  2218. //Stop Transaction Time
  2219. struct timeval tmnow;
  2220. struct tm *tm;
  2221. char buf[28];//, usec_buf[6];
  2222. gettimeofday(&tmnow, NULL);
  2223. time_t t;
  2224. t = time(NULL);
  2225. /*UTC time and date*/
  2226. tm = gmtime(&t);
  2227. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  2229. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2230. random_uuid(guid);
  2231. /***********************************transactionData******************************************************/
  2232. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  2233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  2234. //=================================
  2235. // Transaction_Begin
  2236. //=================================
  2237. // Energy.Active.Export.Interval
  2238. //idx_sample=0;
  2239. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  2240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  2241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  2242. 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*/]);
  2243. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2244. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2245. {
  2246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  2247. }
  2248. else
  2249. {
  2250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  2251. }
  2252. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  2253. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2254. //=================================
  2255. // Transaction_End
  2256. //=================================
  2257. //Current.Export
  2258. //idx_sample=1;
  2259. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  2260. if(gunType[gun_index] == 'J')
  2261. {
  2262. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2263. {
  2264. tempIndex = ((gun_index==2) ? 1: 0);
  2265. }
  2266. else
  2267. {
  2268. tempIndex = gun_index;
  2269. }
  2270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2271. {
  2272. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2273. {
  2274. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2275. }
  2276. }// End of for CHAdeMO_QUANTITY
  2277. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2278. }
  2279. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2280. {
  2281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2282. {
  2283. tempIndex = ((gun_index==2) ? 1: 0);
  2284. }
  2285. else
  2286. {
  2287. tempIndex = gun_index;
  2288. }
  2289. for (int index = 0; index < CCS_QUANTITY; index++)
  2290. {
  2291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2292. {
  2293. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2294. }
  2295. }// End of for CCS_QUANTITY
  2296. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2297. }
  2298. else if(gunType[gun_index] == 'G')
  2299. {
  2300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2301. {
  2302. tempIndex = ((gun_index==2) ? 1: 0);
  2303. }
  2304. else
  2305. {
  2306. tempIndex = gun_index;
  2307. }
  2308. for (int index = 0; index < GB_QUANTITY; index++)
  2309. {
  2310. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2311. {
  2312. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  2313. }
  2314. }// End of for GB_QUANTITY
  2315. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  2316. }
  2317. else
  2318. {
  2319. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2320. {
  2321. tempIndex = 2;
  2322. }
  2323. else
  2324. {
  2325. tempIndex = gun_index;
  2326. }
  2327. for (int index = 0; index < AC_QUANTITY; index++)
  2328. {
  2329. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2330. {
  2331. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  2332. }
  2333. }// End of for AC_QUANTITY
  2334. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2335. }
  2336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2337. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  2338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  2339. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  2340. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  2341. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2342. //Energy.Active.Export.Interval
  2343. //idx_sample=2;
  2344. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2345. if(gunType[gun_index] == 'J')
  2346. {
  2347. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2348. {
  2349. tempIndex = ((gun_index==2) ? 1: 0);
  2350. }
  2351. else
  2352. {
  2353. tempIndex = gun_index;
  2354. }
  2355. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2356. {
  2357. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2358. {
  2359. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2360. }
  2361. }// END OF CHAdeMO_QUANTITY
  2362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2363. }
  2364. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2365. {
  2366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2367. {
  2368. tempIndex = ((gun_index==2) ? 1: 0);
  2369. }
  2370. else
  2371. {
  2372. tempIndex = gun_index;
  2373. }
  2374. for (int index = 0; index < CCS_QUANTITY; index++)
  2375. {
  2376. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2377. {
  2378. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2379. }
  2380. }// END OF CCS_QUANTITY
  2381. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2382. }
  2383. else if(gunType[gun_index] == 'G')
  2384. {
  2385. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2386. {
  2387. tempIndex = ((gun_index==2) ? 1: 0);
  2388. }
  2389. else
  2390. {
  2391. tempIndex = gun_index;
  2392. }
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2396. {
  2397. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2398. }
  2399. }// END OF GB_QUANTITY
  2400. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  2401. }
  2402. else
  2403. {
  2404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2405. {
  2406. tempIndex = 2;
  2407. }
  2408. else
  2409. {
  2410. tempIndex = gun_index;
  2411. }
  2412. for (int index = 0; index < AC_QUANTITY; index++)
  2413. {
  2414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2415. {
  2416. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  2417. }
  2418. }// END OF AC_QUANTITY
  2419. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2420. }
  2421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2422. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  2423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  2424. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  2425. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  2426. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2427. //Power.Active.Export
  2428. //idx_sample=3;
  2429. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2430. if(gunType[gun_index] == 'J')
  2431. {
  2432. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2433. {
  2434. tempIndex = ((gun_index==2) ? 1: 0);
  2435. }
  2436. else
  2437. {
  2438. tempIndex = gun_index;
  2439. }
  2440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2441. {
  2442. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2443. {
  2444. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2445. }
  2446. } // End for CHAdeMO_QUANTITY
  2447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2448. }
  2449. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2450. {
  2451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2452. {
  2453. tempIndex = ((gun_index==2) ? 1: 0);
  2454. }
  2455. else
  2456. {
  2457. tempIndex = gun_index;
  2458. }
  2459. for (int index = 0; index < CCS_QUANTITY; index++)
  2460. {
  2461. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2462. {
  2463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2464. }
  2465. } // END for CCS_QUANTITY
  2466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2467. }
  2468. else if(gunType[gun_index] == 'G')
  2469. {
  2470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2471. {
  2472. tempIndex = ((gun_index==2) ? 1: 0);
  2473. }
  2474. else
  2475. {
  2476. tempIndex = gun_index;
  2477. }
  2478. for (int index = 0; index < GB_QUANTITY; index++)
  2479. {
  2480. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2481. {
  2482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2483. }
  2484. }// END for GB_QUANTITY
  2485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  2486. }
  2487. else
  2488. {
  2489. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2490. {
  2491. tempIndex = 2;
  2492. }
  2493. else
  2494. {
  2495. tempIndex = gun_index;
  2496. }
  2497. for (int index = 0; index < AC_QUANTITY; index++)
  2498. {
  2499. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2500. {
  2501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  2502. }
  2503. } // END for AC_QUANTITY
  2504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2505. }
  2506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  2508. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  2509. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  2510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  2511. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  2512. //Voltage
  2513. //idx_sample=4;
  2514. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2515. if(gunType[gun_index] == 'J')
  2516. {
  2517. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2518. {
  2519. tempIndex = ((gun_index==2) ? 1: 0);
  2520. }
  2521. else
  2522. {
  2523. tempIndex = gun_index;
  2524. }
  2525. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2526. {
  2527. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2528. {
  2529. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2530. }
  2531. } // END OF FOR CHAdeMO_QUANTITY
  2532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2533. }
  2534. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2535. {
  2536. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2537. {
  2538. tempIndex = ((gun_index==2) ? 1: 0);
  2539. }
  2540. else
  2541. {
  2542. tempIndex = gun_index;
  2543. }
  2544. for (int index = 0; index < CCS_QUANTITY; index++)
  2545. {
  2546. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2547. {
  2548. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2549. }
  2550. } // END OF FOR CCS_QUANTITY
  2551. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2552. }
  2553. else if(gunType[gun_index] == 'G')
  2554. {
  2555. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2556. {
  2557. tempIndex = ((gun_index==2) ? 1: 0);
  2558. }
  2559. else
  2560. {
  2561. tempIndex = gun_index;
  2562. }
  2563. for (int index = 0; index < GB_QUANTITY; index++)
  2564. {
  2565. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2566. {
  2567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  2568. }
  2569. } // END OF FOR GB_QUANTITY
  2570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  2571. }
  2572. else
  2573. {
  2574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2575. {
  2576. tempIndex = 2;
  2577. }
  2578. else
  2579. {
  2580. tempIndex = gun_index;
  2581. }
  2582. for (int index = 0; index < AC_QUANTITY; index++)
  2583. {
  2584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2585. {
  2586. 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
  2587. }
  2588. } // END OF FOR AC_QUANTITY
  2589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2590. }
  2591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  2593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  2594. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  2595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  2596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  2597. //SoC
  2598. //idx_sample=5;
  2599. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2600. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2601. {
  2602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2603. {
  2604. tempIndex = ((gun_index==2) ? 1: 0);
  2605. }
  2606. else
  2607. {
  2608. tempIndex = gun_index;
  2609. }
  2610. if(gunType[gun_index] == 'J')
  2611. {
  2612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2613. {
  2614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2615. {
  2616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  2617. }
  2618. }
  2619. }
  2620. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2621. {
  2622. for (int index = 0; index < CCS_QUANTITY; index++)
  2623. {
  2624. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2625. {
  2626. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  2627. }
  2628. }
  2629. }
  2630. else if(gunType[gun_index] == 'G')
  2631. {
  2632. for (int index = 0; index < GB_QUANTITY; index++)
  2633. {
  2634. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2635. {
  2636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  2637. }
  2638. }
  2639. }
  2640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  2641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  2642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  2643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  2644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  2645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  2646. } // END FOR DC CASE
  2647. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  2648. {
  2649. 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\"}]}]}]"
  2650. ,MESSAGE_TYPE_CALL
  2651. ,guid
  2652. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2653. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2654. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2655. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2656. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2657. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2658. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2659. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2660. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2662. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  2694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  2695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  2696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  2697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  2698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  2699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  2700. );
  2701. }
  2702. else
  2703. {
  2704. 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\"}]}]}]"
  2705. ,MESSAGE_TYPE_CALL
  2706. ,guid
  2707. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  2708. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  2709. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  2710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  2711. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  2712. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  2713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  2714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  2715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  2716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  2717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  2718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  2719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  2720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  2721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  2722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  2723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  2724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  2725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  2726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  2727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  2728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  2729. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  2730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  2731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  2732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  2733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  2734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  2735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  2736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  2737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  2738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  2739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  2740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  2741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  2742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  2743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  2744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  2745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  2746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  2747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  2748. );
  2749. }
  2750. #if 1 // for TempStopTransaction
  2751. //Delete TempStopTransaction
  2752. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  2753. {
  2754. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  2755. }
  2756. #endif
  2757. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  2758. if(hashmap_operation(0, guid, tempdata) == 1)
  2759. {
  2760. result = PASS;
  2761. DEBUG_INFO("StopTransaction mapitem pass\n");
  2762. }
  2763. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2764. if(GetTransactionQueueNum() == 1)
  2765. {
  2766. LWS_Send(queuedata);
  2767. }
  2768. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  2769. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  2770. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  2771. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  2772. {
  2773. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  2774. }
  2775. //for test
  2776. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2777. return result;
  2778. }
  2779. int sendMeterValuesRequest(int gun_index)
  2780. {
  2781. mtrace();
  2782. int result = FAIL;
  2783. // char message[1500]={0};
  2784. char guid[37]={0};
  2785. //int idx_sample=0;
  2786. //int length = 0;
  2787. char tempdata[65]={0};
  2788. int tempIndex = 0;
  2789. DEBUG_INFO("sendMeterValuesRequest ...\n");
  2790. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  2791. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  2792. {
  2793. DEBUG_INFO("NOT SENT METER Vlaue\n");
  2794. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  2795. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  2796. return result;
  2797. }
  2798. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  2799. {
  2800. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  2801. }
  2802. memset(queuedata, 0, sizeof(queuedata));
  2803. //set value
  2804. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  2805. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  2806. random_uuid(guid);
  2807. //UTC Date time
  2808. struct timeval tmnow;
  2809. struct tm *tm;
  2810. char buf[28];//, usec_buf[6];
  2811. gettimeofday(&tmnow, NULL);
  2812. time_t t;
  2813. t = time(NULL);
  2814. /*UTC time and date*/
  2815. tm = gmtime(&t);
  2816. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2817. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  2818. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  2819. //idx_sample=0;
  2820. //********************************(1)Current.Export************************************************/
  2821. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2822. if(gunType[gun_index] == 'J')
  2823. {
  2824. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2825. {
  2826. tempIndex = ((gun_index==2) ? 1: 0);
  2827. }
  2828. else
  2829. {
  2830. tempIndex = gun_index;
  2831. }
  2832. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2833. {
  2834. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2835. {
  2836. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  2837. }
  2838. }
  2839. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2840. }
  2841. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2842. {
  2843. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2844. {
  2845. tempIndex = ((gun_index==2) ? 1: 0);
  2846. }
  2847. else
  2848. {
  2849. tempIndex = gun_index;
  2850. }
  2851. for (int index = 0; index < CCS_QUANTITY; index++)
  2852. {
  2853. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2854. {
  2855. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  2856. }
  2857. }
  2858. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2859. }
  2860. else if(gunType[gun_index] == 'G')
  2861. {
  2862. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2863. {
  2864. tempIndex = ((gun_index==2) ? 1: 0);
  2865. }
  2866. else
  2867. {
  2868. tempIndex = gun_index;
  2869. }
  2870. for (int index = 0; index < GB_QUANTITY; index++)
  2871. {
  2872. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2873. {
  2874. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  2875. }
  2876. }
  2877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  2878. }
  2879. else
  2880. {
  2881. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2882. {
  2883. tempIndex = 2;
  2884. }
  2885. else
  2886. {
  2887. tempIndex = gun_index;
  2888. }
  2889. for (int index = 0; index < AC_QUANTITY; index++)
  2890. {
  2891. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2892. {
  2893. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  2894. }
  2895. }
  2896. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2897. }
  2898. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  2900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  2901. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  2903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  2904. //idx_sample=1;
  2905. //********************************(2)Energy.Active.Import.Register ************************************************/
  2906. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2907. if(gunType[gun_index] == 'J')
  2908. {
  2909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2910. {
  2911. tempIndex = ((gun_index==2) ? 1: 0);
  2912. }
  2913. else
  2914. {
  2915. tempIndex = gun_index;
  2916. }
  2917. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2918. {
  2919. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2920. {
  2921. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  2922. }
  2923. }
  2924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2925. }
  2926. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2927. {
  2928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2929. {
  2930. tempIndex = ((gun_index==2) ? 1: 0);
  2931. }
  2932. else
  2933. {
  2934. tempIndex = gun_index;
  2935. }
  2936. for (int index = 0; index < CCS_QUANTITY; index++)
  2937. {
  2938. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2939. {
  2940. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  2941. }
  2942. }
  2943. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2944. }
  2945. else if(gunType[gun_index] == 'G')
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2948. {
  2949. tempIndex = ((gun_index==2) ? 1: 0);
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < GB_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2958. {
  2959. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  2960. }
  2961. }
  2962. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  2963. }
  2964. else
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2967. {
  2968. tempIndex = 2;
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < AC_QUANTITY; index++)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2977. {
  2978. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  2979. }
  2980. }
  2981. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  2982. }
  2983. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  2984. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  2985. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  2986. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  2987. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  2988. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  2989. //idx_sample=2;
  2990. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  2991. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  2992. if(gunType[gun_index] == 'J')
  2993. {
  2994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2995. {
  2996. tempIndex = ((gun_index==2) ? 1: 0);
  2997. }
  2998. else
  2999. {
  3000. tempIndex = gun_index;
  3001. }
  3002. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3003. {
  3004. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3005. {
  3006. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  3007. }
  3008. } // END OF FOR CHAdeMO_QUANTITY
  3009. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3010. }
  3011. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3012. {
  3013. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3014. {
  3015. tempIndex = ((gun_index==2) ? 1: 0);
  3016. }
  3017. else
  3018. {
  3019. tempIndex = gun_index;
  3020. }
  3021. for (int index = 0; index < CCS_QUANTITY; index++)
  3022. {
  3023. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  3024. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3025. {
  3026. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  3027. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  3028. }
  3029. } // END OF CCS_QUANTITY
  3030. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3031. }
  3032. else if(gunType[gun_index] == 'G')
  3033. {
  3034. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3035. {
  3036. tempIndex = ((gun_index==2) ? 1: 0);
  3037. }
  3038. else
  3039. {
  3040. tempIndex = gun_index;
  3041. }
  3042. for (int index = 0; index < GB_QUANTITY; index++)
  3043. {
  3044. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3045. {
  3046. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  3047. }
  3048. } // END OF GB_QUANTITY
  3049. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  3050. }
  3051. else
  3052. {
  3053. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3054. {
  3055. tempIndex = 2;
  3056. }
  3057. else
  3058. {
  3059. tempIndex = gun_index;
  3060. }
  3061. for (int index = 0; index < AC_QUANTITY; index++)
  3062. {
  3063. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3064. {
  3065. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  3066. }
  3067. }
  3068. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3069. }
  3070. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3071. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  3072. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  3073. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  3074. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  3075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3076. //idx_sample=3;
  3077. //********************************(4)Power.Active.Export************************************************/
  3078. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3079. if(gunType[gun_index] == 'J')
  3080. {
  3081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3082. {
  3083. tempIndex = ((gun_index==2) ? 1: 0);
  3084. }
  3085. else
  3086. {
  3087. tempIndex = gun_index;
  3088. }
  3089. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3090. {
  3091. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3092. {
  3093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  3094. }
  3095. } // END OF FOR
  3096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3097. }
  3098. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < CCS_QUANTITY; index++)
  3109. {
  3110. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3111. {
  3112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  3113. }
  3114. }
  3115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3116. }
  3117. else if(gunType[gun_index] == 'G')
  3118. {
  3119. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3120. {
  3121. tempIndex = ((gun_index==2) ? 1: 0);
  3122. }
  3123. else
  3124. {
  3125. tempIndex = gun_index;
  3126. }
  3127. for (int index = 0; index < GB_QUANTITY; index++)
  3128. {
  3129. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3130. {
  3131. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  3132. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  3133. }
  3134. }
  3135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  3136. }
  3137. else
  3138. {
  3139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3140. {
  3141. tempIndex = 2;
  3142. }
  3143. else
  3144. {
  3145. tempIndex = gun_index;
  3146. }
  3147. for (int index = 0; index < AC_QUANTITY; index++)
  3148. {
  3149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3150. {
  3151. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  3152. }
  3153. }
  3154. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3155. }
  3156. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3157. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  3158. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  3159. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  3160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  3161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  3162. //idx_sample=4;
  3163. //***********************************************(5)VOLTAGE******************************************************/
  3164. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3165. if(gunType[gun_index] == 'J')
  3166. {
  3167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3168. {
  3169. tempIndex = ((gun_index==2) ? 1: 0);
  3170. }
  3171. else
  3172. {
  3173. tempIndex = gun_index;
  3174. }
  3175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3176. {
  3177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3178. {
  3179. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  3180. }
  3181. }
  3182. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3183. }
  3184. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3185. {
  3186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3187. {
  3188. tempIndex = ((gun_index==2) ? 1: 0);
  3189. }
  3190. else
  3191. {
  3192. tempIndex = gun_index;
  3193. }
  3194. for (int index = 0; index < CCS_QUANTITY; index++)
  3195. {
  3196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3197. {
  3198. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  3199. }
  3200. }
  3201. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3202. }
  3203. else if(gunType[gun_index] == 'G')
  3204. {
  3205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3206. {
  3207. tempIndex = ((gun_index==2) ? 1: 0);
  3208. }
  3209. else
  3210. {
  3211. tempIndex = gun_index;
  3212. }
  3213. for (int index = 0; index < GB_QUANTITY; index++)
  3214. {
  3215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3216. {
  3217. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  3218. }
  3219. }
  3220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  3221. }
  3222. else
  3223. {
  3224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3225. {
  3226. tempIndex = 2;
  3227. }
  3228. else
  3229. {
  3230. tempIndex = gun_index;
  3231. }
  3232. for (int index = 0; index < AC_QUANTITY; index++)
  3233. {
  3234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3235. {
  3236. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  3237. }
  3238. }
  3239. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  3240. }
  3241. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3242. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  3243. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  3244. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  3245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  3246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3247. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3248. {
  3249. //idx_sample=5;
  3250. //sampledValue = NULL;
  3251. //***********************************************(6)SOC******************************************************/
  3252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3253. {
  3254. tempIndex = ((gun_index==2) ? 1: 0);
  3255. }
  3256. else
  3257. {
  3258. tempIndex = gun_index;
  3259. }
  3260. if(gunType[gun_index] == 'J')
  3261. {
  3262. //tempIndex = ((gun_index==2) ? 1: 0);
  3263. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3264. {
  3265. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3266. {
  3267. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  3268. }
  3269. }
  3270. }
  3271. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3272. {
  3273. //tempIndex = ((gun_index==2) ? 1: 0);
  3274. for (int index = 0; index < CCS_QUANTITY; index++)
  3275. {
  3276. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3277. {
  3278. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  3279. }
  3280. }
  3281. }
  3282. else if(gunType[gun_index] == 'G')
  3283. {
  3284. //tempIndex = ((gun_index==2) ? 1: 0);
  3285. for (int index = 0; index < GB_QUANTITY; index++)
  3286. {
  3287. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3288. {
  3289. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  3290. }
  3291. }
  3292. }
  3293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  3294. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  3295. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  3296. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  3297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  3298. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  3299. }
  3300. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3301. {
  3302. 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\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3303. ,MESSAGE_TYPE_CALL
  3304. ,guid
  3305. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3306. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3307. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3308. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3309. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3310. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3311. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3312. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3313. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3314. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3315. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3316. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3317. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3318. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3319. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3320. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3321. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3322. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3323. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3324. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3325. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3326. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3327. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3328. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3329. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3330. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3331. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3332. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3333. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3334. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3335. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3336. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3337. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3338. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3339. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3340. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3341. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3342. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3343. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  3344. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  3345. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  3346. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  3347. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  3348. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  3349. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  3350. );
  3351. }
  3352. else
  3353. {
  3354. 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\"}]}]}]"
  3355. ,MESSAGE_TYPE_CALL
  3356. ,guid
  3357. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  3358. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  3359. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  3360. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  3361. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  3362. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  3363. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  3364. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  3365. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  3366. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  3367. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  3368. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  3369. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  3370. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  3371. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  3372. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  3373. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  3374. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  3375. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  3376. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  3377. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  3378. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  3379. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  3380. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  3381. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  3382. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  3383. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  3384. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  3385. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  3386. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  3387. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  3388. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  3389. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  3390. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  3391. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  3392. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  3393. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  3394. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  3395. );
  3396. }
  3397. // Put request guid to hash map
  3398. sprintf(tempdata, "MeterValues,%d", (gun_index));
  3399. 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*/)
  3400. {
  3401. result = PASS;
  3402. DEBUG_INFO("MeterValues mapitem pass\n");
  3403. }
  3404. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3405. if(GetTransactionQueueNum() == 1)
  3406. {
  3407. LWS_Send(queuedata);
  3408. }
  3409. return result;
  3410. }
  3411. //==========================================
  3412. // send confirm routine
  3413. //==========================================
  3414. int sendCancelReservationConfirmation(char *uuid,char *payload)
  3415. {
  3416. mtrace();
  3417. int result = FAIL;
  3418. char message[100]={0};
  3419. DEBUG_ERROR("handle sendCancelReservationConfirmation\n");
  3420. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3421. LWS_Send(message);
  3422. result = TRUE;
  3423. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  3424. return result;
  3425. }
  3426. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  3427. {
  3428. mtrace();
  3429. int result = FAIL;
  3430. char message[100]={0};
  3431. DEBUG_ERROR("handle sendChangeAvailabilityConfirmation\n");
  3432. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3433. LWS_Send(message);
  3434. result = TRUE;
  3435. return result;
  3436. }
  3437. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  3438. {
  3439. mtrace();
  3440. int result = FAIL;
  3441. char message[100]={0};
  3442. DEBUG_ERROR("handle sendChangeConfigurationConfirmation\n");
  3443. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  3444. LWS_Send(message);
  3445. result = TRUE;
  3446. return result;
  3447. }
  3448. int sendClearCacheConfirmation(char *uuid,char *payload)
  3449. {
  3450. mtrace();
  3451. int result = FAIL;
  3452. char message[500]={0};
  3453. // int count = 0;
  3454. // int gun_index = 0;
  3455. // char guid[37];
  3456. // [ 3, "1570592744204", { "status": "Accepted" } ]
  3457. DEBUG_ERROR("sendClearCacheConfirmation\n");
  3458. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3459. LWS_Send(message);
  3460. return result;
  3461. }
  3462. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  3463. {
  3464. mtrace();
  3465. int result = FAIL;
  3466. char message[500]={0};
  3467. // [ 3, "1571284268200", { "status": "Unknown" } ]
  3468. DEBUG_ERROR("sendClearChargingProfileConfirmation\n");
  3469. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3470. LWS_Send(message);
  3471. return result;
  3472. }
  3473. int sendDataTransferConfirmation(char *uuid,char *payload)
  3474. {
  3475. mtrace();
  3476. char statusStr[20]={0};
  3477. char dataStr[10]={0};
  3478. char sstr[20]={0};
  3479. int c = 0;
  3480. char *loc;
  3481. int result = FAIL;
  3482. // [3,"792bc950-b279-49e3-ab8f-429e02a2f9a7",{"status":"Accepted","data":"True"}]
  3483. DEBUG_ERROR("sendDataTransferConfirmation ...\n");
  3484. /**********************status**************************/
  3485. loc = strstr(payload, "status");
  3486. memset(sstr ,0, sizeof(sstr) );
  3487. c = 0;
  3488. while (loc[3+strlen("status")+c] != '\"')
  3489. {
  3490. sstr[c] = loc[3+strlen("status")+c];
  3491. c++;
  3492. }
  3493. sstr[c] = '\0';
  3494. strcpy(statusStr, sstr);
  3495. /**********************data**************************/
  3496. loc = strstr(payload, "data");
  3497. memset(sstr ,0, sizeof(sstr) );
  3498. c = 0;
  3499. while (loc[3+strlen("data")+c] != '\"')
  3500. {
  3501. sstr[c] = loc[3+strlen("data")+c];
  3502. c++;
  3503. }
  3504. sstr[c] = '\0';
  3505. strcpy(dataStr, sstr);
  3506. return result;
  3507. }
  3508. int sendGetCompositeScheduleConfirmation(char *uuid,char *payload, int connectorIdInt,int nPeriod)
  3509. {
  3510. mtrace();
  3511. int result = FAIL;
  3512. char message[1000]={0};
  3513. double diff_f = 0.0;
  3514. int diff_i = 0;
  3515. int diffSeconds = 0;
  3516. struct tm tp;
  3517. int TimeZero = FALSE;
  3518. int CompositeScheduleIndex = 0;
  3519. DEBUG_INFO("handle sendGetCompositeScheduleConfirmation ...\n");
  3520. if((CurrentChargingProfileScheduleStr == NULL)||(strcmp((const char *)CurrentChargingProfileScheduleStr,"")==0))
  3521. {
  3522. TimeZero = TRUE;
  3523. }
  3524. else
  3525. {
  3526. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  3527. }
  3528. if(TimeZero == FALSE)
  3529. {
  3530. tp.tm_isdst = -1;
  3531. time_t utc = mktime(&tp);
  3532. time_t t = time(NULL);
  3533. diff_f = difftime(t, utc);
  3534. diff_i = (int)diff_f;
  3535. diffSeconds = diff_i % 86400;//86400 seconds/day
  3536. }
  3537. //DEBUG_INFO("\n diff_f=%f \n",diff_f);
  3538. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  3539. #if 0 //remove temporally
  3540. 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}"
  3541. ,MESSAGE_TYPE_CALLRESULT
  3542. ,uuid
  3543. ,payload
  3544. ,connectorIdInt
  3545. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3546. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.Duration
  3547. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.StartSchedule
  3548. ,ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingRateUnit);
  3549. #endif
  3550. if(nPeriod == 0)
  3551. {
  3552. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  3553. {
  3554. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  3555. ,MESSAGE_TYPE_CALLRESULT
  3556. ,uuid
  3557. ,payload
  3558. ,connectorIdInt);
  3559. }
  3560. else
  3561. {
  3562. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\"}]"
  3563. ,MESSAGE_TYPE_CALLRESULT
  3564. ,uuid
  3565. ,payload
  3566. ,connectorIdInt
  3567. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule);
  3568. }
  3569. }
  3570. else
  3571. {
  3572. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  3573. ,MESSAGE_TYPE_CALLRESULT
  3574. ,uuid
  3575. ,payload
  3576. ,connectorIdInt
  3577. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3578. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  3579. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  3580. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  3581. int len = nPeriod;
  3582. //Last Period StartPriod is less than diffSeconds
  3583. if(((ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].StartPeriod % 86400) < diffSeconds) || (diffSeconds == 0))
  3584. {
  3585. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3586. , 0
  3587. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].Limit
  3588. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[len -1].NumberPhases );
  3589. }
  3590. else
  3591. {
  3592. for(int idx_sample=0;idx_sample< len;idx_sample++)
  3593. {
  3594. 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)
  3595. {
  3596. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3597. , 0 /*ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod*/
  3598. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3599. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3600. }
  3601. else if(ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod > diffSeconds)
  3602. {
  3603. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  3604. , ((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*/))
  3605. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  3606. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  3607. }
  3608. }
  3609. }
  3610. sprintf(message + strlen(message), "]}}]");
  3611. }
  3612. LWS_Send(message);
  3613. result = TRUE;
  3614. return result;
  3615. }
  3616. int sendGetConfigurationConfirmation(char *uuid)
  3617. {
  3618. mtrace();
  3619. int result = FAIL;
  3620. int MaxKeySupported = 0;
  3621. int sentConfigurationNumber= 0;
  3622. int sentunConfigurationNumber= 0;
  3623. char message[4000]={0};
  3624. DEBUG_ERROR("handle sendGetConfigurationConfirmation ...\n");
  3625. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  3626. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  3627. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  3628. ,MESSAGE_TYPE_CALLRESULT
  3629. ,uuid );
  3630. //configuration key
  3631. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  3632. {
  3633. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  3634. {
  3635. if (sentConfigurationNumber == 0)
  3636. {
  3637. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3638. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3639. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3640. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3641. }
  3642. else
  3643. {
  3644. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  3645. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  3646. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  3647. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  3648. }
  3649. sentConfigurationNumber = sentConfigurationNumber + 1;
  3650. }
  3651. }
  3652. sprintf(message + strlen(message), "]");
  3653. if(UnknownKeynum != 0)
  3654. {
  3655. sprintf(message + strlen(message), ",\"unknownKey\":[");
  3656. //unkown key
  3657. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  3658. {
  3659. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  3660. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  3661. if(sentunConfigurationNumber == 0)
  3662. {
  3663. sprintf(message + strlen(message), "\"%s\""
  3664. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3665. }
  3666. else
  3667. {
  3668. sprintf(message + strlen(message), ",\"%s\""
  3669. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  3670. }
  3671. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  3672. }
  3673. sprintf(message + strlen(message), "]");
  3674. }
  3675. sprintf(message + strlen(message), "}]");
  3676. LWS_Send(message);
  3677. return result;
  3678. }
  3679. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  3680. {
  3681. mtrace();
  3682. int result = FAIL;
  3683. char message[400]={0};
  3684. DEBUG_ERROR("handle sendGetDiagnosticsConfirmation ...\n");
  3685. if(strcmp(payload,"")==0)
  3686. {
  3687. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3688. }
  3689. else
  3690. {
  3691. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "fileName", payload);
  3692. }
  3693. LWS_Send(message);
  3694. result = TRUE;
  3695. return result;
  3696. }
  3697. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  3698. {
  3699. mtrace();
  3700. int result = FAIL;
  3701. char message[80]={0};
  3702. //[ 3, "4f0141fb-f3a0-4634-9179-b1379b514d3c", { "listVersion": 1 } ]
  3703. DEBUG_ERROR("handle GetLocalListVersionRequest ...\n");
  3704. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  3705. LWS_Send(message);
  3706. result = TRUE;
  3707. return result;
  3708. }
  3709. int sendRemoteStartConfirmation(char *uuid,char *payload)
  3710. {
  3711. mtrace();
  3712. int result = FAIL;
  3713. char message[80]={0};
  3714. //[3,"26f6b7bc-a6e8-48a8-bdc5-a541bf8f9e27",{"status":"Accepted"}]
  3715. DEBUG_ERROR("handleRemoteStartRequest ...\n");
  3716. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3717. LWS_Send(message);
  3718. result = TRUE;
  3719. return result;
  3720. }
  3721. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  3722. {
  3723. mtrace();
  3724. int result = FAIL;
  3725. char message[80]={0};
  3726. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3727. DEBUG_ERROR("sendRemoteStopTransactionConfirmation ...\n");
  3728. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3729. LWS_Send(message);
  3730. result = TRUE;
  3731. return result;
  3732. }
  3733. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  3734. {
  3735. mtrace();
  3736. int result = FAIL;
  3737. char message[80]={0};
  3738. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  3739. DEBUG_ERROR("sendReserveNowTransactionConfirmation\n");
  3740. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3741. LWS_Send(message);
  3742. result = TRUE;
  3743. return result;
  3744. }
  3745. int sendResetConfirmation(char *uuid,char *payload)
  3746. {
  3747. mtrace();
  3748. int result = FAIL;
  3749. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  3750. char message[80]={0};
  3751. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  3752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3753. LWS_Send(message);
  3754. result = TRUE;
  3755. return result;
  3756. }
  3757. int sendSendLocalListConfirmation(char *uuid,char *payload)
  3758. {
  3759. mtrace();
  3760. int result = FAIL;
  3761. char message[500]={0};
  3762. // [ 3, "1571284266109", { "status": "Accepted" } ]
  3763. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  3764. LWS_Send(message);
  3765. result = TRUE;
  3766. return result;
  3767. }
  3768. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  3769. {
  3770. mtrace();
  3771. int result = FAIL;
  3772. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  3773. char message[80]={0};
  3774. DEBUG_INFO("sendSetChargingProfileConfirmation\n");
  3775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3776. LWS_Send(message);
  3777. result = TRUE;
  3778. return result;
  3779. }
  3780. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  3781. {
  3782. mtrace();
  3783. int result = FAIL;
  3784. char message[80]={0};
  3785. DEBUG_INFO("sendTriggerMessageConfirmation\n");
  3786. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3787. LWS_Send(message);
  3788. result = TRUE;
  3789. return result;
  3790. }
  3791. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  3792. {
  3793. mtrace();
  3794. int result = FAIL;
  3795. char message[80]={0};
  3796. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3797. DEBUG_INFO("sendUnlockConnectorConfirmation\n");
  3798. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  3799. LWS_Send(message);
  3800. result = TRUE;
  3801. return result;
  3802. }
  3803. int sendUpdateFirmwareConfirmation(char *uuid)
  3804. {
  3805. mtrace();
  3806. int result = FAIL;
  3807. char message[60]={0};
  3808. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  3809. DEBUG_INFO("sendUpdateFirmwareConfirmation\n");
  3810. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  3811. LWS_Send(message);
  3812. result = TRUE;
  3813. return result;
  3814. }
  3815. //==========================================
  3816. // send CallError routine
  3817. //==========================================
  3818. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  3819. {
  3820. mtrace();
  3821. //int result = FAIL;
  3822. char message[220]={0};
  3823. // [4,"f1c52ff5-e65d-4070-b7d4-6c70bc1e8970","PropertyConstraintViolation","Payload is syntactically correct but at least one field contains an invalid value",{}]
  3824. #ifdef SystemLogMessage
  3825. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n",
  3826. uniqueId, action, errorCode, errorDescription);
  3827. #endif
  3828. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  3829. LWS_Send(message);
  3830. //result = TRUE;
  3831. }
  3832. //==========================================
  3833. // Handle server request routine Start
  3834. //==========================================
  3835. #define GUN_NUM 1
  3836. int handleCancelReservationRequest(char *uuid, char *payload)
  3837. {
  3838. mtrace();
  3839. int result = FAIL;
  3840. int gunNO = 0;
  3841. int reservationIdInt =0;
  3842. char comfirmstr[20];
  3843. int c = 0;
  3844. int copyTo = 0;
  3845. char *loc;
  3846. char sstr[100]={0};
  3847. DEBUG_INFO("handle CancelReservationRequest\n");
  3848. //ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3849. c = 0;
  3850. copyTo = 0;
  3851. loc = strstr(payload, "reservationId");
  3852. memset(sstr ,0, sizeof(sstr) );
  3853. while (loc[strlen("reservationId")+2+c] != '}')
  3854. {
  3855. if(loc[strlen("interval")+2+c] != ' ')
  3856. {
  3857. sstr[copyTo] = loc[strlen("reservationId")+2+c];
  3858. copyTo = copyTo + 1;
  3859. //printf("i=%d sstr=%c\n",c, sstr[c]);
  3860. }
  3861. c++;
  3862. }
  3863. sstr[copyTo] = '\0';
  3864. reservationIdInt = atoi(sstr);
  3865. memset(comfirmstr, 0, sizeof comfirmstr);
  3866. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  3867. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  3868. //check Transaction active
  3869. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3870. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3871. {
  3872. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  3873. {
  3874. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3875. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3876. if(gunType[2] == 'J')
  3877. {
  3878. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  3879. }
  3880. else
  3881. {
  3882. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  3883. }
  3884. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3885. goto end;
  3886. }
  3887. }
  3888. for (int index = 0; index < CCS_QUANTITY; index++)
  3889. {
  3890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  3891. {
  3892. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3893. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3894. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  3895. {
  3896. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  3897. }
  3898. else
  3899. {
  3900. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  3901. }
  3902. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3903. goto end;
  3904. }
  3905. }
  3906. for (int index = 0; index < GB_QUANTITY; index++)
  3907. {
  3908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  3909. {
  3910. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3911. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3912. if(gunType[2] == 'G')
  3913. {
  3914. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  3915. }
  3916. else
  3917. {
  3918. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  3919. }
  3920. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3921. goto end;
  3922. }
  3923. }
  3924. for (int index = 0; index < AC_QUANTITY; index++)
  3925. {
  3926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  3927. {
  3928. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  3929. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  3930. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3931. {
  3932. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  3933. }
  3934. else
  3935. {
  3936. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  3937. }
  3938. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  3939. goto end;
  3940. }
  3941. }
  3942. //The reservationId does NOT match the reservationId
  3943. sendCancelReservationConfirmation(uuid, comfirmstr);
  3944. end:
  3945. // Fill in ocpp packet uuid
  3946. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  3947. return result;
  3948. }
  3949. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  3950. {
  3951. mtrace();
  3952. int result = FAIL;
  3953. int gunIndex = 0;
  3954. char sstr[90]={0},sstrtemp[50]={ 0 };
  3955. char typeStr[16]={0};
  3956. char comfirmstr[20];
  3957. int specificId = FALSE;
  3958. char *loc;
  3959. //int intervalInt = 0;
  3960. int c = 0;
  3961. DEBUG_ERROR("handle ChangeAvailabilityRequest\n");
  3962. strcpy(sstrtemp, stringtrimspace(payload));
  3963. /*** connectorId ****/
  3964. loc = strstr(sstrtemp, "connectorId");
  3965. memset(sstr ,0, sizeof(sstr) );
  3966. c = 0;
  3967. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') &&(loc[strlen("connectorId")+2+c] != '}') ) // 2: ":
  3968. {
  3969. sstr[c] = loc[strlen("connectorId")+2+c];
  3970. c++;
  3971. }
  3972. sstr[c] = '\0';
  3973. gunIndex = atoi(sstr);
  3974. /***type ****/
  3975. loc = strstr(sstrtemp, "type");
  3976. memset(sstr ,0, sizeof(sstr) );
  3977. c = 0;
  3978. while ((loc != NULL) &&(loc[3+strlen("type")+c] != '\"'))
  3979. {
  3980. sstr[c] = loc[3+strlen("type")+c];
  3981. c++;
  3982. }
  3983. sstr[c] = '\0';
  3984. strcpy(typeStr, sstr);
  3985. if(gunIndex != 0)
  3986. {
  3987. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  3988. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  3989. }
  3990. else
  3991. {
  3992. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  3993. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  3994. }
  3995. memset(comfirmstr, 0, sizeof comfirmstr);
  3996. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  3997. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  3998. {
  3999. specificId = TRUE;
  4000. }
  4001. if(specificId == FALSE)
  4002. goto end;
  4003. if(gunIndex != 0)
  4004. {
  4005. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4006. }
  4007. else
  4008. {
  4009. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  4010. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  4011. }
  4012. /*
  4013. enum SYSTEM_STATUS
  4014. {
  4015. SYS_MODE_BOOTING = 0,
  4016. SYS_MODE_IDLE = 1,
  4017. SYS_MODE_AUTHORIZING = 2,
  4018. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  4019. SYS_MODE_REASSIGN = 4,
  4020. SYS_MODE_PREPARING = 5,
  4021. SYS_MODE_PREPARE_FOR_EV = 6,
  4022. SYS_MODE_PREPARE_FOR_EVSE = 7,
  4023. SYS_MODE_CHARGING = 8,
  4024. SYS_MODE_TERMINATING = 9,
  4025. SYS_MODE_COMPLETE = 10,
  4026. SYS_MODE_ALARM = 11,
  4027. SYS_MODE_FAULT = 12,
  4028. SYS_MODE_RESERVATION = 13,
  4029. SYS_MODE_BOOKING = 14,
  4030. SYS_MODE_MAINTAIN = 15,
  4031. SYS_MODE_DEBUG = 16,
  4032. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  4033. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  4034. SYS_MODE_UPDATE = 19
  4035. };
  4036. */
  4037. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  4038. {
  4039. //check Transaction active
  4040. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4041. {
  4042. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  4043. {
  4044. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4045. {
  4046. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4047. }
  4048. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4049. {
  4050. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4051. }
  4052. else
  4053. {
  4054. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4055. }
  4056. goto end;
  4057. }
  4058. }//END FOR CHAdeMO_QUANTITY
  4059. for (int index = 0; index < CCS_QUANTITY; index++)
  4060. {
  4061. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  4062. {
  4063. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING)// S_PRECHARGE
  4064. {
  4065. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4066. }
  4067. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4068. {
  4069. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4070. }
  4071. else
  4072. {
  4073. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4074. }
  4075. goto end;
  4076. }
  4077. }//END FOR CCS_QUANTITY
  4078. for (int index = 0; index < GB_QUANTITY; index++)
  4079. {
  4080. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  4081. {
  4082. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4083. {
  4084. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4085. }
  4086. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4087. {
  4088. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4089. }
  4090. else
  4091. {
  4092. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4093. }
  4094. goto end;
  4095. }
  4096. }// END FOR GB_QUANTITY
  4097. for (int index = 0; index < AC_QUANTITY; index++)
  4098. {
  4099. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  4100. {
  4101. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) // S_PRECHARGE
  4102. {
  4103. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  4104. }
  4105. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  4106. {
  4107. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  4108. }
  4109. else
  4110. {
  4111. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4112. }
  4113. goto end;
  4114. }
  4115. }//END FOR AC_QUANTITY
  4116. }//END FOR AvailabilityTypeStr[Inoperative]
  4117. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  4118. {
  4119. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  4120. //check Transaction active
  4121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4122. {
  4123. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4124. {
  4125. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4126. goto end;
  4127. }
  4128. }//END FOR CHAdeMO_QUANTITY
  4129. for (int index = 0; index < CCS_QUANTITY; index++)
  4130. {
  4131. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4132. {
  4133. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4134. goto end;
  4135. }
  4136. }//END FOR CCS_QUANTITY
  4137. for (int index = 0; index < GB_QUANTITY; index++)
  4138. {
  4139. if (((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4140. {
  4141. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  4142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4143. goto end;
  4144. }
  4145. }// END FOR GB_QUANTITY
  4146. for (int index = 0; index < AC_QUANTITY; index++)
  4147. {
  4148. if (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  4149. {
  4150. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  4151. goto end;
  4152. }
  4153. }//END FOR CHAdeMO_QUANTITY
  4154. }//END FOR AvailabilityTypeStr[Operative]
  4155. end:
  4156. if(gunIndex != 0)
  4157. {
  4158. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  4159. }
  4160. else
  4161. {
  4162. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  4163. }
  4164. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  4165. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityConf = 1;
  4166. return result;
  4167. }
  4168. int handleChangeConfigurationRequest(char *uuid, char *payload)
  4169. {
  4170. mtrace();
  4171. int result = FAIL;
  4172. char sstr[100]={0},sstrtemp[160]={ 0 };
  4173. char keystr[40]={0};
  4174. char valuestr[100]={0};
  4175. char *loc;
  4176. int c = 0;
  4177. char comfirmstr[20]={0};
  4178. DEBUG_ERROR("handle ChangeConfigurationRequest\n");
  4179. strcpy(sstrtemp, stringtrimspace(payload));
  4180. /***key ****/
  4181. loc = strstr(sstrtemp, "key");
  4182. memset(sstr ,0, sizeof(sstr) );
  4183. c = 0;
  4184. while ((loc != NULL) &&(loc[3+strlen("key")+c] != '\"'))
  4185. {
  4186. sstr[c] = loc[3+strlen("key")+c];
  4187. c++;
  4188. }
  4189. sstr[c] = '\0';
  4190. strcpy(keystr, sstr);
  4191. //DEBUG_INFO( "keystr=%s\n",keystr);
  4192. /***value ****/
  4193. loc = strstr(sstrtemp, "value");
  4194. memset(sstr ,0, sizeof(sstr) );
  4195. c = 0;
  4196. while ((loc != NULL) &&(loc[3+strlen("value")+c] != '\"'))
  4197. {
  4198. sstr[c] = loc[3+strlen("value")+c];
  4199. c++;
  4200. }
  4201. sstr[c] = '\0';
  4202. strcpy(valuestr, sstr);
  4203. //DEBUG_INFO( "valuestr=%s\n",valuestr);
  4204. if((uuid==NULL) || (payload ==NULL) )
  4205. {
  4206. #ifdef Debug
  4207. DEBUG_INFO("payload is null\n");
  4208. #endif
  4209. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4210. }
  4211. else
  4212. {
  4213. int status = setKeyValue(keystr, valuestr);
  4214. switch(status)
  4215. {
  4216. case ConfigurationStatus_Accepted:
  4217. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  4218. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  4219. StoreConfigurationTable();
  4220. break;
  4221. case ConfigurationStatus_Rejected:
  4222. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  4223. break;
  4224. case RebootRequired:
  4225. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  4226. StoreConfigurationTable();
  4227. break;
  4228. case NotSupported:
  4229. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  4230. break;
  4231. default:
  4232. break;
  4233. }
  4234. }
  4235. //confirmation.setStatus(ConfigurationStatus.Rejected);
  4236. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  4237. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  4238. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  4239. {
  4240. ChageWebSocketPingInterval(atoi(valuestr));
  4241. }
  4242. return result;
  4243. }
  4244. int handleClearCacheRequest(char *uuid, char *payload)
  4245. {
  4246. mtrace();
  4247. int result = FAIL;
  4248. char comfirmstr[20];
  4249. int fd;
  4250. char rmFileCmd[100]={0};
  4251. struct stat stats;
  4252. DEBUG_INFO("handle ClearCacheRequest\n");
  4253. stat("/Storage/OCPP", &stats);
  4254. // Check for directory existence
  4255. if (S_ISDIR(stats.st_mode) == 1)
  4256. {
  4257. //DEBUG_ERROR("\n OCPP directory exist \n");
  4258. }
  4259. else
  4260. {
  4261. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  4262. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  4263. system(rmFileCmd);
  4264. }
  4265. memset(rmFileCmd, 0, sizeof rmFileCmd);
  4266. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  4267. {
  4268. DEBUG_INFO("AuthorizationCache file exist.\n");
  4269. }
  4270. else
  4271. {
  4272. DEBUG_INFO("AuthorizationCache file not exist\n");
  4273. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  4274. if(log == NULL)
  4275. {
  4276. DEBUG_INFO("AuthorizationCache file is NULL\n");
  4277. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4278. goto end;
  4279. }
  4280. else
  4281. {
  4282. fclose(log);
  4283. }
  4284. }
  4285. fd = open(AuthorizationCache_JSON,O_RDWR);
  4286. if(fd < 0)
  4287. {
  4288. DEBUG_INFO("open AuthorizationCache file failed\n");
  4289. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  4290. }
  4291. else
  4292. {
  4293. DEBUG_INFO("open AuthorizationCache file successful\n");
  4294. //* 清空? 件 */
  4295. ftruncate(fd,0);
  4296. //* ? 新设置? 件? 移??*/
  4297. lseek(fd,0,SEEK_SET);
  4298. close(fd);
  4299. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  4300. //ShmOCPP16Data->MsMsg.bits.ClearCacheReq = 1; //OCPP handle byself
  4301. }
  4302. end:
  4303. sendClearCacheConfirmation(uuid, comfirmstr);
  4304. //ShmOCPP16Data->MsMsg.bits.ClearCacheConf = 1; //OCPP handle byself
  4305. return result;
  4306. }
  4307. int handleClearChargingProfileRequest(char *uuid, char *payload)
  4308. {
  4309. mtrace();
  4310. int result = FAIL;
  4311. int resultRename;
  4312. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  4313. char chargingProfilePurposeStr[26]={0};
  4314. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  4315. char tempchargingProfilePurposeStr[26]={0};
  4316. char sstr[160]={0},sstrtemp[160]={ 0 };//sstr[200]={ 0 };
  4317. char str[100]={0};
  4318. int c = 0;
  4319. //int i = 0;
  4320. //char * pch;
  4321. char *loc;
  4322. char fname[200]={0};
  4323. char comfirmstr[20]={0};
  4324. char word[1600]={0};
  4325. int clearflag = FALSE;
  4326. int chargingProfileIdIsNULL = FALSE;
  4327. int connectorIsNULL = FALSE;
  4328. int chargingProfilePurposeIsNULL = FALSE;
  4329. int stackLevelIsNULL = FALSE;
  4330. //int GotoEnd = FALSE;
  4331. FILE *fptr1, *fptr2;
  4332. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  4333. int n_chargingProfile=0;
  4334. int isEmptyFile = FALSE;
  4335. char sLineWord[1600]={0};
  4336. char chargingProfiles[10][100]={0};
  4337. int ChargeProfileCount = 0;
  4338. char ch;
  4339. DEBUG_INFO("handle ClearChargingProfileRequest\n");
  4340. strcpy(sstrtemp, stringtrimspace(payload));
  4341. connectorIdInt= chargingProfileIdInt= stackLevelInt =0;
  4342. //***id ****/
  4343. c = 0;
  4344. loc = strstr(sstrtemp, "id");
  4345. memset(sstr ,0, sizeof(sstr) );
  4346. if(loc == NULL)
  4347. {
  4348. chargingProfileIdIsNULL = TRUE;
  4349. }
  4350. else
  4351. {
  4352. while ((loc != NULL) &&((loc[strlen("id")+2+c] != ',')&& (loc[strlen("id")+2+c] != '}')))
  4353. {
  4354. sstr[c] = loc[strlen("id")+2+c];
  4355. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4356. c++;
  4357. }
  4358. sstr[c] = '\0';
  4359. chargingProfileIdInt = atoi(sstr);
  4360. }
  4361. //***connectorId ****/
  4362. c=0;
  4363. loc = strstr(sstrtemp, "connectorId");
  4364. memset(sstr ,0, sizeof(sstr) );
  4365. if(loc == NULL)
  4366. {
  4367. connectorIsNULL = TRUE;
  4368. }
  4369. else
  4370. {
  4371. while ((loc != NULL) &&((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}')))
  4372. {
  4373. sstr[c] = loc[strlen("connectorId")+2+c];
  4374. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4375. c++;
  4376. }
  4377. sstr[c] = '\0';
  4378. connectorIdInt = atoi(sstr);
  4379. }
  4380. //***chargingProfilePurpose ****/
  4381. loc = strstr(sstrtemp, "chargingProfilePurpose");
  4382. memset(sstr ,0, sizeof(sstr) );
  4383. c = 0;
  4384. if(loc == NULL)
  4385. {
  4386. chargingProfilePurposeIsNULL = TRUE;
  4387. }
  4388. else
  4389. {
  4390. while ((loc != NULL) &&(loc[3+strlen("chargingProfilePurpose")+c] != '\"'))
  4391. {
  4392. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4393. c++;
  4394. }
  4395. sstr[c] = '\0';
  4396. strcpy(chargingProfilePurposeStr, sstr);
  4397. }
  4398. //***stackLevel ****/
  4399. c=0;
  4400. loc = strstr(sstrtemp, "stackLevel");
  4401. memset(sstr ,0, sizeof(sstr) );
  4402. if(loc == NULL)
  4403. {
  4404. stackLevelIsNULL = TRUE;
  4405. }
  4406. else
  4407. {
  4408. while ((loc != NULL) &&((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ',')))
  4409. {
  4410. sstr[c] = loc[strlen("stackLevel")+2+c];
  4411. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4412. c++;
  4413. }
  4414. sstr[c] = '\0';
  4415. stackLevelInt = atoi(sstr);
  4416. }
  4417. if(connectorIsNULL == FALSE)
  4418. {
  4419. switch(connectorIdInt)
  4420. {
  4421. case 0:
  4422. if(chargingProfilePurposeIsNULL == TRUE)
  4423. {
  4424. int l = 0;
  4425. strcpy(fname, ChargePointMaxProfile_JSON);
  4426. if((access(fname,F_OK))!=-1)
  4427. {
  4428. strcpy(chargingProfiles[l], fname);
  4429. l = l + 1;
  4430. }
  4431. strcpy(fname, TxDefaultProfile_0_JSON);
  4432. if((access(fname,F_OK))!=-1)
  4433. {
  4434. strcpy(chargingProfiles[l], fname);
  4435. l = l + 1;
  4436. }
  4437. ChargeProfileCount = l;
  4438. }
  4439. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  4440. {
  4441. strcpy(fname, ChargePointMaxProfile_JSON);
  4442. if((access(fname,F_OK))!=-1)
  4443. {
  4444. strcpy(chargingProfiles[0], fname);
  4445. ChargeProfileCount = 1;
  4446. }
  4447. }
  4448. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4449. {
  4450. strcpy(fname, TxDefaultProfile_0_JSON);
  4451. if((access(fname,F_OK))!=-1)
  4452. {
  4453. strcpy(chargingProfiles[0], fname);
  4454. ChargeProfileCount = 1;
  4455. }
  4456. }
  4457. break;
  4458. default:
  4459. if(chargingProfilePurposeIsNULL == TRUE)
  4460. {
  4461. int m = 0;
  4462. memset(fname, 0, sizeof fname);
  4463. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4464. if((access(fname,F_OK))!=-1)
  4465. {
  4466. strcpy(chargingProfiles[m], fname);
  4467. m = m + 1;
  4468. }
  4469. memset(fname, 0, sizeof fname);
  4470. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4471. if((access(fname,F_OK))!=-1)
  4472. {
  4473. strcpy(chargingProfiles[m], fname);
  4474. m = m + 1;
  4475. }
  4476. ChargeProfileCount = m;
  4477. }
  4478. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  4479. {
  4480. //strcpy(fname, TxDefaultProfile_1_JSON);
  4481. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  4482. if((access(fname,F_OK))!=-1)
  4483. {
  4484. strcpy(chargingProfiles[0], fname);
  4485. ChargeProfileCount = 1;
  4486. }
  4487. }
  4488. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  4489. {
  4490. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  4491. if((access(fname,F_OK))!=-1)
  4492. {
  4493. strcpy(chargingProfiles[0], fname);
  4494. ChargeProfileCount = 1;
  4495. }
  4496. //strcpy(fname, TxProfile_1_JSON);
  4497. }
  4498. //strcpy(fname, ChargePointMaxProfile_JSON );
  4499. break;
  4500. }
  4501. }
  4502. else // Check all Charging Profiles
  4503. {
  4504. int i = 0;
  4505. char fnametemp[200]={0};
  4506. ChargeProfileCount = 0;
  4507. //Check ChargePointMaxProfile.json exit
  4508. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  4509. {
  4510. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  4511. i = i + 1;
  4512. }
  4513. //Check TxDefaultProfile_0.json exit
  4514. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  4515. {
  4516. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  4517. i = i + 1;
  4518. }
  4519. //Check TxDefaultProfile_%d.json
  4520. for(int j=1; j <= gunTotalNumber; j++)
  4521. {
  4522. memset(fnametemp, 0, sizeof fnametemp);
  4523. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  4524. if((access(fnametemp,F_OK))!=-1)
  4525. {
  4526. strcpy(chargingProfiles[i], fnametemp);
  4527. i = i + 1;
  4528. }
  4529. }
  4530. //Check TxProfile_%d.json
  4531. for(int j=1; j <= gunTotalNumber; j++)
  4532. {
  4533. memset(fnametemp, 0, sizeof fnametemp);
  4534. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  4535. if((access(fnametemp,F_OK))!=-1)
  4536. {
  4537. strcpy(chargingProfiles[i], fnametemp);
  4538. i = i + 1;
  4539. }
  4540. }
  4541. ChargeProfileCount = i;
  4542. }// End connectorIsNULL is TRUE
  4543. if(ChargeProfileCount == 0)
  4544. {
  4545. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4546. goto end;
  4547. }
  4548. #if 0
  4549. fptr1 = fopen(fname, "r");
  4550. if (!fptr1)
  4551. {
  4552. //file not exist
  4553. DEBUG_INFO("Unable to open the input file!!\n");
  4554. fptr1 = fopen(fname, "w+");
  4555. }
  4556. fclose(fptr1);
  4557. #endif
  4558. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  4559. {
  4560. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4561. goto end;
  4562. }
  4563. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  4564. {
  4565. memset(str, 0, sizeof str);
  4566. // clear temp file
  4567. sprintf(str,"rm -f %s",temp);
  4568. system(str);
  4569. for(int k=0; k < ChargeProfileCount; k++)
  4570. {
  4571. memset(str, 0, sizeof str);
  4572. //clear file in C
  4573. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4574. system(str);
  4575. }
  4576. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4577. goto end;
  4578. }
  4579. else if(connectorIsNULL == TRUE)
  4580. {
  4581. for(int k=0; k < ChargeProfileCount; k++)
  4582. {
  4583. fptr1 = fopen(chargingProfiles[k], "r");
  4584. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  4585. //Check Charging Profile Count
  4586. while(fscanf(fptr1, "%s", word) != EOF)
  4587. {
  4588. //DEBUG_INFO("word=%s\n",word);
  4589. if(strstr(word, "chargingProfileId")!= NULL)
  4590. {
  4591. //DEBUG_INFO("test chargingProfileId \n");
  4592. n_chargingProfile = n_chargingProfile + 1;
  4593. //DEBUG_INFO("chargingProfileId Found\n");
  4594. }
  4595. }
  4596. rewind(fptr1);
  4597. //search Charging Profile Element
  4598. //int i= 0;
  4599. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4600. {
  4601. //------------------------tempconnectorIdInt------------------------//
  4602. loc = strstr(sLineWord, "connectorId");
  4603. c = 0;
  4604. memset(sstr ,0, sizeof(sstr) );
  4605. while (loc[strlen("connectorId")+2+c] != ',')
  4606. {
  4607. sstr[c] = loc[strlen("connectorId")+2+c];
  4608. c++;
  4609. }
  4610. sstr[c] = '\0';
  4611. tempconnectorIdInt = atoi(sstr);
  4612. printf("file's gun number is %d\n", tempconnectorIdInt);
  4613. //--------------------------chargingProfileId--------------------//
  4614. c = 0;
  4615. loc = strstr(sLineWord, "chargingProfileId");
  4616. memset(sstr ,0, sizeof(sstr) );
  4617. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4618. {
  4619. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4620. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4621. c++;
  4622. }
  4623. sstr[c] = '\0';
  4624. tempchargingProfileIdInt = atoi(sstr);
  4625. //stackLevel
  4626. c = 0;
  4627. loc = strstr(sLineWord, "stackLevel");
  4628. memset(sstr ,0, sizeof(sstr) );
  4629. while (loc[strlen("stackLevel")+2+c] != ',')
  4630. {
  4631. sstr[c] = loc[strlen("stackLevel")+2+c];
  4632. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4633. c++;
  4634. }
  4635. sstr[c] = '\0';
  4636. tempstackLevelInt = atoi(sstr);
  4637. c = 0;
  4638. loc = strstr(sLineWord, "chargingProfilePurpose");
  4639. memset(sstr ,0, sizeof(sstr) );
  4640. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4641. {
  4642. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4643. c++;
  4644. }
  4645. sstr[c] = '\0';
  4646. strcpy(tempchargingProfilePurposeStr, sstr);
  4647. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4648. {
  4649. //------- not write to fptr2-------//
  4650. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4651. //clearflag = TRUE;
  4652. }
  4653. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  4654. {
  4655. //------- not write to fptr2-------//
  4656. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4657. }
  4658. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4659. {
  4660. //------- not write to fptr2-------//
  4661. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4662. }
  4663. else
  4664. {
  4665. fprintf(fptr2, sLineWord);//writing data into file
  4666. }
  4667. memset(sLineWord, 0, sizeof sLineWord);
  4668. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4669. if(clearflag == TRUE)
  4670. {
  4671. fclose(fptr1);
  4672. fclose(fptr2);
  4673. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4674. system(str);
  4675. // clear temp file
  4676. sprintf(str,"rm -f %s",temp);
  4677. system(str);
  4678. }
  4679. else
  4680. {
  4681. fclose(fptr1);
  4682. fclose(fptr2);
  4683. memset(str, 0, sizeof str);
  4684. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4685. system(str);
  4686. resultRename = rename(temp, chargingProfiles[k]);
  4687. if(resultRename == 0)
  4688. {
  4689. DEBUG_INFO("File ChargingProfile renamed successfully");
  4690. }
  4691. else
  4692. {
  4693. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4694. }
  4695. if(comfirmstr[0]== 0)
  4696. {
  4697. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4698. }
  4699. //Check chargingProfile is empty file
  4700. /*------ Read the file ----------------*/
  4701. fptr1=fopen(chargingProfiles[k],"r");
  4702. ch=fgetc(fptr1);
  4703. rewind(fptr1);
  4704. memset(sLineWord, 0, sizeof sLineWord);
  4705. if(ch!=EOF)
  4706. {
  4707. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4708. {
  4709. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4710. if(sLineWord[0]=='\0')
  4711. {
  4712. isEmptyFile = TRUE;
  4713. break;
  4714. }
  4715. else
  4716. {
  4717. isEmptyFile = FALSE;
  4718. break;
  4719. }
  4720. }
  4721. }
  4722. fclose(fptr1);
  4723. if(isEmptyFile == TRUE)
  4724. {
  4725. memset(str, 0, sizeof str);
  4726. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4727. system(str);
  4728. }
  4729. }
  4730. }// End of while(int k=0; k < ChargePointCount; k++)
  4731. }
  4732. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  4733. {
  4734. DEBUG_INFO("ChargeProfileCount=%d\n",ChargeProfileCount);
  4735. for(int k=0; k < ChargeProfileCount; k++)
  4736. {
  4737. fptr1 = fopen(chargingProfiles[k], "r");
  4738. fptr2 = fopen(temp, "w+");
  4739. //Check Charging Profile Count
  4740. while(fscanf(fptr1, "%s", word) != EOF)
  4741. {
  4742. //DEBUG_INFO("word=%s\n",word);
  4743. if(strstr(word, "chargingProfileId")!= NULL)
  4744. {
  4745. //DEBUG_INFO("test chargingProfileId \n");
  4746. n_chargingProfile = n_chargingProfile + 1;
  4747. //DEBUG_INFO("chargingProfileId Found\n");
  4748. }
  4749. }
  4750. rewind(fptr1);
  4751. //search Charging Profile Element
  4752. //int i= 0;
  4753. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  4754. {
  4755. //*************************tempconnectorIdInt*********************************/
  4756. loc = strstr(sLineWord, "connectorId");
  4757. c = 0;
  4758. memset(sstr ,0, sizeof(sstr) );
  4759. while (loc[strlen("connectorId")+2+c] != ',')
  4760. {
  4761. sstr[c] = loc[strlen("connectorId")+2+c];
  4762. c++;
  4763. }
  4764. sstr[c] = '\0';
  4765. tempconnectorIdInt = atoi(sstr);
  4766. //chargingProfileId
  4767. c = 0;
  4768. loc = strstr(sLineWord, "chargingProfileId");
  4769. memset(sstr ,0, sizeof(sstr) );
  4770. while (loc[strlen("chargingProfileId")+2+c] != ',')
  4771. {
  4772. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  4773. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4774. c++;
  4775. }
  4776. sstr[c] = '\0';
  4777. tempchargingProfileIdInt = atoi(sstr);
  4778. //stackLevel
  4779. c = 0;
  4780. loc = strstr(sLineWord, "stackLevel");
  4781. memset(sstr ,0, sizeof(sstr) );
  4782. while (loc[strlen("stackLevel")+2+c] != ',')
  4783. {
  4784. sstr[c] = loc[strlen("stackLevel")+2+c];
  4785. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4786. c++;
  4787. }
  4788. sstr[c] = '\0';
  4789. tempstackLevelInt = atoi(sstr);
  4790. c = 0;
  4791. loc = strstr(sLineWord, "chargingProfilePurpose");
  4792. memset(sstr ,0, sizeof(sstr) );
  4793. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  4794. {
  4795. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  4796. c++;
  4797. }
  4798. sstr[c] = '\0';
  4799. strcpy(tempchargingProfilePurposeStr, sstr);
  4800. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  4801. {
  4802. //------- not write to fptr2-------//
  4803. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4804. //clearflag = TRUE;
  4805. }
  4806. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  4807. {
  4808. //------- not write to fptr2-------//
  4809. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4810. }
  4811. else if(stackLevelIsNULL == TRUE)
  4812. {
  4813. //Clear Whole File
  4814. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  4815. clearflag = TRUE;
  4816. break;
  4817. }
  4818. else
  4819. {
  4820. fprintf(fptr2, sLineWord);//writing data into file
  4821. }
  4822. memset(sLineWord, 0, sizeof sLineWord);
  4823. }
  4824. if(clearflag == TRUE)
  4825. {
  4826. fclose(fptr1);
  4827. fclose(fptr2);
  4828. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4829. system(str);
  4830. // clear temp file
  4831. sprintf(str,"rm -f %s",temp);
  4832. system(str);
  4833. }
  4834. else
  4835. {
  4836. fclose(fptr1);
  4837. fclose(fptr2);
  4838. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4839. system(str);
  4840. resultRename = rename(temp, chargingProfiles[k]);
  4841. if(resultRename == 0)
  4842. {
  4843. DEBUG_INFO("File ChargingProfile renamed successfully");
  4844. }
  4845. else
  4846. {
  4847. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  4848. }
  4849. if(comfirmstr[0]== 0)
  4850. {
  4851. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  4852. }
  4853. //Check chargingProfile is empty file
  4854. /*------ Read the file ----------------*/
  4855. fptr1=fopen(chargingProfiles[k],"r");
  4856. ch=fgetc(fptr1);
  4857. rewind(fptr1);
  4858. memset(sLineWord, 0, sizeof sLineWord);
  4859. if(ch!=EOF)
  4860. {
  4861. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  4862. {
  4863. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  4864. if(sLineWord[0]=='\0')
  4865. {
  4866. isEmptyFile = TRUE;
  4867. break;
  4868. }
  4869. else
  4870. {
  4871. isEmptyFile = FALSE;
  4872. break;
  4873. }
  4874. }
  4875. }
  4876. fclose(fptr1);
  4877. if(isEmptyFile == TRUE)
  4878. {
  4879. memset(str, 0, sizeof str);
  4880. sprintf(str,"rm -f %s",chargingProfiles[k]);
  4881. system(str);
  4882. }
  4883. /*------- End of reading ---------------*/
  4884. }
  4885. } // while(int k=0; k < ChargeProfileCount; k++)
  4886. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  4887. end:
  4888. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  4889. return result;
  4890. }
  4891. int handleDataTransferRequest(char *uuid, char *payload)
  4892. {
  4893. mtrace();
  4894. int result = FAIL;
  4895. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  4896. char tempvendorId[255]={0};
  4897. char tempmessageId[50]={0};
  4898. char tempdata[50]={0};
  4899. char sstr[160]={0};//sstr[200]={ 0 };
  4900. char message[80]={0};
  4901. int c = 0;
  4902. char *loc;
  4903. DEBUG_INFO("handle DataTransferRequest\n");
  4904. if((uuid != NULL) && (payload != NULL))
  4905. {
  4906. //===============================
  4907. // vendorId
  4908. //===============================
  4909. c = 0;
  4910. loc = strstr(payload, "vendorId");
  4911. while (loc[strlen("vendorId")+3+c] != '\"')
  4912. {
  4913. sstr[c] = loc[strlen("vendorId")+3+c];
  4914. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4915. c++;
  4916. }
  4917. sstr[c] = '\0';
  4918. strcpy(tempvendorId,sstr);
  4919. //===============================
  4920. // messageId
  4921. //===============================
  4922. memset(sstr ,0, sizeof(sstr) );
  4923. c = 0;
  4924. loc = strstr(payload, "messageId");
  4925. while (loc[strlen("messageId")+3+c] != '\"')
  4926. {
  4927. sstr[c] = loc[strlen("messageId")+3+c];
  4928. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4929. c++;
  4930. }
  4931. sstr[c] = '\0';
  4932. strcpy(tempmessageId,sstr);
  4933. //===============================
  4934. // data
  4935. //===============================
  4936. memset(sstr ,0, sizeof(sstr) );
  4937. c = 0;
  4938. loc = strstr(payload, "data");
  4939. printf("loc=%s\n",loc);
  4940. while (loc[strlen("data")+3+c] != '\"')
  4941. {
  4942. sstr[c] = loc[strlen("data")+3+c];
  4943. //printf("i=%d sstr=%c\n",c, sstr[c]);
  4944. c++;
  4945. }
  4946. sstr[c] = '\0';
  4947. strcpy(tempdata,sstr);
  4948. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  4949. }
  4950. else
  4951. {
  4952. char guid[37]={0};
  4953. random_uuid(guid);
  4954. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  4955. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  4956. }
  4957. LWS_Send(message);
  4958. return result;
  4959. }
  4960. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  4961. {
  4962. mtrace();
  4963. int result = FAIL;
  4964. int connectorIdInt, durationInt;
  4965. char chargingRateUnitStr[4]={0};
  4966. //int tempconnectorIdInt,
  4967. int tempdurationInt;
  4968. float tempminChargingRateFloat = 0.0;
  4969. char tempvalidFromStr[30]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  4970. int tempStartPeriodInt=0;
  4971. float tempLimitInt=0.0;//0.1;
  4972. int tempNumberPhasesInt=0;
  4973. char fname[200];
  4974. char comfirmstr[20];
  4975. //float totallimit =0.0;
  4976. float MinChargingRate =0.0;
  4977. //double diff_t;
  4978. //struct tm tp;
  4979. FILE *fptr1;
  4980. int c = 0;
  4981. //int i = 0;
  4982. char * pch;
  4983. char *loc;
  4984. char sstr[200]={ 0 },sstrtemp[50]={ 0 };
  4985. int n_chargingProfile = 0;
  4986. int n_SchedulePeriods = 0;
  4987. char SchedulePeriodList[10][200]={0};
  4988. char sLineWord[1600]={0};
  4989. //int n_periods = 0;
  4990. char word[1000]={0};
  4991. int confirmPeriods = 0;
  4992. struct StructProfile ChargePointMaxProfile;
  4993. struct StructProfile TxDefaultProfile;
  4994. struct StructProfile TxProfile;
  4995. struct StructProfile TxDefaultProfiletemp[2]={0};
  4996. int TxDefaultProfileFileIsNull=FALSE;
  4997. int ChargePointMaxProfileIsNull=FALSE;
  4998. int TxProfileIsNull=FALSE;
  4999. int CompositeSceduleIndex = 0;
  5000. char ChargePointMaxProfileScheduleStr[30]={0};
  5001. char TxDefaultProfileScheduleStr[30]={0};
  5002. char TxProfileScheduleStr[30]={0};
  5003. DEBUG_INFO("handleGetCompositeScheduleRequest\n");
  5004. strcpy(sstrtemp, stringtrimspace(payload));
  5005. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  5006. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  5007. memset(&TxProfile,0,sizeof(struct StructProfile));
  5008. c=0;
  5009. loc = strstr(sstrtemp, "connectorId");
  5010. memset(sstr ,0, sizeof(sstr) );
  5011. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  5012. {
  5013. sstr[c] = loc[strlen("connectorId")+2+c];
  5014. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5015. c++;
  5016. }
  5017. sstr[c] = '\0';
  5018. connectorIdInt = atoi(sstr);
  5019. c=0;
  5020. loc = strstr(sstrtemp, "duration");
  5021. memset(sstr ,0, sizeof(sstr) );
  5022. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  5023. {
  5024. sstr[c] = loc[strlen("duration")+2+c];
  5025. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5026. c++;
  5027. }
  5028. sstr[c] = '\0';
  5029. durationInt = atoi(sstr);
  5030. c = 0;
  5031. loc = strstr(sstrtemp, "chargingRateUnit");
  5032. memset(sstr ,0, sizeof(sstr) );
  5033. if(loc == NULL)
  5034. {
  5035. }
  5036. else
  5037. {
  5038. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5039. {
  5040. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5041. c++;
  5042. }
  5043. sstr[c] = '\0';
  5044. strcpy(chargingRateUnitStr, sstr);
  5045. }
  5046. CompositeSceduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) :0;
  5047. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/ );
  5048. if(connectorIdInt==0) // connectorId is 0
  5049. {
  5050. //******************************ChargePointMaxProfile*****************************************************/
  5051. strcpy(fname, ChargePointMaxProfile_JSON );
  5052. char word[30]={0};
  5053. char sLineWord[1060]={0};
  5054. int n_chargingProfile=0;
  5055. ChargePointMaxProfileIsNull=TRUE;
  5056. if((access(fname,F_OK))!=-1)
  5057. {
  5058. fptr1 = fopen(fname, "r");
  5059. int c;
  5060. c = fgetc(fptr1);
  5061. //DEBUG_INFO("c:%d\n",c);
  5062. rewind(fptr1);
  5063. if(c == EOF)
  5064. {
  5065. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5066. ChargePointMaxProfileIsNull=TRUE;
  5067. fclose(fptr1);
  5068. }
  5069. else
  5070. {
  5071. ChargePointMaxProfileIsNull=FALSE;
  5072. while(fscanf(fptr1, "%s", word) != EOF)
  5073. {
  5074. if(strcmp(word, "chargingProfileId") == 0)
  5075. {
  5076. n_chargingProfile = n_chargingProfile + 1;
  5077. printf("Found\n");
  5078. }
  5079. }
  5080. rewind(fptr1);
  5081. //search Charging Profile Element
  5082. int i= 0;
  5083. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5084. #if 0
  5085. /***********connectorId****************/
  5086. c = 0;
  5087. loc = strstr(sLineWord, "connectorId");
  5088. // printf("loc=%s\n",loc);
  5089. memset(sstr ,0, sizeof(sstr) );
  5090. while (loc[strlen("connectorId")+2+c] != ',')
  5091. {
  5092. sstr[c] = loc[strlen("connectorId")+2+c];
  5093. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5094. c++;
  5095. }
  5096. sstr[c] = '\0';
  5097. tempconnectorIdInt = atoi(sstr);
  5098. #endif
  5099. //***********validFrom**************/
  5100. c = 0;
  5101. loc = strstr(sLineWord, "validFrom");
  5102. //DEBUG_INFO("loc=%s\n",loc);
  5103. memset(sstr ,0, sizeof(sstr) );
  5104. if(loc != NULL)
  5105. {
  5106. while (loc[3+strlen("validFrom")+c] != '\"')
  5107. {
  5108. sstr[c] = loc[3+strlen("validFrom")+c];
  5109. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5110. c++;
  5111. }
  5112. sstr[c] = '\0';
  5113. DEBUG_INFO("validFrom=%s\n",sstr);
  5114. strcpy(tempvalidFromStr,sstr);
  5115. }
  5116. else
  5117. {
  5118. strcpy(tempvalidFromStr,"");
  5119. }
  5120. //**********startSchedule**********/
  5121. c = 0;
  5122. loc = strstr(sLineWord, "startSchedule");
  5123. //DEBUG_INFO("loc=%s\n",loc);
  5124. memset(sstr ,0, sizeof(sstr) );
  5125. if(loc != NULL)
  5126. {
  5127. while (loc[3+strlen("startSchedule")+c] != '\"')
  5128. {
  5129. sstr[c] = loc[3+strlen("startSchedule")+c];
  5130. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5131. c++;
  5132. }
  5133. sstr[c] = '\0';
  5134. strcpy(tempstartScheduleStr, sstr);
  5135. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5136. }
  5137. else
  5138. {
  5139. strcpy(tempstartScheduleStr, "");
  5140. strcpy(ChargePointMaxProfileScheduleStr, "");
  5141. }
  5142. //**********chargingRateUnit**********/
  5143. c = 0;
  5144. loc = strstr(sLineWord, "chargingRateUnit");
  5145. memset(sstr ,0, sizeof(sstr) );
  5146. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5147. {
  5148. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5149. c++;
  5150. }
  5151. sstr[c] = '\0';
  5152. strcpy(tempchargingRateUnitStr, sstr);
  5153. //**********minChargingRate*******/
  5154. c = 0;
  5155. loc = strstr(sLineWord, "minChargingRate");
  5156. //printf("loc=%s\n",loc);
  5157. if(loc != NULL)
  5158. {
  5159. memset(sstr ,0, sizeof(sstr) );
  5160. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5161. {
  5162. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5164. c++;
  5165. }
  5166. sstr[c] = '\0';
  5167. tempminChargingRateFloat = atof(sstr);
  5168. }
  5169. else
  5170. {
  5171. tempminChargingRateFloat = 0.0;
  5172. }
  5173. //
  5174. #if 0
  5175. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5176. tp.tm_isdst = -1;
  5177. time_t utc = mktime(&tp);
  5178. // current time
  5179. time_t t = time(NULL);
  5180. #endif
  5181. //diff_t = difftime(t, utc);
  5182. //parsing strings to words
  5183. i = 0;
  5184. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5185. loc = loc+3+strlen("chargingSchedulePeriod");
  5186. pch = strtok(loc ,"{");
  5187. while (pch != NULL)
  5188. {
  5189. strcpy(SchedulePeriodList[i], pch);
  5190. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5191. //printf ("%s\n",pch);
  5192. pch = strtok (NULL, "{");
  5193. i = i + 1;
  5194. }
  5195. n_SchedulePeriods = i;
  5196. for(int i=0;i<n_SchedulePeriods;i++)
  5197. {
  5198. //*************startPeriod****************/
  5199. c = 0;
  5200. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5201. memset(sstr ,0, sizeof(sstr) );
  5202. while (loc[strlen("startPeriod")+2+c] != ',')
  5203. {
  5204. sstr[c] = loc[strlen("startPeriod")+2+c];
  5205. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5206. c++;
  5207. }
  5208. sstr[c] = '\0';
  5209. tempStartPeriodInt = atoi(sstr);
  5210. //*************limit****************/
  5211. c = 0;
  5212. loc = strstr(SchedulePeriodList[i], "limit");
  5213. memset(sstr ,0, sizeof(sstr) );
  5214. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5215. {
  5216. sstr[c] = loc[strlen("limit")+2+c];
  5217. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5218. c++;
  5219. }
  5220. sstr[c] = '\0';
  5221. tempLimitInt = atof(sstr);
  5222. //*************numberPhases****************/
  5223. c = 0;
  5224. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5225. memset(sstr ,0, sizeof(sstr) );
  5226. if(loc != NULL)
  5227. {
  5228. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5229. {
  5230. sstr[c] = loc[strlen("numberPhases")+2+c];
  5231. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5232. c++;
  5233. }
  5234. sstr[c] = '\0';
  5235. tempNumberPhasesInt = atoi(sstr);
  5236. }
  5237. else
  5238. {
  5239. tempNumberPhasesInt = 0;
  5240. }
  5241. ChargePointMaxProfile.Duration = durationInt;
  5242. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5243. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5244. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5245. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5246. }
  5247. if(MinChargingRate < tempminChargingRateFloat)
  5248. MinChargingRate = tempminChargingRateFloat;
  5249. }
  5250. }// End of file ChargingProfile
  5251. } //THE END OF ACCESS ChargePointMaxProfile
  5252. //******************************TxDefaultProfile***********************************************/
  5253. strcpy(fname, TxDefaultProfile_0_JSON);
  5254. memset(word, 0, 30);
  5255. memset(sLineWord, 0, 1060);
  5256. //char word[30]={0};
  5257. //char sLineWord[1060]={0};
  5258. n_chargingProfile=0;
  5259. TxDefaultProfileFileIsNull=TRUE;
  5260. if((access(fname,F_OK))!=-1)
  5261. {
  5262. fptr1 = fopen(fname, "r");
  5263. c = 0;
  5264. c = fgetc(fptr1);
  5265. //DEBUG_INFO("c:%d\n",c);
  5266. rewind(fptr1);
  5267. if(c == EOF)
  5268. {
  5269. DEBUG_INFO("\n End of file ChargingProfile reached.");
  5270. TxDefaultProfileFileIsNull=TRUE;
  5271. fclose(fptr1);
  5272. }
  5273. else
  5274. {
  5275. TxDefaultProfileFileIsNull=FALSE;
  5276. while(fscanf(fptr1, "%s", word) != EOF)
  5277. {
  5278. if(strcmp(word, "chargingProfileId") == 0)
  5279. {
  5280. n_chargingProfile = n_chargingProfile + 1;
  5281. printf("Found\n");
  5282. }
  5283. }
  5284. rewind(fptr1);
  5285. //search Charging Profile Element
  5286. int i= 0;
  5287. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5288. #if 0
  5289. /***********connectorId****************/
  5290. c = 0;
  5291. loc = strstr(sLineWord, "connectorId");
  5292. // printf("loc=%s\n",loc);
  5293. memset(sstr ,0, sizeof(sstr) );
  5294. while (loc[strlen("connectorId")+2+c] != ',')
  5295. {
  5296. sstr[c] = loc[strlen("connectorId")+2+c];
  5297. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5298. c++;
  5299. }
  5300. sstr[c] = '\0';
  5301. DEBUG_INFO("connectorId=%d\n",atoi(sstr));
  5302. tempconnectorIdInt = atoi(sstr);
  5303. #endif
  5304. //***********validFrom**************/
  5305. c = 0;
  5306. loc = strstr(sLineWord, "validFrom");
  5307. //DEBUG_INFO("loc=%s\n",loc);
  5308. memset(sstr ,0, sizeof(sstr) );
  5309. if(loc != NULL)
  5310. {
  5311. while (loc[3+strlen("validFrom")+c] != '\"')
  5312. {
  5313. sstr[c] = loc[3+strlen("validFrom")+c];
  5314. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5315. c++;
  5316. }
  5317. sstr[c] = '\0';
  5318. DEBUG_INFO("validFrom=%s\n",sstr);
  5319. strcpy(tempvalidFromStr,sstr);
  5320. }
  5321. else
  5322. {
  5323. strcpy(tempvalidFromStr,"");
  5324. }
  5325. //**********startSchedule**********/
  5326. c = 0;
  5327. loc = strstr(sLineWord, "startSchedule");
  5328. //DEBUG_INFO("loc=%s\n",loc);
  5329. memset(sstr ,0, sizeof(sstr) );
  5330. if(loc != NULL)
  5331. {
  5332. while (loc[3+strlen("startSchedule")+c] != '\"')
  5333. {
  5334. sstr[c] = loc[3+strlen("startSchedule")+c];
  5335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5336. c++;
  5337. }
  5338. sstr[c] = '\0';
  5339. strcpy(tempstartScheduleStr, sstr);
  5340. strcpy(TxDefaultProfileScheduleStr, sstr);
  5341. }
  5342. else
  5343. {
  5344. strcpy(tempstartScheduleStr, "");
  5345. strcpy(TxDefaultProfileScheduleStr, "");
  5346. }
  5347. //**********chargingRateUnit**********/
  5348. c = 0;
  5349. loc = strstr(sLineWord, "chargingRateUnit");
  5350. memset(sstr ,0, sizeof(sstr) );
  5351. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5352. {
  5353. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5354. c++;
  5355. }
  5356. sstr[c] = '\0';
  5357. strcpy(tempchargingRateUnitStr, sstr);
  5358. //**********minChargingRate*******/
  5359. c = 0;
  5360. loc = strstr(sLineWord, "minChargingRate");
  5361. //printf("loc=%s\n",loc);
  5362. if(loc != NULL)
  5363. {
  5364. memset(sstr ,0, sizeof(sstr) );
  5365. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5366. {
  5367. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5368. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5369. c++;
  5370. }
  5371. sstr[c] = '\0';
  5372. tempminChargingRateFloat = atof(sstr);
  5373. }
  5374. else
  5375. {
  5376. tempminChargingRateFloat = 0.0;
  5377. }
  5378. #if 0
  5379. //
  5380. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5381. tp.tm_isdst = -1;
  5382. time_t utc = mktime(&tp);
  5383. // current time
  5384. time_t t = time(NULL);
  5385. //diff_t = difftime(t, utc);
  5386. #endif
  5387. //parsing strings to words
  5388. i = 0;
  5389. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5390. loc = loc+3+strlen("chargingSchedulePeriod");
  5391. pch = strtok(loc ,"{");
  5392. while (pch != NULL)
  5393. {
  5394. strcpy(SchedulePeriodList[i], pch);
  5395. //printf ("SchedulePeriodList[%d]:%s\n",i,SchedulePeriodList[i]);
  5396. //printf ("%s\n",pch);
  5397. pch = strtok (NULL, "{");
  5398. i = i + 1;
  5399. }
  5400. n_SchedulePeriods = i;
  5401. for(int i=0;i<n_SchedulePeriods;i++)
  5402. {
  5403. //*************startPeriod****************/
  5404. c = 0;
  5405. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5406. memset(sstr ,0, sizeof(sstr) );
  5407. while (loc[strlen("startPeriod")+2+c] != ',')
  5408. {
  5409. sstr[c] = loc[strlen("startPeriod")+2+c];
  5410. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5411. c++;
  5412. }
  5413. sstr[c] = '\0';
  5414. tempStartPeriodInt = atoi(sstr);
  5415. //*************limit****************/
  5416. c = 0;
  5417. loc = strstr(SchedulePeriodList[i], "limit");
  5418. memset(sstr ,0, sizeof(sstr) );
  5419. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5420. {
  5421. sstr[c] = loc[strlen("limit")+2+c];
  5422. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5423. c++;
  5424. }
  5425. sstr[c] = '\0';
  5426. tempLimitInt = atof(sstr);
  5427. //*************numberPhases****************/
  5428. c = 0;
  5429. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5430. memset(sstr ,0, sizeof(sstr) );
  5431. if(loc != NULL)
  5432. {
  5433. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5434. {
  5435. sstr[c] = loc[strlen("numberPhases")+2+c];
  5436. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5437. c++;
  5438. }
  5439. sstr[c] = '\0';
  5440. tempNumberPhasesInt = atoi(sstr);
  5441. }
  5442. else
  5443. {
  5444. tempNumberPhasesInt = 0;
  5445. }
  5446. TxDefaultProfile.Duration = durationInt;
  5447. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5448. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5449. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5450. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5451. }
  5452. if(MinChargingRate < tempminChargingRateFloat)
  5453. MinChargingRate = tempminChargingRateFloat;
  5454. }
  5455. }
  5456. }// the end of ACCESS TxDefaultProfile
  5457. //--------------------- Composite Schedule-----------------------------//
  5458. if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==FALSE))
  5459. {
  5460. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5461. struct tm tp;
  5462. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5463. tp.tm_isdst = -1;
  5464. time_t utc = mktime(&tp);
  5465. time_t t = time(NULL);
  5466. double diff_f = difftime(t, utc);
  5467. int diff_i; //= (int)diff_f;
  5468. int quotient; //= diff_i / 86400;//86400 seconds/day
  5469. int period = 0;
  5470. if(diff_f >= 0)
  5471. {
  5472. diff_i = (int)diff_f;
  5473. quotient = diff_i / 86400;
  5474. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5475. {
  5476. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5477. {
  5478. if(ChargePointMaxProfile.Period[0].Limit > TxDefaultProfile.Period[index].Limit)
  5479. {
  5480. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5481. }
  5482. else
  5483. {
  5484. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  5485. }
  5486. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5487. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5488. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5489. period = period + 1;
  5490. }
  5491. }
  5492. }
  5493. confirmPeriods = period;
  5494. }
  5495. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==FALSE))
  5496. {
  5497. strcpy(CurrentChargingProfileScheduleStr, TxDefaultProfileScheduleStr);
  5498. struct tm tp;
  5499. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5500. tp.tm_isdst = -1;
  5501. time_t utc = mktime(&tp);
  5502. time_t t = time(NULL);
  5503. double diff_f = difftime(t, utc);
  5504. int diff_i; // = (int)diff_f;
  5505. int quotient; // = diff_i / 86400;//86400 seconds/day
  5506. int period = 0;
  5507. if(diff_f >= 0)
  5508. {
  5509. diff_i = (int)diff_f;
  5510. quotient = diff_i / 86400;//86400 seconds/day
  5511. for(int index=0; index < TxDefaultProfile.TotalPeriod ; index++)
  5512. {
  5513. if(((TxDefaultProfile.Period[index].StartPeriod % 86400) < durationInt) && ((TxDefaultProfile.Period[index].StartPeriod / 86400) == quotient))
  5514. {
  5515. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[index].Limit;
  5516. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[index].NumberPhases; //for discussion
  5517. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[index].StartPeriod % 86400);
  5518. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5519. period = period + 1;
  5520. }
  5521. }
  5522. }
  5523. confirmPeriods = period;
  5524. }
  5525. else if((ChargePointMaxProfileIsNull==FALSE)&&(TxDefaultProfileFileIsNull==TRUE))
  5526. {
  5527. strcpy(CurrentChargingProfileScheduleStr, ChargePointMaxProfileScheduleStr);
  5528. for(int index=0; index < ChargePointMaxProfile.TotalPeriod ; index++)
  5529. {
  5530. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].Limit = ChargePointMaxProfile.Period[index].Limit;
  5531. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].NumberPhases = ChargePointMaxProfile.Period[index].NumberPhases; //for discussion
  5532. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[index].StartPeriod = ChargePointMaxProfile.Period[index].StartPeriod;
  5533. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = TxDefaultProfile.Duration;
  5534. }
  5535. confirmPeriods = ChargePointMaxProfile.TotalPeriod;
  5536. }
  5537. else if((ChargePointMaxProfileIsNull==TRUE)&&(TxDefaultProfileFileIsNull==TRUE))
  5538. {
  5539. confirmPeriods = 0;
  5540. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  5541. //goto end;
  5542. }
  5543. //* Define temporary variables */
  5544. struct tm *gtime;
  5545. time_t now;
  5546. char buf[28];
  5547. /* Read the current system time */
  5548. time(&now);
  5549. /* Convert the system time to GMT (now UTC) */
  5550. gtime = gmtime(&now);
  5551. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  5552. // make .conf
  5553. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  5554. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  5555. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  5556. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  5557. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  5558. }
  5559. else if ((connectorIdInt > 0)&&((connectorIdInt -1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/) )
  5560. {
  5561. //*****************************ChargePointMaxProfile******************************************/
  5562. strcpy(fname, ChargePointMaxProfile_JSON);
  5563. ChargePointMaxProfileIsNull=TRUE;
  5564. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  5565. {
  5566. fptr1 = fopen(fname, "r");
  5567. int c;
  5568. c = fgetc(fptr1);
  5569. //DEBUG_INFO("c:%d\n",c);
  5570. rewind(fptr1);
  5571. if(c == EOF)
  5572. {
  5573. DEBUG_INFO("\n End of file reached.");
  5574. ChargePointMaxProfileIsNull=TRUE;
  5575. fclose(fptr1);
  5576. }
  5577. else
  5578. {
  5579. ChargePointMaxProfileIsNull=FALSE;
  5580. while(fscanf(fptr1, "%s", word) != EOF)
  5581. {
  5582. if(strcmp(word, "chargingProfileId") == 0)
  5583. {
  5584. n_chargingProfile = n_chargingProfile + 1;
  5585. }
  5586. }
  5587. rewind(fptr1);
  5588. //search Charging Profile Element
  5589. int i = 0;
  5590. int j = 0;
  5591. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5592. #if 0
  5593. /***********connectorId****************/
  5594. c = 0;
  5595. loc = strstr(sLineWord, "connectorId");
  5596. memset(sstr ,0, sizeof(sstr) );
  5597. while (loc[strlen("connectorId")+2+c] != ',')
  5598. {
  5599. sstr[c] = loc[strlen("connectorId")+2+c];
  5600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5601. c++;
  5602. }
  5603. sstr[c] = '\0';
  5604. tempconnectorIdInt = atoi(sstr);
  5605. #endif
  5606. //***********validFrom**************/
  5607. c = 0;
  5608. loc = strstr(sLineWord, "validFrom");
  5609. if(loc != NULL)
  5610. {
  5611. memset(sstr ,0, sizeof(sstr) );
  5612. while (loc[3+strlen("validFrom")+c] != '\"')
  5613. {
  5614. sstr[c] = loc[3+strlen("validFrom")+c];
  5615. c++;
  5616. }
  5617. sstr[c] = '\0';
  5618. strcpy(tempvalidFromStr,sstr);
  5619. }
  5620. else
  5621. {
  5622. strcpy(tempvalidFromStr,"");
  5623. }
  5624. //***********validFrom**************/
  5625. c = 0;
  5626. loc = strstr(sLineWord, "duration");
  5627. if(loc != NULL)
  5628. {
  5629. memset(sstr ,0, sizeof(sstr) );
  5630. while (loc[2+strlen("duration")+c] != ',')
  5631. {
  5632. sstr[c] = loc[2+strlen("duration")+c];
  5633. c++;
  5634. }
  5635. sstr[c] = '\0';
  5636. tempdurationInt = atoi(sstr);
  5637. }
  5638. else
  5639. {
  5640. tempdurationInt = 0;
  5641. }
  5642. //**********startSchedule**********/
  5643. c = 0;
  5644. loc = strstr(sLineWord, "startSchedule");
  5645. memset(sstr ,0, sizeof(sstr) );
  5646. if(loc != NULL)
  5647. {
  5648. while (loc[3+strlen("startSchedule")+c] != '\"')
  5649. {
  5650. sstr[c] = loc[3+strlen("startSchedule")+c];
  5651. c++;
  5652. }
  5653. sstr[c] = '\0';
  5654. strcpy(tempstartScheduleStr, sstr);
  5655. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  5656. }
  5657. else
  5658. {
  5659. strcpy(tempstartScheduleStr, "");
  5660. strcpy(ChargePointMaxProfileScheduleStr, "");
  5661. }
  5662. //**********chargingRateUnit**********/
  5663. c = 0;
  5664. loc = strstr(sLineWord, "chargingRateUnit");
  5665. memset(sstr ,0, sizeof(sstr) );
  5666. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5667. {
  5668. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5669. c++;
  5670. }
  5671. sstr[c] = '\0';
  5672. strcpy(tempchargingRateUnitStr, sstr);
  5673. //**********minChargingRate*******/
  5674. c = 0;
  5675. loc = strstr(sLineWord, "minChargingRate");
  5676. if(loc != NULL)
  5677. {
  5678. memset(sstr ,0, sizeof(sstr) );
  5679. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5680. {
  5681. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5682. c++;
  5683. }
  5684. sstr[c] = '\0';
  5685. tempminChargingRateFloat = atof(sstr);
  5686. }
  5687. else
  5688. {
  5689. tempminChargingRateFloat = 0.0;
  5690. }
  5691. #if 0
  5692. //
  5693. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5694. tp.tm_isdst = -1;
  5695. time_t utc = mktime(&tp);
  5696. time_t t = time(NULL);
  5697. //diff_t = difftime(t, utc);
  5698. #endif
  5699. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5700. //DEBUG_INFO(" debug 5 -1\n");
  5701. //parsing strings to words
  5702. i = 0;
  5703. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5704. loc = loc+3+strlen("chargingSchedulePeriod");
  5705. pch = strtok(loc ,"{");
  5706. while (pch != NULL)
  5707. {
  5708. strcpy(SchedulePeriodList[i], pch);
  5709. pch = strtok (NULL, "{");
  5710. i = i + 1;
  5711. }
  5712. n_SchedulePeriods = i;
  5713. for(int i=0;i<n_SchedulePeriods;i++)
  5714. {
  5715. //*************startPeriod****************/
  5716. c = 0;
  5717. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5718. memset(sstr ,0, sizeof(sstr) );
  5719. while (loc[strlen("startPeriod")+2+c] != ',')
  5720. {
  5721. sstr[c] = loc[strlen("startPeriod")+2+c];
  5722. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5723. c++;
  5724. }
  5725. sstr[c] = '\0';
  5726. tempStartPeriodInt = atoi(sstr);
  5727. //*************limit****************/
  5728. c = 0;
  5729. loc = strstr(SchedulePeriodList[i], "limit");
  5730. memset(sstr ,0, sizeof(sstr) );
  5731. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5732. {
  5733. sstr[c] = loc[strlen("limit")+2+c];
  5734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5735. c++;
  5736. }
  5737. sstr[c] = '\0';
  5738. tempLimitInt = atof(sstr);
  5739. //*************numberPhases****************/
  5740. c = 0;
  5741. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5742. memset(sstr ,0, sizeof(sstr) );
  5743. if(loc != NULL)
  5744. {
  5745. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5746. {
  5747. sstr[c] = loc[strlen("numberPhases")+2+c];
  5748. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5749. c++;
  5750. }
  5751. sstr[c] = '\0';
  5752. tempNumberPhasesInt = atoi(sstr);
  5753. }
  5754. else
  5755. {
  5756. tempNumberPhasesInt = 0;
  5757. }
  5758. if(j == 0)
  5759. {
  5760. ChargePointMaxProfile.Duration = tempdurationInt;
  5761. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  5762. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  5763. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5764. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5765. }
  5766. }
  5767. if(MinChargingRate < tempminChargingRateFloat)
  5768. {
  5769. MinChargingRate = tempminChargingRateFloat;
  5770. }
  5771. if(confirmPeriods < n_SchedulePeriods)
  5772. {
  5773. confirmPeriods = n_SchedulePeriods;
  5774. }
  5775. j = j + 1;
  5776. }
  5777. fclose(fptr1);
  5778. }
  5779. }// the end of access file ChargePointMaxProfile
  5780. //****************************TxDefaultProfile************************************************/
  5781. memset(fname, 0, sizeof fname);
  5782. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5783. TxDefaultProfileFileIsNull=TRUE;
  5784. if((access(fname,F_OK))!=-1)
  5785. {
  5786. fptr1 = fopen(fname, "r");
  5787. c = 0;
  5788. c = fgetc(fptr1);
  5789. //DEBUG_INFO("c:%d\n",c);
  5790. rewind(fptr1);
  5791. if(c == EOF)
  5792. {
  5793. DEBUG_INFO("\n End of file reached.");
  5794. TxDefaultProfileFileIsNull=TRUE;
  5795. fclose(fptr1);
  5796. }
  5797. else
  5798. {
  5799. TxDefaultProfileFileIsNull=FALSE;
  5800. while(fscanf(fptr1, "%s", word) != EOF)
  5801. {
  5802. if(strcmp(word, "chargingProfileId") == 0)
  5803. {
  5804. n_chargingProfile = n_chargingProfile + 1;
  5805. }
  5806. }
  5807. rewind(fptr1);
  5808. //search Charging Profile Element
  5809. int i = 0;
  5810. int j = 0;
  5811. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  5812. //DEBUG_INFO(" 1-1\n");
  5813. #if 0
  5814. /***********connectorId****************/
  5815. c = 0;
  5816. loc = strstr(sLineWord, "connectorId");
  5817. memset(sstr ,0, sizeof(sstr) );
  5818. while (loc[strlen("connectorId")+2+c] != ',')
  5819. {
  5820. sstr[c] = loc[strlen("connectorId")+2+c];
  5821. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5822. c++;
  5823. }
  5824. sstr[c] = '\0';
  5825. tempconnectorIdInt = atoi(sstr);
  5826. #endif
  5827. //***********validFrom**************/
  5828. c = 0;
  5829. loc = strstr(sLineWord, "validFrom");
  5830. if(loc != NULL)
  5831. {
  5832. memset(sstr ,0, sizeof(sstr) );
  5833. while (loc[3+strlen("validFrom")+c] != '\"')
  5834. {
  5835. sstr[c] = loc[3+strlen("validFrom")+c];
  5836. c++;
  5837. }
  5838. sstr[c] = '\0';
  5839. strcpy(tempvalidFromStr,sstr);
  5840. }
  5841. else
  5842. {
  5843. strcpy(tempvalidFromStr,"");
  5844. }
  5845. //***********duration**************/
  5846. c = 0;
  5847. loc = strstr(sLineWord, "duration");
  5848. if(loc != NULL)
  5849. {
  5850. memset(sstr ,0, sizeof(sstr) );
  5851. while (loc[2+strlen("duration")+c] != ',')
  5852. {
  5853. sstr[c] = loc[2+strlen("duration")+c];
  5854. c++;
  5855. }
  5856. sstr[c] = '\0';
  5857. tempdurationInt = atoi(sstr);
  5858. }
  5859. else
  5860. {
  5861. tempdurationInt = 0;
  5862. }
  5863. //**********startSchedule**********/
  5864. c = 0;
  5865. loc = strstr(sLineWord, "startSchedule");
  5866. memset(sstr ,0, sizeof(sstr) );
  5867. if(loc != NULL)
  5868. {
  5869. while (loc[3+strlen("startSchedule")+c] != '\"')
  5870. {
  5871. sstr[c] = loc[3+strlen("startSchedule")+c];
  5872. c++;
  5873. }
  5874. sstr[c] = '\0';
  5875. strcpy(tempstartScheduleStr, sstr);
  5876. strcpy(TxDefaultProfileScheduleStr, sstr);
  5877. }
  5878. else
  5879. {
  5880. strcpy(tempstartScheduleStr, "");
  5881. strcpy(TxDefaultProfileScheduleStr, "");
  5882. }
  5883. //**********chargingRateUnit**********/
  5884. c = 0;
  5885. loc = strstr(sLineWord, "chargingRateUnit");
  5886. memset(sstr ,0, sizeof(sstr) );
  5887. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  5888. {
  5889. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  5890. c++;
  5891. }
  5892. sstr[c] = '\0';
  5893. strcpy(tempchargingRateUnitStr, sstr);
  5894. //**********minChargingRate*******/
  5895. c = 0;
  5896. loc = strstr(sLineWord, "minChargingRate");
  5897. if(loc != NULL)
  5898. {
  5899. memset(sstr ,0, sizeof(sstr) );
  5900. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  5901. {
  5902. sstr[c] = loc[2+strlen("minChargingRate")+c];
  5903. c++;
  5904. }
  5905. sstr[c] = '\0';
  5906. tempminChargingRateFloat = atof(sstr);
  5907. }
  5908. else
  5909. {
  5910. tempminChargingRateFloat = 0.0;
  5911. }
  5912. #if 0
  5913. //
  5914. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  5915. tp.tm_isdst = -1;
  5916. time_t utc = mktime(&tp);
  5917. time_t t = time(NULL);
  5918. //diff_t = difftime(t, utc);
  5919. #endif
  5920. //DEBUG_INFO("diff_t=%f\n",diff_t);
  5921. //parsing strings to words
  5922. i = 0;
  5923. loc = strstr(sLineWord, "chargingSchedulePeriod");
  5924. loc = loc+3+strlen("chargingSchedulePeriod");
  5925. pch = strtok(loc ,"{");
  5926. while (pch != NULL)
  5927. {
  5928. strcpy(SchedulePeriodList[i], pch);
  5929. pch = strtok (NULL, "{");
  5930. i = i + 1;
  5931. }
  5932. n_SchedulePeriods = i;
  5933. for(int i=0;i<n_SchedulePeriods;i++)
  5934. {
  5935. //*************startPeriod****************/
  5936. c = 0;
  5937. loc = strstr(SchedulePeriodList[i], "startPeriod");
  5938. memset(sstr ,0, sizeof(sstr) );
  5939. while (loc[strlen("startPeriod")+2+c] != ',')
  5940. {
  5941. sstr[c] = loc[strlen("startPeriod")+2+c];
  5942. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5943. c++;
  5944. }
  5945. sstr[c] = '\0';
  5946. tempStartPeriodInt = atoi(sstr);
  5947. //*************limit****************/
  5948. c = 0;
  5949. loc = strstr(SchedulePeriodList[i], "limit");
  5950. memset(sstr ,0, sizeof(sstr) );
  5951. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  5952. {
  5953. sstr[c] = loc[strlen("limit")+2+c];
  5954. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5955. c++;
  5956. }
  5957. sstr[c] = '\0';
  5958. tempLimitInt = atof(sstr);
  5959. //*************numberPhases****************/
  5960. c = 0;
  5961. loc = strstr(SchedulePeriodList[i], "numberPhases");
  5962. memset(sstr ,0, sizeof(sstr) );
  5963. if(loc != NULL)
  5964. {
  5965. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  5966. {
  5967. sstr[c] = loc[strlen("numberPhases")+2+c];
  5968. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5969. c++;
  5970. }
  5971. sstr[c] = '\0';
  5972. tempNumberPhasesInt = atoi(sstr);
  5973. }
  5974. else
  5975. {
  5976. tempNumberPhasesInt = 0;
  5977. }
  5978. if(j == 0)
  5979. {
  5980. TxDefaultProfile.Duration = tempdurationInt;
  5981. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  5982. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  5983. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  5984. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  5985. }
  5986. else
  5987. {
  5988. //other stack level charging Profile
  5989. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  5990. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  5991. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  5992. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  5993. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  5994. }
  5995. }
  5996. if(MinChargingRate < tempminChargingRateFloat)
  5997. MinChargingRate = tempminChargingRateFloat;
  5998. if(confirmPeriods < n_SchedulePeriods)
  5999. confirmPeriods = n_SchedulePeriods;
  6000. j = j + 1;
  6001. //DEBUG_INFO(" 1-2\n");
  6002. }
  6003. fclose(fptr1);
  6004. //Stacking Charging Profiles
  6005. for(int l=0; l <(j-1) ;l++)
  6006. {
  6007. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  6008. {
  6009. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  6010. {
  6011. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  6012. {
  6013. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  6014. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  6015. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  6016. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6017. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6018. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  6019. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  6020. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  6021. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6022. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6023. }
  6024. else
  6025. {
  6026. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  6027. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  6028. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  6029. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  6030. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  6031. }
  6032. }
  6033. }
  6034. }
  6035. //end of Stacking Charging Profiles
  6036. }
  6037. }// the end of ACCESS TxDefaultProfile
  6038. //****************************TxProfile************************************************/
  6039. memset(fname, 0, sizeof fname);
  6040. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6041. TxProfileIsNull=TRUE;
  6042. if((access(fname,F_OK))!=-1)
  6043. {
  6044. fptr1 = fopen(fname, "r");
  6045. c = 0;
  6046. c = fgetc(fptr1);
  6047. //DEBUG_INFO("c:%d\n",c);
  6048. rewind(fptr1);
  6049. if(c == EOF)
  6050. {
  6051. DEBUG_INFO("\n End of file reached.");
  6052. TxProfileIsNull=TRUE;
  6053. fclose(fptr1);
  6054. }
  6055. else
  6056. {
  6057. TxProfileIsNull=FALSE;
  6058. while(fscanf(fptr1, "%s", word) != EOF)
  6059. {
  6060. if(strcmp(word, "chargingProfileId") == 0)
  6061. {
  6062. n_chargingProfile = n_chargingProfile + 1;
  6063. }
  6064. }
  6065. rewind(fptr1);
  6066. //search Charging Profile Element
  6067. int i= 0;
  6068. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  6069. #if 0
  6070. /***********connectorId****************/
  6071. c = 0;
  6072. loc = strstr(sLineWord, "connectorId");
  6073. memset(sstr ,0, sizeof(sstr) );
  6074. while (loc[strlen("connectorId")+2+c] != ',')
  6075. {
  6076. sstr[c] = loc[strlen("connectorId")+2+c];
  6077. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6078. c++;
  6079. }
  6080. sstr[c] = '\0';
  6081. tempconnectorIdInt = atoi(sstr);
  6082. #endif
  6083. //***********validFrom**************/
  6084. c = 0;
  6085. loc = strstr(sLineWord, "validFrom");
  6086. if(loc != NULL)
  6087. {
  6088. memset(sstr ,0, sizeof(sstr) );
  6089. while (loc[3+strlen("validFrom")+c] != '\"')
  6090. {
  6091. sstr[c] = loc[3+strlen("validFrom")+c];
  6092. c++;
  6093. }
  6094. sstr[c] = '\0';
  6095. strcpy(tempvalidFromStr,sstr);
  6096. }
  6097. else
  6098. {
  6099. strcpy(tempvalidFromStr,"");
  6100. }
  6101. //**********startSchedule**********/
  6102. c = 0;
  6103. loc = strstr(sLineWord, "startSchedule");
  6104. memset(sstr ,0, sizeof(sstr) );
  6105. if(loc != NULL)
  6106. {
  6107. while (loc[3+strlen("startSchedule")+c] != '\"')
  6108. {
  6109. sstr[c] = loc[3+strlen("startSchedule")+c];
  6110. c++;
  6111. }
  6112. sstr[c] = '\0';
  6113. strcpy(tempstartScheduleStr, sstr);
  6114. strcpy(TxProfileScheduleStr, sstr);
  6115. }
  6116. else
  6117. {
  6118. strcpy(tempstartScheduleStr, "");
  6119. strcpy(TxProfileScheduleStr, "");
  6120. }
  6121. //**********chargingRateUnit**********/
  6122. c = 0;
  6123. loc = strstr(sLineWord, "chargingRateUnit");
  6124. memset(sstr ,0, sizeof(sstr) );
  6125. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6126. {
  6127. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6128. c++;
  6129. }
  6130. sstr[c] = '\0';
  6131. strcpy(tempchargingRateUnitStr, sstr);
  6132. //**********minChargingRate*******/
  6133. c = 0;
  6134. loc = strstr(sLineWord, "minChargingRate");
  6135. if(loc != NULL)
  6136. {
  6137. memset(sstr ,0, sizeof(sstr) );
  6138. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  6139. {
  6140. sstr[c] = loc[2+strlen("minChargingRate")+c];
  6141. c++;
  6142. }
  6143. sstr[c] = '\0';
  6144. tempminChargingRateFloat = atof(sstr);
  6145. }
  6146. else
  6147. {
  6148. tempminChargingRateFloat = 0.0;
  6149. }
  6150. #if 0
  6151. //
  6152. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6153. tp.tm_isdst = -1;
  6154. time_t utc = mktime(&tp);
  6155. time_t t = time(NULL);
  6156. //diff_t = difftime(t, utc);
  6157. #endif
  6158. //DEBUG_INFO("diff_t=%f\n",diff_t);
  6159. //parsing strings to words
  6160. i = 0;
  6161. loc = strstr(sLineWord, "chargingSchedulePeriod");
  6162. loc = loc+3+strlen("chargingSchedulePeriod");
  6163. pch = strtok(loc ,"{");
  6164. while (pch != NULL)
  6165. {
  6166. strcpy(SchedulePeriodList[i], pch);
  6167. pch = strtok (NULL, "{");
  6168. i = i + 1;
  6169. }
  6170. n_SchedulePeriods = i;
  6171. for(int i=0;i<n_SchedulePeriods;i++)
  6172. {
  6173. //*************startPeriod****************/
  6174. c = 0;
  6175. loc = strstr(SchedulePeriodList[i], "startPeriod");
  6176. memset(sstr ,0, sizeof(sstr) );
  6177. while (loc[strlen("startPeriod")+2+c] != ',')
  6178. {
  6179. sstr[c] = loc[strlen("startPeriod")+2+c];
  6180. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6181. c++;
  6182. }
  6183. sstr[c] = '\0';
  6184. tempStartPeriodInt = atoi(sstr);
  6185. //*************limit****************/
  6186. c = 0;
  6187. loc = strstr(SchedulePeriodList[i], "limit");
  6188. memset(sstr ,0, sizeof(sstr) );
  6189. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  6190. {
  6191. sstr[c] = loc[strlen("limit")+2+c];
  6192. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6193. c++;
  6194. }
  6195. sstr[c] = '\0';
  6196. tempLimitInt = atof(sstr);
  6197. //*************numberPhases****************/
  6198. c = 0;
  6199. loc = strstr(SchedulePeriodList[i], "numberPhases");
  6200. memset(sstr ,0, sizeof(sstr) );
  6201. if(loc != NULL)
  6202. {
  6203. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  6204. {
  6205. sstr[c] = loc[strlen("numberPhases")+2+c];
  6206. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6207. c++;
  6208. }
  6209. sstr[c] = '\0';
  6210. tempNumberPhasesInt = atoi(sstr);
  6211. }
  6212. else
  6213. {
  6214. tempNumberPhasesInt = 0;
  6215. }
  6216. TxProfile.Duration = durationInt;
  6217. TxProfile.TotalPeriod = n_SchedulePeriods;
  6218. TxProfile.Period[i].Limit = tempLimitInt;
  6219. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  6220. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  6221. }
  6222. if(MinChargingRate < tempminChargingRateFloat)
  6223. MinChargingRate = tempminChargingRateFloat;
  6224. if(confirmPeriods < n_SchedulePeriods)
  6225. confirmPeriods = n_SchedulePeriods;
  6226. }
  6227. fclose(fptr1);
  6228. }
  6229. }// the end of ACCESS TxProfile
  6230. //CompositeSchedule
  6231. int period=0;
  6232. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  6233. {
  6234. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  6235. struct tm tp;
  6236. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6237. tp.tm_isdst = -1;
  6238. time_t utc = mktime(&tp);
  6239. time_t t = time(NULL);
  6240. double diff_f = difftime(t, utc);
  6241. int diff_i; // = (int)diff_f;
  6242. int quotient; // = diff_i / 86400;//86400 seconds/day
  6243. //int remainder = diff_i % 86400;
  6244. for(int k=0; k < TxProfile.TotalPeriod;k++)
  6245. {
  6246. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  6247. {
  6248. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  6249. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6250. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6251. period = period + 1;
  6252. }
  6253. else
  6254. {
  6255. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  6256. {
  6257. }
  6258. else
  6259. {
  6260. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6261. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  6262. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  6263. period = period + 1;
  6264. }
  6265. }
  6266. }
  6267. if( diff_f >= 0)
  6268. {
  6269. diff_i = (int)diff_f;
  6270. quotient = diff_i / 86400;//86400 seconds/day
  6271. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6272. {
  6273. 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))
  6274. {
  6275. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6276. {
  6277. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6278. }
  6279. else
  6280. {
  6281. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6282. }
  6283. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6284. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  6285. period = period + 1;
  6286. }
  6287. }
  6288. // Check Last Period
  6289. if((TxDefaultProfile.Duration < durationInt) && (ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].Limit) < ChargePointMaxProfile.Period[0].Limit)
  6290. {
  6291. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6292. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = ShmOCPP16Data->GetCompositeSchedule[0].ResponseChargingSchedule.ChargingSchedulePeriod[period-1].NumberPhases;
  6293. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Duration;
  6294. period = period + 1;
  6295. }
  6296. } // diff_f >= 0
  6297. }
  6298. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  6299. {
  6300. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6301. struct tm tp;
  6302. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6303. tp.tm_isdst = -1;
  6304. time_t utc = mktime(&tp);
  6305. time_t t = time(NULL);
  6306. double diff_f = difftime(t, utc);
  6307. int diff_i;// = (int)diff_f;
  6308. int quotient; // = diff_i / 86400;//86400 seconds/day
  6309. //int remainder = diff_i % 86400;
  6310. if(diff_f >= 0)
  6311. {
  6312. diff_i = (int)diff_f;
  6313. quotient = diff_i / 86400;//86400 seconds/day
  6314. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6315. {
  6316. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6317. {
  6318. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6319. {
  6320. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6321. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6322. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6323. period = period + 1;
  6324. }
  6325. else
  6326. {
  6327. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6328. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6329. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6330. period = period + 1;
  6331. }
  6332. }
  6333. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6334. {
  6335. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6336. {
  6337. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6338. {
  6339. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  6340. {
  6341. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6342. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6343. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6344. period = period + 1;
  6345. }
  6346. else
  6347. {
  6348. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  6349. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6350. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6351. period = period + 1;
  6352. }
  6353. }
  6354. }
  6355. }
  6356. }
  6357. } // end diff_f >= 0
  6358. }
  6359. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  6360. {
  6361. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  6362. struct tm tp;
  6363. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  6364. tp.tm_isdst = -1;
  6365. time_t utc = mktime(&tp);
  6366. time_t t = time(NULL);
  6367. double diff_f = difftime(t, utc);
  6368. int diff_i; // = (int)diff_f;
  6369. int quotient; // = diff_i / 86400;//86400 seconds/day
  6370. //int remainder = diff_i % 86400;
  6371. if(diff_f >= 0)
  6372. {
  6373. diff_i = (int)diff_f;
  6374. quotient = diff_i / 86400;//86400 seconds/day
  6375. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  6376. {
  6377. if((TxDefaultProfile.Period[l].StartPeriod < durationInt) && ((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient))
  6378. {
  6379. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6380. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6381. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6382. period = period + 1;
  6383. }
  6384. else if(TxDefaultProfile.Period[l].StartPeriod > durationInt)
  6385. {
  6386. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  6387. {
  6388. if((TxDefaultProfile.Period[l].StartPeriod % 86400) < durationInt)
  6389. {
  6390. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  6391. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  6392. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  6393. period = period + 1;
  6394. }
  6395. }
  6396. }
  6397. }
  6398. } // diff_f >= 0
  6399. }
  6400. else if((TxDefaultProfileFileIsNull==TRUE) && (TxProfileIsNull==TRUE))
  6401. {
  6402. confirmPeriods = 0;
  6403. //sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6404. //goto end;
  6405. }
  6406. confirmPeriods = period;
  6407. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  6408. //---- Define StartSchedule----/
  6409. struct tm *gtime;
  6410. time_t now;
  6411. char buf[28];
  6412. //---Read the current system time---/
  6413. time(&now);
  6414. //---Convert the system time to GMT (now UTC)---/
  6415. gtime = gmtime(&now);
  6416. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  6417. // make .conf
  6418. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.StartSchedule,buf);
  6419. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.Duration = durationInt;
  6420. //DEBUG_INFO(" debug 11\n");
  6421. strcpy((char *)ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingRateUnit, tempchargingRateUnitStr );
  6422. ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.MinChargingRate = MinChargingRate;
  6423. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6424. }
  6425. else
  6426. {
  6427. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6428. }
  6429. //end:
  6430. sendGetCompositeScheduleConfirmation(uuid,comfirmstr, connectorIdInt, confirmPeriods);
  6431. return result;
  6432. }
  6433. int handleGetConfigurationRequest(char *uuid, char *payload)
  6434. {
  6435. mtrace();
  6436. int result = FAIL;
  6437. // struct json_object *obj=NULL, *key=NULL;// *jsonitem;
  6438. //struct json_object *jsonitem;
  6439. int MaxKeySupported = 0;
  6440. int n_keys = 0;
  6441. char requestKey[43][50]={0};
  6442. char search[]="[";
  6443. char sstr[500]={ 0 },sstrtemp[60]={ 0 };
  6444. //int pos;
  6445. int l, c = 0;
  6446. int i = 0;
  6447. char *delim = "\",\"";
  6448. char * pch;
  6449. strcpy(sstrtemp, stringtrimspace(payload));
  6450. char *loc = strstr(sstrtemp, search);
  6451. //********************* Parsing String ***********************************/
  6452. if(loc == NULL) {
  6453. DEBUG_INFO("no key match in Configuration \n");
  6454. }
  6455. else {
  6456. //pos = loc - payload;
  6457. l = strlen(loc)-4;
  6458. while (c < l)
  6459. {
  6460. sstr[c] = loc[c+2];
  6461. c++;
  6462. }
  6463. sstr[c] = '\0';
  6464. //parsing strings to words
  6465. pch = strtok(sstr,delim);
  6466. if(pch == NULL)
  6467. {
  6468. strcpy(requestKey[0], sstr);
  6469. }
  6470. else
  6471. {
  6472. while (pch != NULL)
  6473. {
  6474. strcpy(requestKey[i], pch);
  6475. pch = strtok (NULL, delim);
  6476. i = i + 1;
  6477. }
  6478. n_keys = i;
  6479. }
  6480. }
  6481. UnknownKeynum = 0;
  6482. memset( (void *)unknownkey, 0, sizeof(unknownkey)/*sizeof(char)*10*20*/ );
  6483. MaxKeySupported = GetConfigurationMaxKeysNUM;//atoi(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  6484. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6485. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6486. if(n_keys != 0)
  6487. {
  6488. for(int i=0;i<n_keys;i++)
  6489. {
  6490. getKeyValue(requestKey[i]);
  6491. //json_object_put(jsonitem);
  6492. }
  6493. }
  6494. else
  6495. {
  6496. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6497. getKeyValue("");
  6498. }
  6499. processUnkownKey();
  6500. sendGetConfigurationConfirmation(uuid);
  6501. return result;
  6502. }
  6503. static char fnamePlusPath[100]={0};
  6504. static char fnamePWithNoPath[60]={0};
  6505. void checkUploadLog(void)
  6506. {
  6507. FILE *fp;
  6508. /* Open the command for reading. */
  6509. fp = popen("find ../mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6510. if (fp == NULL) {
  6511. printf("Failed to run command\n" );
  6512. exit(1);
  6513. }
  6514. int ftppathlen = 0;
  6515. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6516. int i = 0;
  6517. /* Read the output a line at a time - output it. */
  6518. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6519. if(i==0)
  6520. {
  6521. ftppathlen = strlen(fnamePlusPath);
  6522. printf("%s\n", fnamePlusPath);
  6523. fnamePlusPath[ftppathlen]='\0';
  6524. break;
  6525. }
  6526. i= i+1;
  6527. }
  6528. /* close */
  6529. pclose(fp);
  6530. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6531. {
  6532. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6533. {
  6534. fnamePlusPath[k]='\0';
  6535. }
  6536. }
  6537. i=1;
  6538. //char fname[60]={0};
  6539. while(i < ftppathlen)
  6540. {
  6541. int len=ftppathlen-i;
  6542. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6543. {
  6544. printf("compare '/' all right\n");
  6545. break;
  6546. }
  6547. i=i+1;
  6548. }
  6549. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6550. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6551. fnamePWithNoPath[i+1] = '\0';
  6552. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6553. {
  6554. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6555. {
  6556. fnamePWithNoPath[j]='\0';
  6557. }
  6558. }
  6559. FILE* fp1 = fopen(fnamePlusPath, "r");
  6560. if (fp1)
  6561. {
  6562. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6563. // file exists
  6564. fclose(fp1);
  6565. }
  6566. else
  6567. {
  6568. // file doesn't exist
  6569. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6570. }
  6571. }
  6572. static char GetDiagnosticspayloadData[300]={0};
  6573. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6574. {
  6575. mtrace();
  6576. int result = FAIL;
  6577. pthread_t t; // pthread 變數
  6578. system("exec /root/logPackTools 'log' 6");
  6579. #if 0
  6580. //char buffer [128];
  6581. time (&rawtime);
  6582. //printf("%ld\n", rawtime);
  6583. timeinfo = localtime (&rawtime);
  6584. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6585. DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6586. if((access(fnamePlusPath,F_OK))!=-1)
  6587. {
  6588. DEBUG_INFO("fnamePlusPath exist.\n");
  6589. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6590. }
  6591. else
  6592. {
  6593. DEBUG_INFO("fnamePlusPath not exist!\n");
  6594. }
  6595. #endif
  6596. checkUploadLog();
  6597. memset(GetDiagnosticspayloadData, 0, 300);
  6598. strcpy(GetDiagnosticspayloadData, stringtrimspace(payload));
  6599. sendGetDiagnosticsConfirmation(uuid,fnamePWithNoPath/*(char*) ret*/);
  6600. pthread_create(&t, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6601. return result;
  6602. }
  6603. void* GetDiagnosticsProcess(void* data)
  6604. {
  6605. pthread_detach(pthread_self());
  6606. mtrace();
  6607. int retriesInt=0, retryIntervalInt=0;
  6608. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6609. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6610. 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};
  6611. int port=0;
  6612. char sstr[260]={ 0 };//sstr[200]={ 0 };
  6613. int c = 0;
  6614. char *loc;
  6615. int isSuccess = FALSE;
  6616. char ftpbuf[200]={0};
  6617. //char temp[100]={0};
  6618. char * pch;
  6619. // [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"}]
  6620. char str[300]={ 0 };
  6621. strcpy(str,(const char*)GetDiagnosticspayloadData);
  6622. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6623. DEBUG_INFO("GetDiagnosticsProcess\n");
  6624. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6625. //****************location*******************/
  6626. c = 0;
  6627. memset(sstr ,0, sizeof(sstr) );
  6628. loc = strstr(str, "location");
  6629. while (loc[3+strlen("location")+c] != '\"')
  6630. {
  6631. sstr[c] = loc[3+strlen("location")+c];
  6632. c++;
  6633. }
  6634. sstr[c] = '\0';
  6635. strcpy(locationstr,sstr);
  6636. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6637. if(strcmp(locationstr,"")==0)
  6638. {
  6639. DEBUG_INFO("location is <Empty>!\n");
  6640. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6641. goto end;
  6642. }
  6643. //****************retries*******************/
  6644. c = 0;
  6645. loc = strstr(str, "retries");
  6646. if(loc == NULL)
  6647. {
  6648. retriesIsNULL = TRUE;
  6649. }
  6650. else
  6651. {
  6652. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6653. {
  6654. sstr[c] = loc[strlen("retries")+2+c];
  6655. c++;
  6656. }
  6657. sstr[c] = '\0';
  6658. retriesInt = atoi(sstr);
  6659. }
  6660. if(retriesIsNULL == TRUE)
  6661. {
  6662. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6663. }
  6664. //****************retryInterval*******************/
  6665. c = 0;
  6666. loc = strstr(str, "retryInterval");
  6667. if(loc == NULL)
  6668. {
  6669. retryIntervalIsNULL = TRUE;
  6670. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6671. }
  6672. else
  6673. {
  6674. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6675. {
  6676. sstr[c] = loc[strlen("retryInterval")+2+c];
  6677. c++;
  6678. }
  6679. sstr[c] = '\0';
  6680. retryIntervalInt = atoi(sstr);
  6681. }
  6682. //****************startTime*******************/
  6683. c = 0;
  6684. memset(sstr ,0, sizeof(sstr) );
  6685. loc = strstr(str, "startTime");
  6686. if(loc == NULL)
  6687. {
  6688. startTimeIsNULL = TRUE;
  6689. }
  6690. else
  6691. {
  6692. while (loc[3+strlen("startTime")+c] != '\"')
  6693. {
  6694. sstr[c] = loc[3+strlen("startTime")+c];
  6695. c++;
  6696. }
  6697. sstr[c] = '\0';
  6698. strcpy(startTimestr,sstr);
  6699. }
  6700. //****************stopTime*******************/
  6701. c = 0;
  6702. memset(sstr ,0, sizeof(sstr) );
  6703. loc = strstr(str, "stopTime");
  6704. if(loc == NULL)
  6705. {
  6706. stopTimeIsNULL = TRUE;
  6707. }
  6708. else
  6709. {
  6710. while (loc[3+strlen("stopTime")+c] != '\"')
  6711. {
  6712. sstr[c] = loc[3+strlen("stopTime")+c];
  6713. c++;
  6714. }
  6715. sstr[c] = '\0';
  6716. strcpy(stopTimestr,sstr);
  6717. }
  6718. memset(protocol, 0, sizeof(protocol));
  6719. memset(user, 0, sizeof(user) );
  6720. memset(password, 0, sizeof(password));
  6721. memset(host, 0, sizeof(host));
  6722. memset(path, 0, sizeof(path));
  6723. memset(ftppath, 0, sizeof(ftppath));
  6724. memset(host1, 0, sizeof(host1));
  6725. memset(path1, 0, sizeof(path1));
  6726. /*location: ftp://user:password@host:port/path*/
  6727. #if 0
  6728. time_t rawtime;
  6729. struct tm * timeinfo;
  6730. //char buffer [128];
  6731. time (&rawtime);
  6732. //printf("%ld\n", rawtime);
  6733. timeinfo = localtime (&rawtime);
  6734. strftime (fnamePlusPath,sizeof(fnamePlusPath),"../mnt/%4Y-%2m.zip",timeinfo);
  6735. strftime (fname,sizeof(fname),"%4Y-%2m-%d-%H-%M-%S.zip",timeinfo);
  6736. #endif
  6737. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6738. if((access(fnamePlusPath,F_OK))!=-1)
  6739. {
  6740. DEBUG_INFO("fnamePlusPath exist.\n");
  6741. }
  6742. else
  6743. {
  6744. DEBUG_INFO("fnamePlusPath not exist!\n");
  6745. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6746. goto end;
  6747. }
  6748. pch=strchr(locationstr,'@');
  6749. if(pch==NULL)
  6750. {
  6751. sscanf(locationstr,
  6752. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6753. protocol, host, &port, path);
  6754. strcpy(user,"anonymous");
  6755. strcpy(password,"");
  6756. }
  6757. else
  6758. {
  6759. //DEBUG_INFO("pch=%s\n", pch);
  6760. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6761. protocol, user, password, host, &port, path);
  6762. }
  6763. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6764. {
  6765. DEBUG_INFO("protocol is not ftp/http ! \n");
  6766. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6767. goto end;
  6768. }
  6769. if(strncmp(locationstr,"http", 4) == 0)
  6770. {
  6771. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6772. sprintf(ftppath,"/%s", path);
  6773. do{
  6774. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6775. sleep(retryIntervalInt);
  6776. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6777. if(!isSuccess)
  6778. {
  6779. DEBUG_INFO("Diagnostics fail.\n");
  6780. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6781. }
  6782. else
  6783. {
  6784. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6785. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6786. }
  6787. }
  6788. else
  6789. {
  6790. sscanf(host,"%[^/]%s",host1, path1);
  6791. sprintf(ftppath,"%s", path1);
  6792. int ftppathlen=strlen(ftppath);
  6793. int i=1;
  6794. char filenametemp[50];
  6795. while(i < ftppathlen)
  6796. {
  6797. int len=ftppathlen-i;
  6798. if(ftppath[len]== 47) // '/' ascll code: 47
  6799. {
  6800. DEBUG_INFO("find '/' all right\n");
  6801. break;
  6802. }
  6803. i=i+1;
  6804. }
  6805. memset(filenametemp, 0, sizeof(filenametemp));
  6806. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6807. filenametemp[i+1] = 0;
  6808. memset(ftpbuf, 0, sizeof(ftpbuf));
  6809. if(port == 0)
  6810. port = 21;
  6811. do{
  6812. isSuccess = ftpFile(/*"test.evsocket.phihong.com.cn","phihong","y42j/4cj84",21,"/",fname*/host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6813. sleep(retryIntervalInt);
  6814. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6815. if(!isSuccess)
  6816. {
  6817. DEBUG_INFO("Diagnostics fail.\n");
  6818. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6819. }
  6820. else
  6821. {
  6822. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6823. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6824. }
  6825. }
  6826. end:
  6827. DiagnosticsStatusNotificationStatus = 0; //Idle
  6828. pthread_exit(NULL/*(void *) fname*/); // ? ?子執行 ?
  6829. }
  6830. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6831. {
  6832. mtrace();
  6833. int result = FAIL;
  6834. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6835. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6836. {
  6837. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6838. localversion = -1;
  6839. }
  6840. else
  6841. {
  6842. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6843. OCPP_getListVerion();
  6844. }
  6845. //from db.OCPP_getListVerion
  6846. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6847. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6848. sendGetLocalListVersionConfirmation(uuid,"");
  6849. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6850. return result;
  6851. }
  6852. int handleRemoteStartRequest(char *uuid, char *payload)
  6853. {
  6854. mtrace();
  6855. int result = FAIL;
  6856. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6857. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6858. int tempIndex = 0;
  6859. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6860. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6861. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6862. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6863. int chargingSchedulePeriodCount = 0;
  6864. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6865. int c = 0;
  6866. char *loc;
  6867. char comfirmstr[20]={0};
  6868. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6869. if(server_pending == TRUE)
  6870. {
  6871. return 0;
  6872. }
  6873. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6874. strcpy(sstrtemp, stringtrimspace(payload));
  6875. //**********connectorId****************/
  6876. c = 0;
  6877. memset(sstr ,0, sizeof(sstr) );
  6878. loc = strstr(sstrtemp, "connectorId");
  6879. if(loc == NULL)
  6880. {
  6881. connectorIdIsNULL = TRUE;
  6882. }
  6883. else
  6884. {
  6885. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6886. {
  6887. sstr[c] = loc[strlen("connectorId")+2+c];
  6888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6889. c++;
  6890. }
  6891. sstr[c] = '\0';
  6892. connectorIdInt = atoi(sstr);
  6893. }
  6894. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6895. {
  6896. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6897. goto end;
  6898. }
  6899. //****************idTag*******************/
  6900. c = 0;
  6901. memset(sstr ,0, sizeof(sstr) );
  6902. loc = strstr(sstrtemp, "idTag");
  6903. while (loc[3+strlen("idTag")+c] != '\"')
  6904. {
  6905. sstr[c] = loc[3+strlen("idTag")+c];
  6906. c++;
  6907. }
  6908. sstr[c] = '\0';
  6909. strcpy(idTagstr,sstr);
  6910. //****************chargingProfile*******************/
  6911. c = 0;
  6912. memset(sstr ,0, sizeof(sstr) );
  6913. loc = strstr(sstrtemp, "chargingProfile");
  6914. if(loc == NULL)
  6915. {
  6916. chargingProfileIsNULL = TRUE;
  6917. }
  6918. else
  6919. {
  6920. //****************chargingProfileId*******************/
  6921. c=0;
  6922. loc = strstr(sstrtemp, "chargingProfileId");
  6923. memset(sstr ,0, sizeof(sstr) );
  6924. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6925. {
  6926. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6927. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6928. c++;
  6929. }
  6930. sstr[c] = '\0';
  6931. chargingProfileIdInt = atoi(sstr);
  6932. //****************transactionId*******************/
  6933. loc = strstr(sstrtemp, "transactionId");
  6934. if(loc == NULL)
  6935. {
  6936. transactionIdIsNULL = TRUE;
  6937. }
  6938. else
  6939. {
  6940. c=0;
  6941. memset(sstr ,0, sizeof(sstr) );
  6942. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6943. {
  6944. sstr[c] = loc[strlen("transactionId")+2+c];
  6945. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6946. c++;
  6947. }
  6948. sstr[c] = '\0';
  6949. transactionIdInt = atoi(sstr);
  6950. }
  6951. //****************stackLevel*******************/
  6952. c=0;
  6953. loc = strstr(sstrtemp, "stackLevel");
  6954. memset(sstr ,0, sizeof(sstr) );
  6955. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6956. {
  6957. sstr[c] = loc[strlen("stackLevel")+2+c];
  6958. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6959. c++;
  6960. }
  6961. sstr[c] = '\0';
  6962. stackLevelInt = atoi(sstr);
  6963. //****************chargingProfilePurpose*******************/
  6964. c = 0;
  6965. memset(sstr ,0, sizeof(sstr) );
  6966. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6967. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6968. {
  6969. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6970. c++;
  6971. }
  6972. sstr[c] = '\0';
  6973. strcpy(chargingProfilePurposestr,sstr);
  6974. //****************chargingProfileKind*******************/
  6975. c = 0;
  6976. memset(sstr ,0, sizeof(sstr) );
  6977. loc = strstr(sstrtemp, "chargingProfileKind");
  6978. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6979. {
  6980. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6981. c++;
  6982. }
  6983. sstr[c] = '\0';
  6984. strcpy(chargingProfileKindstr,sstr);
  6985. //****************recurrencyKind*******************/
  6986. loc = strstr(sstrtemp, "recurrencyKind");
  6987. if(loc == NULL)
  6988. {
  6989. recurrencyKindIsNULL = TRUE;
  6990. }
  6991. else
  6992. {
  6993. c = 0;
  6994. memset(sstr ,0, sizeof(sstr) );
  6995. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6996. {
  6997. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6998. c++;
  6999. }
  7000. sstr[c] = '\0';
  7001. strcpy(recurrencyKindstr,sstr);
  7002. }
  7003. //****************validFrom*******************/
  7004. loc = strstr(sstrtemp, "validFrom");
  7005. if(loc == NULL)
  7006. {
  7007. validFromIsNULL = TRUE;
  7008. }
  7009. else
  7010. {
  7011. c = 0;
  7012. memset(sstr ,0, sizeof(sstr) );
  7013. while (loc[3+strlen("validFrom")+c] != '\"')
  7014. {
  7015. sstr[c] = loc[3+strlen("validFrom")+c];
  7016. c++;
  7017. }
  7018. sstr[c] = '\0';
  7019. strcpy(validFromstr,sstr);
  7020. }
  7021. //****************validTo*******************/
  7022. loc = strstr(sstrtemp, "validTo");
  7023. if(loc == NULL)
  7024. {
  7025. validToIsNULL = TRUE;
  7026. }
  7027. else
  7028. {
  7029. c = 0;
  7030. memset(sstr ,0, sizeof(sstr) );
  7031. while (loc[3+strlen("validTo")+c] != '\"')
  7032. {
  7033. sstr[c] = loc[3+strlen("validTo")+c];
  7034. c++;
  7035. }
  7036. sstr[c] = '\0';
  7037. strcpy(validTostr,sstr);
  7038. }
  7039. //****************chargingSchedule*******************/
  7040. loc = strstr(sstrtemp, "chargingSchedule");
  7041. if(loc != NULL)
  7042. {
  7043. //****************duration*******************/
  7044. loc = strstr(sstrtemp, "duration");
  7045. if(loc == NULL)
  7046. {
  7047. durationIsNULL = TRUE;
  7048. }
  7049. else
  7050. {
  7051. c=0;
  7052. memset(sstr ,0, sizeof(sstr) );
  7053. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  7054. {
  7055. sstr[c] = loc[strlen("duration")+2+c];
  7056. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7057. c++;
  7058. }
  7059. sstr[c] = '\0';
  7060. durationInt = atoi(sstr);
  7061. }
  7062. //****************startSchedule******************/
  7063. loc = strstr(sstrtemp, "startSchedule");
  7064. if(loc == NULL)
  7065. {
  7066. startScheduleIsNULL = TRUE;
  7067. }
  7068. else
  7069. {
  7070. c = 0;
  7071. memset(sstr ,0, sizeof(sstr) );
  7072. while (loc[3+strlen("startSchedule")+c] != '\"')
  7073. {
  7074. sstr[c] = loc[3+strlen("startSchedule")+c];
  7075. c++;
  7076. }
  7077. sstr[c] = '\0';
  7078. strcpy(startSchedulestr,sstr);
  7079. }
  7080. //****************chargingRateUnit*******************/
  7081. c = 0;
  7082. memset(sstr ,0, sizeof(sstr) );
  7083. loc = strstr(sstrtemp, "chargingRateUnit");
  7084. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  7085. {
  7086. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  7087. c++;
  7088. }
  7089. sstr[c] = '\0';
  7090. strcpy(chargingRateUnitstr,sstr);
  7091. //****************minChargingRate*******************/
  7092. loc = strstr(sstrtemp, "minChargingRate");
  7093. if(loc == NULL)
  7094. {
  7095. minChargingRateIsNULL = TRUE;
  7096. }
  7097. else
  7098. {
  7099. c=0;
  7100. memset(sstr ,0, sizeof(sstr) );
  7101. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  7102. {
  7103. sstr[c] = loc[strlen("minChargingRate")+2+c];
  7104. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7105. c++;
  7106. }
  7107. sstr[c] = '\0';
  7108. minChargingRateflaot = atof(sstr);
  7109. }
  7110. //****************chargingSchedulePeriod count*******************/
  7111. int what_len = strlen("startPeriod");
  7112. char *where = sstrtemp;
  7113. while ((where = strstr(where, "startPeriod"))) {
  7114. where += what_len;
  7115. chargingSchedulePeriodCount++;
  7116. }
  7117. where = sstrtemp;
  7118. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7119. {
  7120. //****************startPeriod*******************/
  7121. c=0;
  7122. loc = strstr(where, "startPeriod");
  7123. memset(sstr ,0, sizeof(sstr) );
  7124. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  7125. {
  7126. sstr[c] = loc[strlen("startPeriod")+2+c];
  7127. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7128. c++;
  7129. }
  7130. sstr[c] = '\0';
  7131. startPeriodInt[periodNums] = atoi(sstr);
  7132. //****************limit*******************/
  7133. c=0;
  7134. loc = strstr(where, "limit");
  7135. memset(sstr ,0, sizeof(sstr) );
  7136. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  7137. {
  7138. sstr[c] = loc[strlen("limit")+2+c];
  7139. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7140. c++;
  7141. }
  7142. sstr[c] = '\0';
  7143. limitflaot[periodNums] = atof(sstr);
  7144. //****************numberPhases*******************/
  7145. loc = strstr(where, "numberPhases");
  7146. if(loc == NULL)
  7147. {
  7148. numberPhasesIsNULL = TRUE;
  7149. }
  7150. else
  7151. {
  7152. c=0;
  7153. memset(sstr ,0, sizeof(sstr) );
  7154. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  7155. {
  7156. sstr[c] = loc[strlen("numberPhases")+2+c];
  7157. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7158. c++;
  7159. }
  7160. sstr[c] = '\0';
  7161. numberPhasesInt[periodNums] = atoi(sstr);
  7162. }
  7163. where = loc;
  7164. } // END FOR chargingSchedulePeriodCount
  7165. }// END IF chargingSchedule
  7166. } // END chargingProfile
  7167. /*
  7168. enum _SYSTEM_STATUS
  7169. {
  7170. S_BOOTING = 0,
  7171. S_IDLE, = 1
  7172. S_AUTHORIZING, =2
  7173. S_REASSIGN_CHECK, =3
  7174. S_REASSIGN, =4
  7175. S_PRECHARGE, =5
  7176. S_PREPARING_FOR_EV, =6
  7177. S_PREPARING_FOR_EVSE, =7
  7178. S_CHARGING, =8
  7179. S_TERMINATING, =9
  7180. S_COMPLETE, =10
  7181. S_ALARM, =11
  7182. S_FAULT =12
  7183. }
  7184. */
  7185. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  7186. {
  7187. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  7188. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7189. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  7190. //check Transaction active
  7191. if(gunType[connectorIdInt -1] == 'J')
  7192. {
  7193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7194. {
  7195. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7196. }
  7197. else
  7198. {
  7199. tempIndex = connectorIdInt -1;
  7200. }
  7201. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7202. {
  7203. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7204. {
  7205. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7206. {
  7207. //Reserved
  7208. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7209. }
  7210. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7211. {
  7212. //Reserved
  7213. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7214. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7215. goto end;
  7216. }
  7217. else
  7218. {
  7219. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7220. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7221. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7222. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7223. {
  7224. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7225. goto end;
  7226. }
  7227. }//END FOR ELSE
  7228. }
  7229. }// END FOR CHAdeMO_QUANTITY
  7230. }
  7231. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7232. {
  7233. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7234. {
  7235. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7236. }
  7237. else
  7238. {
  7239. tempIndex = connectorIdInt -1;
  7240. }
  7241. for (int index = 0; index < CCS_QUANTITY; index++)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7244. {
  7245. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7246. {
  7247. //Reserved
  7248. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7249. }
  7250. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7251. {
  7252. //Reserved
  7253. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7254. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7255. goto end;
  7256. }
  7257. else
  7258. {
  7259. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7260. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7261. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7262. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7263. {
  7264. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7265. goto end;
  7266. }
  7267. }// END FOR ELSE
  7268. }
  7269. }// END FOR CCS_QUANTITY
  7270. }
  7271. else if(gunType[connectorIdInt -1] == 'G')
  7272. {
  7273. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7274. {
  7275. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7276. }
  7277. else
  7278. {
  7279. tempIndex = connectorIdInt -1;
  7280. }
  7281. for (int index = 0; index < GB_QUANTITY; index++)
  7282. {
  7283. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7284. {
  7285. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7286. {
  7287. //Reserved
  7288. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7289. }
  7290. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7291. {
  7292. //Reserved
  7293. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7294. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7295. goto end;
  7296. }
  7297. else
  7298. {
  7299. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7300. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7301. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7302. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7303. {
  7304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7305. goto end;
  7306. }
  7307. }// END FOR ELSE
  7308. }
  7309. } // END FOR GB_QUANTITY
  7310. }
  7311. else
  7312. {
  7313. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7314. {
  7315. tempIndex = 2;
  7316. }
  7317. else
  7318. {
  7319. tempIndex = connectorIdInt -1;
  7320. }
  7321. for (int index = 0; index < AC_QUANTITY; index++)
  7322. {
  7323. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7324. {
  7325. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) == 0))
  7326. {
  7327. //Reserved
  7328. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7329. }
  7330. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmSysConfigAndInfo->SysConfig.UserId, idTagstr) != 0))
  7331. {
  7332. //Reserved
  7333. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7334. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7335. goto end;
  7336. }
  7337. else
  7338. {
  7339. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7340. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7341. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7342. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7343. {
  7344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7345. goto end;
  7346. }
  7347. }//END FOR ELSE
  7348. }
  7349. }// END FOR AC_QUANTITY
  7350. }
  7351. if(chargingProfileIsNULL == FALSE)
  7352. {
  7353. //ChargingProfile
  7354. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7355. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7356. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7357. if(recurrencyKindIsNULL == FALSE) //OPTION
  7358. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7359. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7360. if(transactionIdIsNULL == FALSE) // OPTION
  7361. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7362. if(validFromIsNULL == FALSE) // OPTION
  7363. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7364. if(validToIsNULL == FALSE) //OPTION
  7365. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7366. //ChargingSchedule
  7367. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7368. if(durationIsNULL == FALSE) //OPTION
  7369. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7370. if(minChargingRateIsNULL == FALSE) //OPTION
  7371. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7372. if(startScheduleIsNULL == FALSE) //OPTION
  7373. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7374. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7375. {
  7376. //ChargingSchedulePeriod
  7377. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7378. if(numberPhasesIsNULL == FALSE)
  7379. {
  7380. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7381. }
  7382. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7383. }
  7384. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7385. {
  7386. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7387. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7388. //memset idTag
  7389. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7390. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7391. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7392. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7393. }
  7394. else
  7395. {
  7396. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7397. }
  7398. }
  7399. else
  7400. {
  7401. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7402. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7403. //memset idTag
  7404. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7405. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7406. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7407. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7408. }
  7409. }
  7410. else
  7411. {
  7412. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7413. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7414. }
  7415. end:
  7416. if(connectorIdIsNULL == FALSE)
  7417. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7418. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7419. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7420. //OCPP send RemoteStartConfirmation by first.
  7421. sendRemoteStartConfirmation(uuid, comfirmstr);
  7422. return result;
  7423. }
  7424. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7425. {
  7426. mtrace();
  7427. int result = FAIL;
  7428. int match = FALSE;
  7429. int GunNO = 0;
  7430. int tempIndex = 0;
  7431. int transactionIdInt=0;
  7432. int transactionIdIsNULL= FALSE;
  7433. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7434. int c = 0;
  7435. char *loc;
  7436. char comfirmstr[20];
  7437. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7438. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7439. if(server_pending == TRUE)
  7440. {
  7441. return 0;
  7442. }
  7443. strcpy(sstrtemp, stringtrimspace(payload));
  7444. c=0;
  7445. loc = strstr(sstrtemp, "transactionId");
  7446. if(loc == NULL)
  7447. {
  7448. transactionIdIsNULL= TRUE;
  7449. }
  7450. else
  7451. {
  7452. memset(sstr ,0, sizeof(sstr) );
  7453. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7454. {
  7455. sstr[c] = loc[strlen("transactionId")+2+c];
  7456. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7457. c++;
  7458. }
  7459. sstr[c] = '\0';
  7460. transactionIdInt = atoi(sstr);
  7461. }
  7462. if(transactionIdIsNULL == FALSE)
  7463. {
  7464. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7465. {
  7466. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7467. {
  7468. //check Transaction active
  7469. if(gunType[gun_index] == 'J')
  7470. {
  7471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7472. {
  7473. tempIndex = ((gun_index==2) ? 1: 0);
  7474. }
  7475. else
  7476. {
  7477. tempIndex = gun_index;
  7478. }
  7479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7480. {
  7481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7482. {
  7483. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7484. {
  7485. match = TRUE;
  7486. GunNO = gun_index;
  7487. }
  7488. }
  7489. }// END FOR CHAdeMO_QUANTITY
  7490. }
  7491. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7492. {
  7493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7494. {
  7495. tempIndex = ((gun_index==2) ? 1: 0);
  7496. }
  7497. else
  7498. {
  7499. tempIndex = gun_index;
  7500. }
  7501. for (int index = 0; index < CCS_QUANTITY; index++)
  7502. {
  7503. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7504. {
  7505. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7506. {
  7507. match = TRUE;
  7508. GunNO = gun_index;
  7509. }
  7510. }
  7511. }// END FOR CCS_QUANTITY
  7512. }
  7513. else if(gunType[gun_index] == 'G')
  7514. {
  7515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7516. {
  7517. tempIndex = ((gun_index==2) ? 1: 0);
  7518. }
  7519. else
  7520. {
  7521. tempIndex = gun_index;
  7522. }
  7523. for (int index = 0; index < GB_QUANTITY; index++)
  7524. {
  7525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7526. {
  7527. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7528. {
  7529. match = TRUE;
  7530. GunNO = gun_index;
  7531. }
  7532. }
  7533. }// END FOR GB_QUANTITY
  7534. }
  7535. else
  7536. {
  7537. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7538. {
  7539. tempIndex = 2;
  7540. }
  7541. else
  7542. {
  7543. tempIndex = gun_index;
  7544. }
  7545. for (int index = 0; index < AC_QUANTITY; index++)
  7546. {
  7547. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7548. {
  7549. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7550. {
  7551. match = TRUE;
  7552. GunNO = gun_index;
  7553. }
  7554. }
  7555. }// END FOR CHAdeMO_QUANTITY
  7556. } // END FOR AC ELSE
  7557. }// CHECK IF ResponseTransactionId == transactionIdInt
  7558. }//END FOR
  7559. if( match == TRUE)
  7560. {
  7561. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7562. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7563. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7564. }
  7565. else
  7566. {
  7567. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7568. }
  7569. }
  7570. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7571. return result;
  7572. }
  7573. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7574. {
  7575. mtrace();
  7576. int result = FAIL;
  7577. int connectorIdInt=0, reservationIdInt=0;
  7578. int tempIndex = 0;
  7579. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7580. char comfirmstr[20]={0};
  7581. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7582. int c = 0;
  7583. char *loc;
  7584. //char *ptr;
  7585. //[2,"1571898416054","ReserveNow",{"connectorId":1,"expiryDate":"2020-06-19T09:10:00.000Z","idTag":"B014EA9C","reservationId":1}]
  7586. strcpy(sstrtemp, stringtrimspace(payload));
  7587. //***(1)connectorId ****/
  7588. c=0;
  7589. loc = strstr(sstrtemp, "connectorId");
  7590. memset(sstr ,0, sizeof(sstr) );
  7591. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7592. {
  7593. sstr[c] = loc[strlen("connectorId")+2+c];
  7594. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7595. c++;
  7596. }
  7597. sstr[c] = '\0';
  7598. connectorIdInt = atoi(sstr);
  7599. //***(2)expiryDate ****/
  7600. loc = strstr(sstrtemp, "expiryDate");
  7601. memset(sstr ,0, sizeof(sstr) );
  7602. c = 0;
  7603. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7604. {
  7605. sstr[c] = loc[3+strlen("expiryDate")+c];
  7606. c++;
  7607. }
  7608. sstr[c] = '\0';
  7609. strcpy(expiryDatestr, sstr);
  7610. //***(3)idTag ****/
  7611. loc = strstr(sstrtemp, "idTag");
  7612. memset(sstr ,0, sizeof(sstr) );
  7613. c = 0;
  7614. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7615. {
  7616. sstr[c] = loc[3+strlen("idTag")+c];
  7617. c++;
  7618. }
  7619. sstr[c] = '\0';
  7620. strcpy(idTagstr, sstr);
  7621. //***(4)parentIdTag ****/
  7622. loc = strstr(sstrtemp, "parentIdTag");
  7623. memset(sstr ,0, sizeof(sstr) );
  7624. c = 0;
  7625. if(loc == NULL)
  7626. {
  7627. strcpy(parentIdTagstr, "");
  7628. }
  7629. else
  7630. {
  7631. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7632. {
  7633. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7634. c++;
  7635. }
  7636. sstr[c] = '\0';
  7637. strcpy(parentIdTagstr, sstr);
  7638. }
  7639. //***(5)reservationId ****/
  7640. c=0;
  7641. loc = strstr(sstrtemp, "reservationId");
  7642. memset(sstr ,0, sizeof(sstr) );
  7643. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7644. {
  7645. sstr[c] = loc[strlen("reservationId")+2+c];
  7646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7647. c++;
  7648. }
  7649. sstr[c] = '\0';
  7650. reservationIdInt = atoi(sstr);
  7651. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7652. /*
  7653. enum SYSTEM_STATUS
  7654. {
  7655. SYS_MODE_BOOTING = 0,
  7656. SYS_MODE_IDLE = 1,
  7657. SYS_MODE_AUTHORIZING = 2,
  7658. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7659. SYS_MODE_REASSIGN = 4,
  7660. SYS_MODE_PREPARING = 5,
  7661. SYS_MODE_PREPARE_FOR_EV = 6,
  7662. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7663. SYS_MODE_CHARGING = 8,
  7664. SYS_MODE_TERMINATING = 9,
  7665. SYS_MODE_COMPLETE = 10,
  7666. SYS_MODE_ALARM = 11,
  7667. SYS_MODE_FAULT = 12,
  7668. SYS_MODE_RESERVATION = 13,
  7669. SYS_MODE_BOOKING = 14,
  7670. SYS_MODE_MAINTAIN = 15,
  7671. SYS_MODE_DEBUG = 16,
  7672. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7673. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7674. SYS_MODE_UPDATE = 19
  7675. };
  7676. */
  7677. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7678. {
  7679. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7680. goto end;
  7681. }
  7682. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7683. {
  7684. //check Transaction active
  7685. if(gunType[connectorIdInt -1] == 'J')
  7686. {
  7687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7688. {
  7689. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7690. }
  7691. else
  7692. {
  7693. tempIndex = connectorIdInt -1;
  7694. }
  7695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7696. {
  7697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7698. {
  7699. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7700. {
  7701. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7702. {
  7703. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7704. {
  7705. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7706. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7707. }
  7708. else if((ShmSysConfigAndInfo->SysInfo.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'))
  7709. {
  7710. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7711. }
  7712. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. }
  7716. else
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7719. }
  7720. }
  7721. else if((ShmSysConfigAndInfo->SysInfo.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
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7724. }
  7725. }
  7726. else
  7727. {
  7728. //replace reservation
  7729. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7731. }
  7732. }
  7733. } // END FOR CHAdeMO_QUANTITY
  7734. }
  7735. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7736. {
  7737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7738. {
  7739. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7740. }
  7741. else
  7742. {
  7743. tempIndex = connectorIdInt -1;
  7744. }
  7745. for (int index = 0; index < CCS_QUANTITY; index++)
  7746. {
  7747. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7748. {
  7749. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7750. {
  7751. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7752. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7753. {
  7754. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7755. {
  7756. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7757. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7758. }
  7759. 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'))
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7762. }
  7763. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7764. {
  7765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7766. }
  7767. else
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7770. }
  7771. }
  7772. 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
  7773. {
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7775. }
  7776. }
  7777. else
  7778. {
  7779. //replace reservation
  7780. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7782. }
  7783. }
  7784. } // END FOR CCS_QUANTITY
  7785. }
  7786. else if(gunType[connectorIdInt -1] == 'G')
  7787. {
  7788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7789. {
  7790. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7791. }
  7792. else
  7793. {
  7794. tempIndex = connectorIdInt -1;
  7795. }
  7796. for (int index = 0; index < GB_QUANTITY; index++)
  7797. {
  7798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7799. {
  7800. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7801. {
  7802. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7803. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7804. {
  7805. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7806. {
  7807. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7808. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7809. }
  7810. 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'))
  7811. {
  7812. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7813. }
  7814. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7815. {
  7816. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7817. }
  7818. else
  7819. {
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7821. }
  7822. }
  7823. 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
  7824. {
  7825. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7826. }
  7827. }
  7828. else
  7829. {
  7830. //replace reservation
  7831. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7832. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7833. }
  7834. }
  7835. }// END FOR GB_QUANTITY
  7836. }
  7837. else
  7838. {
  7839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7840. {
  7841. tempIndex = 2;
  7842. }
  7843. else
  7844. {
  7845. tempIndex = (connectorIdInt -1);
  7846. }
  7847. for (int index = 0; index < AC_QUANTITY; index++)
  7848. {
  7849. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7850. {
  7851. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7852. {
  7853. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7854. {
  7855. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7856. {
  7857. 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))
  7858. {
  7859. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7860. }
  7861. else
  7862. {
  7863. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7864. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7865. }
  7866. }
  7867. 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'))
  7868. {
  7869. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7870. }
  7871. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7872. {
  7873. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7874. }
  7875. else
  7876. {
  7877. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7878. }
  7879. }
  7880. 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
  7881. {
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7883. }
  7884. }
  7885. else
  7886. {
  7887. //replace reservation
  7888. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7889. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7890. }
  7891. }
  7892. } // END FOR AC_QUANTITY
  7893. }
  7894. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7895. }
  7896. else if(connectorIdInt == 0)
  7897. {
  7898. //check Transaction active
  7899. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7900. {
  7901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7902. {
  7903. 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'))
  7904. {
  7905. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7906. goto end;
  7907. }
  7908. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7909. {
  7910. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7911. goto end;
  7912. }
  7913. 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
  7914. {
  7915. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7916. goto end;
  7917. }
  7918. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7919. {
  7920. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7921. goto end;
  7922. }
  7923. }
  7924. }// END FOR CHAdeMO_QUANTITY
  7925. for (int index = 0; index < CCS_QUANTITY; index++)
  7926. {
  7927. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7928. {
  7929. 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'))
  7930. {
  7931. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7932. goto end;
  7933. }
  7934. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7935. {
  7936. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7937. goto end;
  7938. }
  7939. 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
  7940. {
  7941. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7942. goto end;
  7943. }
  7944. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7945. {
  7946. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7947. goto end;
  7948. }
  7949. }
  7950. } // END FOR CCS_QUANTITY
  7951. for (int index = 0; index < GB_QUANTITY; index++)
  7952. {
  7953. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7954. {
  7955. 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'))
  7956. {
  7957. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7958. goto end;
  7959. }
  7960. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7961. {
  7962. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7963. goto end;
  7964. }
  7965. 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
  7966. {
  7967. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7968. goto end;
  7969. }
  7970. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7971. {
  7972. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7973. goto end;
  7974. }
  7975. }
  7976. } // END FOR GB_QUANTITY
  7977. for (int index = 0; index < AC_QUANTITY; index++)
  7978. {
  7979. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7980. {
  7981. 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'))
  7982. {
  7983. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7984. goto end;
  7985. }
  7986. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7987. {
  7988. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7989. goto end;
  7990. }
  7991. 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
  7992. {
  7993. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7994. goto end;
  7995. }
  7996. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7997. {
  7998. 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))
  7999. {
  8000. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8001. goto end;
  8002. }
  8003. }
  8004. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8005. {
  8006. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8007. goto end;
  8008. }
  8009. }
  8010. }// END FOR AC_QUANTITY
  8011. //The connectorId is 0
  8012. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8013. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8014. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8015. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8016. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8017. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8018. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8019. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8020. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8021. result = TRUE;
  8022. return result;
  8023. }
  8024. else
  8025. {
  8026. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8027. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8028. }
  8029. if(strcmp(comfirmstr,"Accepted") == 0)
  8030. {
  8031. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8032. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8033. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8034. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8035. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8036. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8037. result = TRUE;
  8038. return result;
  8039. }
  8040. end:
  8041. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8042. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8043. return result;
  8044. }
  8045. int handleResetRequest(char *uuid, char *payload)
  8046. {
  8047. mtrace();
  8048. int result = FAIL;
  8049. char sstr[10]={0},sstrtemp[30]={ 0 };
  8050. char typestr[10]={0};
  8051. char comfirmstr[20]={0};
  8052. int c = 0;
  8053. char *loc;
  8054. //[2,"6f88d461-4d17-462c-a69b-1f7a8c5b12df","Reset",{"type":"Hard"}]
  8055. DEBUG_INFO("handleResetRequest ...\n");
  8056. strcpy(sstrtemp, stringtrimspace(payload));
  8057. loc = strstr(sstrtemp, "type");
  8058. memset(sstr ,0, sizeof(sstr) );
  8059. c = 0;
  8060. while (loc[3+strlen("type")+c] != '\"')
  8061. {
  8062. sstr[c] = loc[3+strlen("type")+c];
  8063. c++;
  8064. }
  8065. sstr[c] = '\0';
  8066. strcpy(typestr,sstr);
  8067. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8068. //strcpy(ShmOCPP16Data->Reset.Type, typestr);
  8069. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8070. {
  8071. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8072. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8073. result = TRUE;
  8074. return result;
  8075. }
  8076. else
  8077. {
  8078. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8079. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8080. goto errorend;
  8081. }
  8082. errorend:
  8083. sendResetConfirmation(uuid, comfirmstr);
  8084. return result;
  8085. }
  8086. int handleSendLocalListRequest(char *uuid, char *payload)
  8087. {
  8088. mtrace();
  8089. int result = FAIL;
  8090. int listVersionInt;
  8091. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8092. char listsearch[]="listVersion";
  8093. char updateTypesearch[]="updateType";
  8094. char localAuthorizationListsearch[]="localAuthorizationList";
  8095. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8096. char CardList[500][160]={0};
  8097. char updateTypestr[15]={0};
  8098. char idTagstr[20]={0};
  8099. char parentIdTag[20]={0};
  8100. char expiryDate[30]={0};
  8101. char idTagstatus[16]={0};
  8102. int c = 0;
  8103. int i = 0;
  8104. char *delim1 = "}";
  8105. char * pch;
  8106. char *loc;
  8107. //char *ptr;
  8108. char comfirmstr[20];
  8109. //int n_localAuthorizations = 0;
  8110. int checkState_Faulted = FALSE;
  8111. DEBUG_INFO("handleSendLocalListRequest\n");
  8112. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8113. {
  8114. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8115. goto end;
  8116. }
  8117. //check Charge Point state
  8118. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8119. {
  8120. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8121. {
  8122. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8123. }
  8124. }
  8125. for (int index = 0; index < CCS_QUANTITY; index++)
  8126. {
  8127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8128. {
  8129. checkState_Faulted = TRUE; //OCPP Status
  8130. }
  8131. }
  8132. for (int index = 0; index < GB_QUANTITY; index++)
  8133. {
  8134. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8135. {
  8136. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8137. }
  8138. }
  8139. //check Charge Point state
  8140. for (int index = 0; index < AC_QUANTITY; index++)
  8141. {
  8142. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8143. {
  8144. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8145. }
  8146. }
  8147. if(checkState_Faulted == TRUE)
  8148. {
  8149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8150. goto end;
  8151. }
  8152. //Filter payload space
  8153. strcpy(sstrtemp, stringtrimspace(payload));
  8154. //listVersion
  8155. c = 0;
  8156. loc = strstr(sstrtemp, listsearch);
  8157. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8158. {
  8159. sstr[c] = loc[strlen("listVersion")+2+c];
  8160. c++;
  8161. }
  8162. sstr[c] = '\0';
  8163. listVersionInt = atoi(sstr);
  8164. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8165. //updateType
  8166. loc = strstr(sstrtemp, updateTypesearch);
  8167. c = 0;
  8168. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8169. {
  8170. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8171. c++;
  8172. }
  8173. sstr[c] = '\0';
  8174. strcpy(updateTypestr, sstr);
  8175. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8176. //localAuthorizationList
  8177. memset(sstr ,0, sizeof(sstr) );
  8178. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8179. if(loc != NULL) // localAuthorizationList is not NULL
  8180. {
  8181. //Check UpdateType
  8182. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8183. {
  8184. //Local list full update
  8185. printf("Local list full update.\n");
  8186. OCPP_getListVerion();
  8187. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8188. {
  8189. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8190. goto end;
  8191. }
  8192. OCPP_cleanLocalList();
  8193. }
  8194. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8195. {
  8196. //Local list different update
  8197. printf("Local list different update.\n");
  8198. OCPP_getListVerion();
  8199. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8200. {
  8201. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8202. goto end;
  8203. }
  8204. }
  8205. else
  8206. {
  8207. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8208. goto end;
  8209. }
  8210. c = 0;
  8211. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8212. {
  8213. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8214. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8215. c++;
  8216. }
  8217. sstr[c] = '\0';
  8218. //DEBUG_INFO("sstr=%s\n", sstr);
  8219. //parsing strings to words
  8220. i = 0;
  8221. pch = strtok(sstr,delim1);
  8222. while (pch != NULL)
  8223. {
  8224. strcpy(CardList[i], pch);
  8225. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8226. pch = strtok (NULL, delim1);
  8227. i = i + 1;
  8228. }
  8229. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8230. //local Authorizations List Numbers
  8231. //n_localAuthorizations = i;
  8232. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8233. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8234. c= 0;
  8235. while(c < i) // i is CardList Number
  8236. {
  8237. //Search "IdToken"
  8238. memset(sstr ,0, sizeof(sstr) );
  8239. loc = strstr(CardList[c], "idTag");
  8240. int j = 0;
  8241. while (loc[3+strlen("idTag")+j] != '\"')
  8242. {
  8243. sstr[j] = loc[3+strlen("idTag")+j];
  8244. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8245. j++;
  8246. }
  8247. sstr[j] = '\0';
  8248. strcpy(idTagstr, sstr);
  8249. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8250. //Search "expiryDate"
  8251. memset(sstr ,0, sizeof(sstr) );
  8252. loc = strstr(CardList[c], "expiryDate");
  8253. j = 0;
  8254. if(loc != NULL)
  8255. {
  8256. while (loc[3+strlen("expiryDate")+j] != '\"')
  8257. {
  8258. sstr[j] = loc[3+strlen("expiryDate")+j];
  8259. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8260. j++;
  8261. }
  8262. sstr[j] = '\0';
  8263. strcpy(expiryDate, sstr);
  8264. }
  8265. else
  8266. {
  8267. strcpy(expiryDate, "");
  8268. }
  8269. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8270. //Search "parentIdTag"
  8271. memset(sstr ,0, sizeof(sstr) );
  8272. loc = strstr(CardList[c], "parentIdTag");
  8273. j = 0;
  8274. if(loc != NULL)
  8275. {
  8276. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8277. {
  8278. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8279. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8280. j++;
  8281. }
  8282. sstr[j] = '\0';
  8283. strcpy(parentIdTag, sstr);
  8284. }
  8285. else
  8286. {
  8287. strcpy(parentIdTag, "");
  8288. }
  8289. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8290. //Search "status"
  8291. memset(sstr ,0, sizeof(sstr) );
  8292. loc = strstr(CardList[c], "status");
  8293. j = 0;
  8294. while (loc[3+strlen("status")+j] != '\"')
  8295. {
  8296. sstr[j] = loc[3+strlen("status")+j];
  8297. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8298. j++;
  8299. }
  8300. sstr[j] = '\0';
  8301. strcpy(idTagstatus, sstr);
  8302. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8303. OCPP_getIdTag(idTagstr);
  8304. //OCPP_getIdTag("test"); For Test
  8305. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8306. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8307. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8308. {
  8309. //Local list full
  8310. DEBUG_INFO("Local list full update.\n");
  8311. // update list
  8312. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8313. //DEBUG_INFO("Local list full update. 1\n");
  8314. //OCPP_get_TableAuthlocalAllData();
  8315. //DEBUG_INFO("Local list full update. 2\n");
  8316. }
  8317. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8318. {
  8319. #if 0
  8320. if(strcmp(idTagstr, idTagAuthorization) == 0)
  8321. {
  8322. //OCPP_deleteIdTag(idTagstr);
  8323. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update
  8324. }
  8325. else if(strcmp(idTagstr, idTagAuthorization) != 0)
  8326. {
  8327. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // add
  8328. }
  8329. #endif
  8330. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8331. }
  8332. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8333. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8334. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8335. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8336. c++;
  8337. }
  8338. }
  8339. else
  8340. {
  8341. //Check UpdateType
  8342. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8343. {
  8344. //Local list full update
  8345. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8346. OCPP_cleanLocalList();
  8347. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8348. goto end;
  8349. }
  8350. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8351. {
  8352. //Local list different update
  8353. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8354. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8355. goto end;
  8356. }
  8357. }
  8358. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8359. end:
  8360. sendSendLocalListConfirmation(uuid, comfirmstr);
  8361. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8362. return result;
  8363. }
  8364. #define MAX 200
  8365. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8366. {
  8367. mtrace();
  8368. int result = FAIL;
  8369. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8370. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8371. char chargingProfilePurposeStr[30]={0};
  8372. char chargingProfileKindStr[16]={0};
  8373. char recurrencyKindStr[10]={0};
  8374. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8375. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8376. int chargingSchedulePeriodCount = 0;
  8377. //int updateflag = FALSE;
  8378. char comfirmstr[20]={0};
  8379. int meet= FALSE;
  8380. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8381. int c = 0;
  8382. char *loc;
  8383. FILE *fptr1;//, *fptr2;
  8384. //int lno=0;//, linectr = 0;
  8385. //int modifyflag = FALSE;
  8386. char filename[MAX]={0};
  8387. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8388. //int resultRename=0;
  8389. char rmFileCmd[50]={0};
  8390. char tempchargingProfilePurposeStr[30]={0};
  8391. char word[1600]={0};
  8392. int n_chargingProfile = 0;
  8393. //[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}}}]
  8394. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8395. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8396. //Filter string space
  8397. strcpy(sstrtemp, stringtrimspace(payload));
  8398. //*********************connectorId***************************/
  8399. loc = strstr(sstrtemp, "connectorId");
  8400. c = 0;
  8401. memset(sstr ,0, sizeof(sstr) );
  8402. while (loc[strlen("connectorId")+2+c] != ',')
  8403. {
  8404. sstr[c] = loc[strlen("connectorId")+2+c];
  8405. c++;
  8406. }
  8407. sstr[c] = '\0';
  8408. connectorIdInt = atoi(sstr);
  8409. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8410. {
  8411. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8412. }
  8413. else
  8414. {
  8415. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8416. }
  8417. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8418. //*********************chargingProfileId***************************/
  8419. loc = strstr(sstrtemp, "chargingProfileId");
  8420. c = 0;
  8421. memset(sstr ,0, sizeof(sstr) );
  8422. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8423. {
  8424. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8425. c++;
  8426. }
  8427. sstr[c] = '\0';
  8428. chargingProfileIdInt = atoi(sstr);
  8429. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8430. {
  8431. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8432. }
  8433. else
  8434. {
  8435. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8436. }
  8437. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8438. //*********************transactionId***************************/
  8439. loc = strstr(sstrtemp, "transactionId");
  8440. if(loc != NULL)
  8441. {
  8442. c = 0;
  8443. memset(sstr ,0, sizeof(sstr) );
  8444. while (loc[strlen("transactionId")+2+c] != ',')
  8445. {
  8446. sstr[c] = loc[strlen("transactionId")+2+c];
  8447. c++;
  8448. }
  8449. sstr[c] = '\0';
  8450. transactionIdInt = atoi(sstr);
  8451. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8452. {
  8453. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8454. }
  8455. else
  8456. {
  8457. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8458. }
  8459. }
  8460. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8461. //*********************stackLevel***************************/
  8462. loc = strstr(sstrtemp, "stackLevel");
  8463. c = 0;
  8464. memset(sstr ,0, sizeof(sstr) );
  8465. while (loc[strlen("stackLevel")+2+c] != ',')
  8466. {
  8467. sstr[c] = loc[strlen("stackLevel")+2+c];
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. stackLevelInt = atoi(sstr);
  8472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8473. {
  8474. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8475. }
  8476. else
  8477. {
  8478. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8479. }
  8480. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8481. //*********************chargingProfilePurpose***************************/
  8482. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8483. c = 0;
  8484. memset(sstr ,0, sizeof(sstr) );
  8485. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8486. {
  8487. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8488. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8489. c++;
  8490. }
  8491. sstr[c] = '\0';
  8492. strcpy(chargingProfilePurposeStr,sstr);
  8493. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8494. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8495. {
  8496. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8497. }
  8498. else
  8499. {
  8500. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8501. }
  8502. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8503. //*********************chargingProfileKind***************************/
  8504. loc = strstr(sstrtemp, "chargingProfileKind");
  8505. c = 0;
  8506. memset(sstr ,0, sizeof(sstr) );
  8507. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8508. {
  8509. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8511. c++;
  8512. }
  8513. sstr[c] = '\0';
  8514. strcpy(chargingProfileKindStr,sstr);
  8515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8516. {
  8517. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8518. }
  8519. else
  8520. {
  8521. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8522. }
  8523. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8524. //*********************recurrencyKind***************************/
  8525. loc = strstr(sstrtemp, "recurrencyKind");
  8526. if(loc != NULL)
  8527. {
  8528. c = 0;
  8529. memset(sstr ,0, sizeof(sstr) );
  8530. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8531. {
  8532. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8533. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8534. c++;
  8535. }
  8536. sstr[c] = '\0';
  8537. strcpy(recurrencyKindStr,sstr);
  8538. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8539. {
  8540. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8541. }
  8542. else
  8543. {
  8544. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8545. }
  8546. }
  8547. else
  8548. {
  8549. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8550. {
  8551. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8552. }
  8553. else
  8554. {
  8555. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8556. }
  8557. }
  8558. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8559. //*********************validFrom***************************/
  8560. loc = strstr(sstrtemp, "validFrom");
  8561. if(loc != NULL)
  8562. {
  8563. c = 0;
  8564. memset(sstr ,0, sizeof(sstr) );
  8565. while (loc[3+strlen("validFrom")+c] != '\"')
  8566. {
  8567. sstr[c] = loc[3+strlen("validFrom")+c];
  8568. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8569. c++;
  8570. }
  8571. sstr[c] = '\0';
  8572. strcpy(validFromStr,sstr);
  8573. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8574. {
  8575. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8576. }
  8577. else
  8578. {
  8579. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8580. }
  8581. }
  8582. else
  8583. {
  8584. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8585. {
  8586. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8587. }
  8588. else
  8589. {
  8590. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8591. }
  8592. }
  8593. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8594. //*********************validTo***************************/
  8595. loc = strstr(sstrtemp, "validTo");
  8596. if(loc != NULL)
  8597. {
  8598. c = 0;
  8599. memset(sstr ,0, sizeof(sstr) );
  8600. while (loc[3+strlen("validTo")+c] != '\"')
  8601. {
  8602. sstr[c] = loc[3+strlen("validTo")+c];
  8603. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8604. c++;
  8605. }
  8606. sstr[c] = '\0';
  8607. strcpy(validToStr,sstr);
  8608. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8609. {
  8610. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8611. }
  8612. else
  8613. {
  8614. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8615. }
  8616. }
  8617. else
  8618. {
  8619. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8620. {
  8621. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8622. }
  8623. else
  8624. {
  8625. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8626. }
  8627. }
  8628. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8629. //*********************duration***************************/
  8630. loc = strstr(sstrtemp, "duration");
  8631. if(loc != NULL)
  8632. {
  8633. c = 0;
  8634. memset(sstr ,0, sizeof(sstr) );
  8635. while (loc[strlen("duration")+2+c] != ',')
  8636. {
  8637. sstr[c] = loc[strlen("duration")+2+c];
  8638. c++;
  8639. }
  8640. sstr[c] = '\0';
  8641. durationInt = atoi(sstr);
  8642. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8643. {
  8644. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8645. }
  8646. else
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8649. }
  8650. }
  8651. else
  8652. {
  8653. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8654. {
  8655. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8656. }
  8657. else
  8658. {
  8659. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8660. }
  8661. }
  8662. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8663. //*********************startSchedule***************************/
  8664. loc = strstr(sstrtemp, "startSchedule");
  8665. if(loc != NULL)
  8666. {
  8667. c = 0;
  8668. memset(sstr ,0, sizeof(sstr) );
  8669. while (loc[3+strlen("startSchedule")+c] != '\"')
  8670. {
  8671. sstr[c] = loc[3+strlen("startSchedule")+c];
  8672. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8673. c++;
  8674. }
  8675. sstr[c] = '\0';
  8676. strcpy(startScheduleStr,sstr);
  8677. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8678. {
  8679. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8680. }
  8681. else
  8682. {
  8683. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8684. }
  8685. }
  8686. else
  8687. {
  8688. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8689. {
  8690. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8691. }
  8692. else
  8693. {
  8694. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8695. }
  8696. }
  8697. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8698. //*********************chargingRateUnit***************************/
  8699. loc = strstr(sstrtemp, "chargingRateUnit");
  8700. if(loc != NULL)
  8701. {
  8702. c = 0;
  8703. memset(sstr ,0, sizeof(sstr) );
  8704. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8705. {
  8706. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8707. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8708. c++;
  8709. }
  8710. sstr[c] = '\0';
  8711. strcpy(chargingRateUnitStr,sstr);
  8712. #if 0
  8713. if((strcmp(chargingRateUnitStr,"A")!=0)&& strcmp((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current")==0)
  8714. {
  8715. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8716. goto end;
  8717. }
  8718. #endif
  8719. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8720. {
  8721. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8722. }
  8723. else
  8724. {
  8725. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8726. }
  8727. }
  8728. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8729. //****************chargingSchedulePeriod count start*******************/
  8730. int what_len = strlen("startPeriod");
  8731. char tempChargingProfile[1600]={0};
  8732. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8733. char *where = tempChargingProfile;
  8734. if (what_len)
  8735. {
  8736. while ((where = strstr(where, "startPeriod"))) {
  8737. where += what_len;
  8738. chargingSchedulePeriodCount++;
  8739. }
  8740. }
  8741. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8742. {
  8743. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8744. goto end;
  8745. }
  8746. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8747. //where = payload;
  8748. int templength = 0;
  8749. //int searchstart = 0;
  8750. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8751. {
  8752. //****************startPeriod*******************/
  8753. c=0;
  8754. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8755. memset(sstr ,0, sizeof(sstr) );
  8756. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8757. {
  8758. sstr[c] = loc[strlen("startPeriod")+2+c];
  8759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8760. c++;
  8761. }
  8762. sstr[c] = '\0';
  8763. startPeriodInt[periodNums] = atoi(sstr);
  8764. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8765. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8766. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8767. {
  8768. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8769. }
  8770. else
  8771. {
  8772. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8773. }
  8774. templength = strlen("startPeriod")+2+c;
  8775. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8776. //****************limit*******************/
  8777. c=0;
  8778. loc = strstr(tempChargingProfile + templength, "limit");
  8779. memset(sstr ,0, sizeof(sstr) );
  8780. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8781. {
  8782. sstr[c] = loc[strlen("limit")+2+c];
  8783. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8784. c++;
  8785. }
  8786. sstr[c] = '\0';
  8787. limitflaot[periodNums] = atof(sstr);
  8788. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8789. {
  8790. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8791. }
  8792. else
  8793. {
  8794. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8795. }
  8796. templength = templength + strlen("limit")+2+c;
  8797. //****************numberPhases*******************/
  8798. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8799. if(loc != NULL)
  8800. {
  8801. c=0;
  8802. memset(sstr ,0, sizeof(sstr) );
  8803. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8804. {
  8805. sstr[c] = loc[strlen("numberPhases")+2+c];
  8806. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8807. c++;
  8808. }
  8809. sstr[c] = '\0';
  8810. numberPhasesInt[periodNums] = atoi(sstr);
  8811. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8812. {
  8813. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8814. }
  8815. else
  8816. {
  8817. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8818. }
  8819. templength = templength + strlen("numberPhases")+2+c;
  8820. }
  8821. //where = loc;
  8822. }
  8823. //****************chargingSchedulePeriod count end*******************/
  8824. //*********************minChargingRate***************************/
  8825. loc = strstr(sstrtemp, "minChargingRate");
  8826. if(loc != NULL)
  8827. {
  8828. c = 0;
  8829. memset(sstr ,0, sizeof(sstr) );
  8830. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8831. {
  8832. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8833. c++;
  8834. }
  8835. sstr[c] = '\0';
  8836. minChargingRateFloat = atof(sstr);
  8837. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8838. {
  8839. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8840. }
  8841. else
  8842. {
  8843. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8844. }
  8845. }
  8846. else
  8847. {
  8848. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8849. {
  8850. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8851. }
  8852. else
  8853. {
  8854. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8855. }
  8856. }
  8857. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8858. {
  8859. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8860. if(connectorIdInt != 0)
  8861. {
  8862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8863. goto end;
  8864. }
  8865. strcpy(filename, ChargePointMaxProfile_JSON );
  8866. fptr1 = fopen(filename, "r");
  8867. if (!fptr1)
  8868. {
  8869. //file not exist
  8870. DEBUG_INFO("Unable to open the input file!!\n");
  8871. fptr1 = fopen(filename, "w+");
  8872. }
  8873. else
  8874. {
  8875. //Check Charging Profile Count
  8876. while(fscanf(fptr1, "%s", word) != EOF)
  8877. {
  8878. //DEBUG_INFO("word=%s\n",word);
  8879. if(strstr(word, "chargingProfileId")!= NULL)
  8880. {
  8881. //DEBUG_INFO("test chargingProfileId \n");
  8882. n_chargingProfile = n_chargingProfile + 1;
  8883. //DEBUG_INFO("chargingProfileId Found\n");
  8884. }
  8885. }
  8886. }
  8887. fclose(fptr1);
  8888. }
  8889. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8890. {
  8891. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8892. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8893. {
  8894. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8895. goto end;
  8896. }
  8897. memset(filename, 0, sizeof filename);
  8898. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8899. fptr1 = fopen(filename, "r");
  8900. if (!fptr1)
  8901. {
  8902. //file not exist
  8903. //DEBUG_INFO("Unable to open the input file!!\n");
  8904. fptr1 = fopen(filename, "w+");
  8905. }
  8906. else
  8907. {
  8908. //Check Charging Profile Count
  8909. while(fscanf(fptr1, "%s", word) != EOF)
  8910. {
  8911. //DEBUG_INFO("word=%s\n",word);
  8912. if(strstr(word, "chargingProfileId")!= NULL)
  8913. {
  8914. //DEBUG_INFO("test chargingProfileId \n");
  8915. n_chargingProfile = n_chargingProfile + 1;
  8916. //DEBUG_INFO("chargingProfileId Found\n");
  8917. }
  8918. }
  8919. }
  8920. fclose(fptr1);
  8921. }
  8922. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8923. {
  8924. //printf("set chargingProfile 1-4\n");
  8925. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8926. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8927. if(connectorIdInt == 0)
  8928. {
  8929. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8930. goto end;
  8931. }
  8932. int tempIndex = 0;
  8933. //check Transaction active
  8934. if(gunType[connectorIdInt -1] == 'J')
  8935. {
  8936. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8937. {
  8938. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8939. }
  8940. else
  8941. {
  8942. tempIndex = connectorIdInt -1;
  8943. }
  8944. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8945. {
  8946. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8947. {
  8948. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8949. {
  8950. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8951. {
  8952. meet = TRUE;
  8953. break;
  8954. }
  8955. }
  8956. }
  8957. }
  8958. }
  8959. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8960. {
  8961. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8962. {
  8963. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8964. }
  8965. else
  8966. {
  8967. tempIndex = connectorIdInt -1;
  8968. }
  8969. for (int index = 0; index < CCS_QUANTITY; index++)
  8970. {
  8971. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8972. {
  8973. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8974. {
  8975. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8976. {
  8977. meet = TRUE;
  8978. break;
  8979. }
  8980. }
  8981. }
  8982. }
  8983. }
  8984. else if(gunType[connectorIdInt -1] == 'G')
  8985. {
  8986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8987. {
  8988. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8989. }
  8990. else
  8991. {
  8992. tempIndex = connectorIdInt -1;
  8993. }
  8994. for (int index = 0; index < GB_QUANTITY; index++)
  8995. {
  8996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8997. {
  8998. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8999. {
  9000. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9001. {
  9002. meet = TRUE;
  9003. break;
  9004. }
  9005. }
  9006. }
  9007. }
  9008. }
  9009. else
  9010. {
  9011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9012. {
  9013. tempIndex = 2;
  9014. }
  9015. else
  9016. {
  9017. tempIndex = (connectorIdInt -1);
  9018. }
  9019. for (int index = 0; index < AC_QUANTITY; index++)
  9020. {
  9021. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9022. {
  9023. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  9024. {
  9025. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  9026. {
  9027. meet = TRUE;
  9028. break;
  9029. }
  9030. }
  9031. }
  9032. }
  9033. }
  9034. //check Transaction active
  9035. if(meet == FALSE)
  9036. {
  9037. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9038. goto end;
  9039. }
  9040. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  9041. {
  9042. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9043. goto end;
  9044. }
  9045. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9046. fptr1 = fopen(filename, "r");
  9047. if (!fptr1)
  9048. {
  9049. //file not exist
  9050. DEBUG_INFO("Unable to open the input file!!\n");
  9051. fptr1 = fopen(filename, "w+");
  9052. }
  9053. else
  9054. {
  9055. //Check Charging Profile Count
  9056. while(fscanf(fptr1, "%s", word) != EOF)
  9057. {
  9058. //DEBUG_INFO("word=%s\n",word);
  9059. if(strstr(word, "chargingProfileId")!= NULL)
  9060. {
  9061. //DEBUG_INFO("test chargingProfileId \n");
  9062. n_chargingProfile = n_chargingProfile + 1;
  9063. //DEBUG_INFO("chargingProfileId Found\n");
  9064. }
  9065. }
  9066. }
  9067. fclose(fptr1);
  9068. }
  9069. // Check ChargeProfileMaxStackLevel
  9070. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  9071. {
  9072. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9073. goto end;
  9074. }
  9075. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9076. {
  9077. int i = 0;
  9078. char fnametemp[200]={0};
  9079. n_chargingProfile = 0;
  9080. //Check ChargePointMaxProfile.json exit
  9081. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9082. {
  9083. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  9084. //Check Charging Profile Count
  9085. while(fscanf(fptr1, "%s", word) != EOF)
  9086. {
  9087. //DEBUG_INFO("word=%s\n",word);
  9088. if(strstr(word, "chargingProfileId")!= NULL)
  9089. {
  9090. //DEBUG_INFO("test chargingProfileId \n");
  9091. n_chargingProfile = n_chargingProfile + 1;
  9092. i = i + 1;
  9093. //DEBUG_INFO("chargingProfileId Found\n");
  9094. }
  9095. memset(word, 0, sizeof word);
  9096. }
  9097. fclose(fptr1);
  9098. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  9099. }
  9100. //Check TxDefaultProfile_0.json exit
  9101. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9102. {
  9103. i = 0;
  9104. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  9105. //Check Charging Profile Count
  9106. while(fscanf(fptr1, "%s", word) != EOF)
  9107. {
  9108. //DEBUG_INFO("word=%s\n",word);
  9109. if(strstr(word, "chargingProfileId")!= NULL)
  9110. {
  9111. //DEBUG_INFO("test chargingProfileId \n");
  9112. n_chargingProfile = n_chargingProfile + 1;
  9113. i = i + 1;
  9114. //DEBUG_INFO("chargingProfileId Found\n");
  9115. }
  9116. memset(word, 0, sizeof word);
  9117. }
  9118. fclose(fptr1);
  9119. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  9120. }
  9121. //Check TxDefaultProfile_%d.json
  9122. for(int j=1; j <= gunTotalNumber; j++)
  9123. {
  9124. memset(fnametemp, 0, sizeof fnametemp);
  9125. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9126. if((access(fnametemp,F_OK))!=-1)
  9127. {
  9128. i = 0;
  9129. fptr1 = fopen(fnametemp, "r");
  9130. //Check Charging Profile Count
  9131. while(fscanf(fptr1, "%s", word) != EOF)
  9132. {
  9133. //DEBUG_INFO("word=%s\n",word);
  9134. if(strstr(word, "chargingProfileId")!= NULL)
  9135. {
  9136. //DEBUG_INFO("test chargingProfileId \n");
  9137. n_chargingProfile = n_chargingProfile + 1;
  9138. i = i + 1;
  9139. //DEBUG_INFO("chargingProfileId Found\n");
  9140. }
  9141. memset(word, 0, sizeof word);
  9142. }
  9143. fclose(fptr1);
  9144. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9145. }
  9146. }
  9147. //Check TxProfile_%d.json
  9148. for(int j=1; j <= gunTotalNumber; j++)
  9149. {
  9150. memset(fnametemp, 0, sizeof fnametemp);
  9151. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9152. if((access(fnametemp,F_OK))!=-1)
  9153. {
  9154. i = 0;
  9155. fptr1 = fopen(fnametemp, "r");
  9156. //Check Charging Profile Count
  9157. while(fscanf(fptr1, "%s", word) != EOF)
  9158. {
  9159. //DEBUG_INFO("word=%s\n",word);
  9160. if(strstr(word, "chargingProfileId")!= NULL)
  9161. {
  9162. //DEBUG_INFO("test chargingProfileId \n");
  9163. n_chargingProfile = n_chargingProfile + 1;
  9164. i = i + 1;
  9165. //DEBUG_INFO("chargingProfileId Found\n");
  9166. }
  9167. memset(word, 0, sizeof word);
  9168. }
  9169. fclose(fptr1);
  9170. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  9171. }
  9172. }
  9173. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  9174. {
  9175. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9176. goto end;
  9177. }
  9178. }
  9179. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9180. //**********************************Write to File********************************************************/
  9181. FILE *infile;
  9182. FILE *outfile;
  9183. // open file for writing
  9184. infile = fopen (filename, "r");
  9185. outfile = fopen (tempfile, "w");
  9186. int d =0;
  9187. d = fgetc(infile);
  9188. //DEBUG_INFO("d:%d\n",d);
  9189. rewind(infile);
  9190. //*检测到文件结束标识返回1,否则返回0。*/
  9191. if(d == EOF)
  9192. {
  9193. //DEBUG_INFO("ChargingProfile content is NULL\n");
  9194. fprintf(outfile,"%s\n",payload);
  9195. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9196. fclose(infile);
  9197. fclose(outfile);
  9198. sprintf(rmFileCmd,"rm -f %s",filename);
  9199. system(rmFileCmd);
  9200. rename(tempfile, filename);
  9201. sleep(1);
  9202. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  9203. //system(rmFileCmd);
  9204. }
  9205. else
  9206. {
  9207. char buf[1000]={0};
  9208. int ChargingProfileAdded = FALSE;
  9209. while (fgets(buf, sizeof(buf), infile) != NULL)
  9210. {
  9211. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9212. //*************************tempconnectorIdInt*********************************/
  9213. loc = strstr(buf, "connectorId");
  9214. c = 0;
  9215. memset(sstr ,0, sizeof(sstr) );
  9216. while (loc[strlen("connectorId")+2+c] != ',')
  9217. {
  9218. sstr[c] = loc[strlen("connectorId")+2+c];
  9219. c++;
  9220. }
  9221. sstr[c] = '\0';
  9222. tempconnectorIdInt = atoi(sstr);
  9223. //*************************tempchargingProfileIdInt*********************************/
  9224. loc = strstr(buf, "chargingProfileId");
  9225. c = 0;
  9226. memset(sstr ,0, sizeof(sstr) );
  9227. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9228. {
  9229. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9230. c++;
  9231. }
  9232. sstr[c] = '\0';
  9233. tempchargingProfileIdInt = atoi(sstr);
  9234. //*************************tempstackLevelInt*********************************/
  9235. loc = strstr(buf, "stackLevel");
  9236. c = 0;
  9237. memset(sstr ,0, sizeof(sstr) );
  9238. while (loc[strlen("stackLevel")+2+c] != ',')
  9239. {
  9240. sstr[c] = loc[strlen("stackLevel")+2+c];
  9241. c++;
  9242. }
  9243. sstr[c] = '\0';
  9244. tempstackLevelInt = atoi(sstr);
  9245. //*************************tempchargingProfilePurposeStr*********************************/
  9246. loc = strstr(payload, "chargingProfilePurpose");
  9247. c = 0;
  9248. memset(sstr ,0, sizeof(sstr) );
  9249. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9250. {
  9251. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9252. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9253. c++;
  9254. }
  9255. sstr[c] = '\0';
  9256. strcpy(tempchargingProfilePurposeStr,sstr);
  9257. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9258. {
  9259. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9260. {
  9261. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9262. if(ChargingProfileAdded == FALSE)
  9263. {
  9264. fprintf(outfile,"%s\n",payload);
  9265. ChargingProfileAdded = TRUE;
  9266. }
  9267. }
  9268. else
  9269. {
  9270. if(tempstackLevelInt < stackLevelInt)
  9271. {
  9272. if(ChargingProfileAdded == FALSE)
  9273. {
  9274. fprintf(outfile,"%s\n",payload);
  9275. ChargingProfileAdded = TRUE;
  9276. fprintf(outfile,"%s\n",buf);
  9277. }
  9278. else
  9279. {
  9280. fprintf(outfile,"%s\n",buf);
  9281. }
  9282. }
  9283. else
  9284. {
  9285. if(ChargingProfileAdded == FALSE)
  9286. {
  9287. fprintf(outfile,"%s\n",buf);
  9288. fprintf(outfile,"%s\n",payload);
  9289. ChargingProfileAdded = TRUE;
  9290. }
  9291. else
  9292. {
  9293. fprintf(outfile,"%s\n",buf);
  9294. }
  9295. }
  9296. }
  9297. }
  9298. else
  9299. {
  9300. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9301. {
  9302. if(ChargingProfileAdded == FALSE)
  9303. {
  9304. fprintf(outfile,"%s\n",payload);
  9305. ChargingProfileAdded = TRUE;
  9306. fprintf(outfile,"%s\n",buf);
  9307. }
  9308. else
  9309. {
  9310. fprintf(outfile,"%s\n",buf);
  9311. }
  9312. }
  9313. else if(tempstackLevelInt < stackLevelInt)
  9314. {
  9315. if(ChargingProfileAdded == FALSE)
  9316. {
  9317. fprintf(outfile,"%s\n",payload);
  9318. ChargingProfileAdded = TRUE;
  9319. fprintf(outfile,"%s\n",buf);
  9320. }
  9321. else
  9322. {
  9323. fprintf(outfile,"%s\n",buf);
  9324. }
  9325. }
  9326. else
  9327. {
  9328. if(ChargingProfileAdded == FALSE)
  9329. {
  9330. fprintf(outfile,"%s\n",buf);
  9331. fprintf(outfile,"%s\n",payload);
  9332. ChargingProfileAdded = TRUE;
  9333. }
  9334. else
  9335. {
  9336. fprintf(outfile,"%s\n",buf);
  9337. }
  9338. }
  9339. }
  9340. } // end of while loop
  9341. fclose(infile);
  9342. fclose(outfile);
  9343. sprintf(rmFileCmd,"rm -f %s",filename);
  9344. system(rmFileCmd);
  9345. rename(tempfile, filename);
  9346. sleep(1);
  9347. result = TRUE;
  9348. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9349. }
  9350. end:
  9351. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9352. return result;
  9353. return result;
  9354. }
  9355. int handleTriggerMessageRequest(char *uuid, char *payload)
  9356. {
  9357. mtrace();
  9358. int result = FAIL;
  9359. int connectorIdIsNULL = FALSE;
  9360. int connectorIdInt =0;
  9361. char sstr[40]={0},sstrtemp[100]={ 0 };
  9362. char requestedMessagestr[40]={0};
  9363. char comfirmstr[20]={0};
  9364. int c = 0;
  9365. char *loc;
  9366. DEBUG_INFO("handleTriggerMessageRequest\n");
  9367. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9368. strcpy(sstrtemp, stringtrimspace(payload));
  9369. c = 0;
  9370. loc = strstr(sstrtemp, "requestedMessage");
  9371. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9372. {
  9373. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9374. c++;
  9375. }
  9376. sstr[c] = '\0';
  9377. strcpy(requestedMessagestr, sstr);
  9378. c = 0;
  9379. loc = strstr(sstrtemp, "connectorId");
  9380. if(loc == NULL)
  9381. {
  9382. connectorIdIsNULL = TRUE;
  9383. }
  9384. else
  9385. {
  9386. memset(sstr ,0, sizeof(sstr) );
  9387. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9388. {
  9389. sstr[c] = loc[strlen("connectorId")+2+c];
  9390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9391. c++;
  9392. }
  9393. sstr[c] = '\0';
  9394. connectorIdInt = atoi(sstr);
  9395. }
  9396. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9397. {
  9398. //connectorIdInt = json_object_get_int(connectorId);
  9399. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9400. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9401. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9402. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9403. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9404. }
  9405. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9406. {
  9407. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9408. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9409. return TRUE;
  9410. }
  9411. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9412. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9413. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9414. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9415. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9416. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9417. {
  9418. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9419. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9420. return TRUE;
  9421. }
  9422. else
  9423. {
  9424. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9425. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9426. }
  9427. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9428. {
  9429. if((FirmwareStatusNotificationStatus != 2) && (FirmwareStatusNotificationStatus != 3) && (FirmwareStatusNotificationStatus != 5) )
  9430. {
  9431. FirmwareStatusNotificationStatus = 3;
  9432. }
  9433. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9434. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9435. }
  9436. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9437. {
  9438. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9439. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9440. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9441. }
  9442. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9443. {
  9444. sendBootNotificationRequest();
  9445. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9446. }
  9447. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9448. {
  9449. sendHeartbeatRequest(connectorIdInt);
  9450. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9451. }
  9452. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9453. {
  9454. if(connectorIdIsNULL == FALSE)
  9455. {
  9456. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9457. {
  9458. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9459. sendMeterValuesRequest(connectorIdInt -1);
  9460. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9461. }
  9462. }
  9463. else
  9464. {
  9465. for(int idx=0;idx< gunTotalNumber;idx++)
  9466. {
  9467. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9468. sendMeterValuesRequest(idx);
  9469. }
  9470. }
  9471. }
  9472. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9473. {
  9474. if(connectorIdIsNULL == FALSE)
  9475. {
  9476. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9477. {
  9478. sendStatusNotificationRequest(connectorIdInt -1);
  9479. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9480. }
  9481. }
  9482. else
  9483. {
  9484. for(int idx=0;idx< gunTotalNumber;idx++)
  9485. sendStatusNotificationRequest(idx);
  9486. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9487. }
  9488. }
  9489. return result;
  9490. }
  9491. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9492. {
  9493. mtrace();
  9494. int result = FAIL;
  9495. char sstr[6]={0},sstrtemp[50]={ 0 };
  9496. int connectorIdInt =0;
  9497. char comfirmstr[20]={0};
  9498. int c = 0;
  9499. int tempIndex = 0;
  9500. char *loc;
  9501. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9502. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9503. strcpy(sstrtemp, stringtrimspace(payload));
  9504. c = 0;
  9505. loc = strstr(sstrtemp, "connectorId");
  9506. memset(sstr ,0, sizeof(sstr) );
  9507. while (loc[strlen("connectorId")+2+c] != '}')
  9508. {
  9509. sstr[c] = loc[strlen("connectorId")+2+c];
  9510. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9511. c++;
  9512. }
  9513. sstr[c] = '\0';
  9514. connectorIdInt = atoi(sstr);
  9515. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9516. if(gunTotalNumber == 0)
  9517. {
  9518. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9519. goto end;
  9520. }
  9521. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9522. {
  9523. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9524. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9525. goto end;
  9526. }
  9527. else
  9528. {
  9529. //check Transaction active
  9530. if(gunType[connectorIdInt-1] == 'J')
  9531. {
  9532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9533. {
  9534. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9535. }
  9536. else
  9537. {
  9538. tempIndex = connectorIdInt -1;
  9539. }
  9540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9541. {
  9542. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9543. {
  9544. //stop Transaction
  9545. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9546. }
  9547. }
  9548. }
  9549. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9550. {
  9551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9552. {
  9553. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9554. }
  9555. else
  9556. {
  9557. tempIndex = connectorIdInt -1;
  9558. }
  9559. for (int index = 0; index < CCS_QUANTITY; index++)
  9560. {
  9561. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9562. {
  9563. //stop Transaction
  9564. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9565. }
  9566. }
  9567. }
  9568. else if(gunType[connectorIdInt-1] == 'G')
  9569. {
  9570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9571. {
  9572. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9573. }
  9574. else
  9575. {
  9576. tempIndex = connectorIdInt -1;
  9577. }
  9578. for (int index = 0; index < GB_QUANTITY; index++)
  9579. {
  9580. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9581. {
  9582. //stop Transaction
  9583. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9584. }
  9585. }
  9586. }
  9587. else
  9588. {
  9589. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9590. {
  9591. tempIndex = 2;
  9592. }
  9593. else
  9594. {
  9595. tempIndex = connectorIdInt-1;
  9596. }
  9597. for (int index = 0; index < AC_QUANTITY; index++)
  9598. {
  9599. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9600. {
  9601. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9602. }
  9603. }
  9604. }
  9605. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9606. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9607. result = TRUE;
  9608. return result;
  9609. }
  9610. end:
  9611. //json_object_put(obj); --- remove temporally
  9612. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9613. return result;
  9614. }
  9615. static char UpdateFirmwarepayloadData[300]={0};
  9616. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9617. {
  9618. mtrace();
  9619. int result = FAIL;
  9620. pthread_t t;
  9621. sendUpdateFirmwareConfirmation(uuid);
  9622. memset(UpdateFirmwarepayloadData, 0, 300);
  9623. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9624. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9625. ////pthread_join(t, NULL); //
  9626. //pthread_detach(t);
  9627. //sendUpdateFirmwareConfirmation(uuid);
  9628. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9629. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9630. return result;
  9631. }
  9632. void *UpdateFirmwareProcess(void *data)
  9633. {
  9634. pthread_detach(pthread_self());
  9635. mtrace();
  9636. int retriesInt =0, retryIntervalInt=0;
  9637. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9638. int port=0;
  9639. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9640. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9641. //char comfirmstr[20];
  9642. int isSuccess = 0;
  9643. char ftpbuf[200];
  9644. char temp[100];
  9645. char * pch;
  9646. int retriesISNULL=FALSE;
  9647. int retryInterval=FALSE;
  9648. int c = 0;
  9649. //int i = 0;
  9650. char *loc;
  9651. char sstr[300]={ 0 };
  9652. char str[300]={ 0 };
  9653. //char *str = (char*) data; // ? ?輸入資 ?
  9654. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9655. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9656. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9657. //***************location **************/
  9658. loc = strstr(str, "location");
  9659. memset(sstr ,0, sizeof(sstr) );
  9660. c = 0;
  9661. while (loc[3+strlen("location")+c] != '\"')
  9662. {
  9663. sstr[c] = loc[3+strlen("location")+c];
  9664. c++;
  9665. }
  9666. sstr[c] = '\0';
  9667. strcpy(locationstr, sstr);
  9668. //***************retries**************/
  9669. c = 0;
  9670. loc = strstr(str, "retries");
  9671. if(loc == NULL)
  9672. {
  9673. retriesISNULL=TRUE;
  9674. }
  9675. else
  9676. {
  9677. memset(sstr ,0, sizeof(sstr) );
  9678. while (loc[strlen("retries")+2+c] != ',')
  9679. {
  9680. sstr[c] = loc[strlen("retries")+2+c];
  9681. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9682. c++;
  9683. }
  9684. sstr[c] = '\0';
  9685. }
  9686. if(retriesISNULL == FALSE)
  9687. {
  9688. retriesInt = atoi(sstr);
  9689. }
  9690. //***************retrieveDate **************/
  9691. loc = strstr(str, "retrieveDate");
  9692. memset(sstr ,0, sizeof(sstr) );
  9693. c = 0;
  9694. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9695. {
  9696. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9697. c++;
  9698. }
  9699. sstr[c] = '\0';
  9700. strcpy(retrieveDatestr, sstr);
  9701. //***************retryInterval **************/
  9702. c = 0;
  9703. loc = strstr(str, "retryInterval");
  9704. memset(sstr ,0, sizeof(sstr) );
  9705. if(loc == NULL)
  9706. {
  9707. retryInterval=TRUE;
  9708. }
  9709. else
  9710. {
  9711. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9712. {
  9713. sstr[c] = loc[strlen("retryInterval")+2+c];
  9714. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9715. c++;
  9716. }
  9717. sstr[c] = '\0';
  9718. }
  9719. if(retryInterval==FALSE)
  9720. {
  9721. retryIntervalInt = atoi(sstr);
  9722. }
  9723. memset(ftppath, 0, sizeof(ftppath));
  9724. memset(path, 0, sizeof(path));
  9725. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9726. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9727. if(strncmp(locationstr,"http", 4) == 0)
  9728. {
  9729. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9730. protocol, host, path);
  9731. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9732. // protocol, user, password, host, path);
  9733. sprintf(ftppath,"/%s", path);
  9734. //DEBUG_INFO("protocol =%s\n",protocol);
  9735. //DEBUG_INFO("host =%s\n",host);
  9736. //DEBUG_INFO("path =%s\n",path);
  9737. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9738. int ftppathlen=strlen(ftppath);
  9739. int i=1;
  9740. char filenametemp[50];
  9741. while(i < ftppathlen)
  9742. {
  9743. int len=ftppathlen-i;
  9744. if(ftppath[len]== 47) // '/' ascll code: 47
  9745. {
  9746. DEBUG_INFO("compare '/' all right\n");
  9747. break;
  9748. }
  9749. i=i+1;
  9750. }
  9751. memset(filenametemp, 0, sizeof(filenametemp));
  9752. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9753. filenametemp[i+1] = 0;
  9754. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9755. do{
  9756. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9757. sleep(retryIntervalInt);
  9758. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9759. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9760. if(!isSuccess)
  9761. {
  9762. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9763. }
  9764. else
  9765. {
  9766. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9767. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9768. //isUpdateRequest = TRUE;
  9769. }
  9770. }
  9771. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9772. {
  9773. memset(ftpbuf, 0, sizeof(ftpbuf));
  9774. memset(temp, 0, sizeof(temp));
  9775. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9776. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9777. int ftppathlen=strlen(ftpbuf);
  9778. int i=1;
  9779. char filenametemp[50];
  9780. while(i < ftppathlen)
  9781. {
  9782. int len=ftppathlen-i;
  9783. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9784. {
  9785. DEBUG_INFO(" compare '/' all right\n");
  9786. break;
  9787. }
  9788. i=i+1;
  9789. }
  9790. memset(filenametemp, 0, sizeof(filenametemp));
  9791. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9792. filenametemp[i+1] = 0;
  9793. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9794. pch=strchr(temp,'@');
  9795. if(pch==NULL)
  9796. {
  9797. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9798. protocol, host, &port, path);
  9799. strcpy(user,"anonymous");
  9800. strcpy(password,"");
  9801. }
  9802. else
  9803. {
  9804. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9805. protocol, user, password, host, &port, path);
  9806. }
  9807. sscanf(host,"%[^/]%s",host1, path1);
  9808. sprintf(ftppath,"%s", path1);
  9809. //DEBUG_INFO("protocol =%s\n",protocol);
  9810. //DEBUG_INFO("user =%s\n",user);
  9811. //DEBUG_INFO("password =%s\n",password);
  9812. //DEBUG_INFO("host1 =%s\n",host1);
  9813. //DEBUG_INFO("port =%d\n",port);
  9814. //DEBUG_INFO("path1 =%s\n",path1);
  9815. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9816. //ftpFile(host, user, password, port, ftppath, fname);
  9817. //download firmware pthred
  9818. if(port == 0)
  9819. {
  9820. port = 21;
  9821. }
  9822. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9823. do{
  9824. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9825. sleep(retryIntervalInt);
  9826. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9827. if(!isSuccess)
  9828. {
  9829. //BulldogUtil.sleepMs(interval*1000);
  9830. DEBUG_INFO("Update firmware request and download file fail.\n");
  9831. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9832. }
  9833. else
  9834. {
  9835. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9836. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9837. //isUpdateRequest = TRUE;
  9838. }
  9839. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9840. }
  9841. else
  9842. {
  9843. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9844. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9845. }
  9846. pthread_exit(NULL);
  9847. }
  9848. //==========================================
  9849. // Handle server response routine
  9850. //==========================================
  9851. void handleAuthorizeResponse(char *payload, int gun_index)
  9852. {
  9853. mtrace();
  9854. char expiryDatestr[30]={0};
  9855. char parentIdTagstr[20]={0};
  9856. char statusstr[20]={0};
  9857. char expiryDatestrtemp[30]={0};
  9858. char parentIdTagstrtemp[20]={0};
  9859. char IdTagstrtemp[20]={0};
  9860. char statusstrtemp[20]={0};
  9861. int expiryDateISNULL=FALSE;
  9862. int parentIdTagISNULL=FALSE;
  9863. char sstr[160]={0},sstrtemp[160]={0};
  9864. char* filename = AuthorizationCache_JSON;
  9865. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9866. int c = 0;
  9867. char *loc;
  9868. int resultRename=0;
  9869. int responseIdTagInfoAsZero= 0;
  9870. char rmFileCmd[50]={0};
  9871. DEBUG_INFO("handleAuthorizeResponse ...\n");
  9872. strcpy(sstrtemp, stringtrimspace(payload));
  9873. //***********expiryDate*************/
  9874. loc = strstr(sstrtemp, "expiryDate");
  9875. memset(sstr ,0, sizeof(sstr) );
  9876. c = 0;
  9877. if(loc == NULL)
  9878. {
  9879. expiryDateISNULL = TRUE;
  9880. }
  9881. else
  9882. {
  9883. while ((loc != NULL)&&(loc[3+strlen("expiryDate")+c] != '\"'))
  9884. {
  9885. sstr[c] = loc[3+strlen("expiryDate")+c];
  9886. c++;
  9887. }
  9888. sstr[c] = '\0';
  9889. strcpy(expiryDatestr, sstr);
  9890. }
  9891. //***********parentIdTag*************/
  9892. loc = strstr(sstrtemp, "parentIdTag");
  9893. memset(sstr ,0, sizeof(sstr) );
  9894. c = 0;
  9895. if(loc == NULL)
  9896. {
  9897. parentIdTagISNULL = TRUE;
  9898. }
  9899. else
  9900. {
  9901. while ((loc != NULL)&&(loc[3+strlen("parentIdTag")+c] != '\"'))
  9902. {
  9903. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9904. c++;
  9905. }
  9906. sstr[c] = '\0';
  9907. strcpy(parentIdTagstr, sstr);
  9908. }
  9909. //***********status*************/
  9910. loc = strstr(sstrtemp, "status");
  9911. memset(sstr ,0, sizeof(sstr) );
  9912. c = 0;
  9913. while (loc[3+strlen("status")+c] != '\"')
  9914. {
  9915. sstr[c] = loc[3+strlen("status")+c];
  9916. c++;
  9917. }
  9918. sstr[c] = '\0';
  9919. strcpy(statusstr, sstr);
  9920. if(expiryDateISNULL == FALSE)
  9921. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9922. if(parentIdTagISNULL == FALSE)
  9923. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9924. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9925. //Update idTag information to authorization cache if supproted
  9926. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9927. {
  9928. if((access(filename,F_OK))!=-1)
  9929. {
  9930. printf("AuthorizationCache exist.\n");
  9931. }
  9932. else
  9933. {
  9934. printf("AuthorizationCache not exist\n");
  9935. FILE *log = fopen(filename, "w+");
  9936. if(log == NULL)
  9937. {
  9938. printf("log is NULL\n");
  9939. goto out;
  9940. }
  9941. else
  9942. {
  9943. fclose(log);
  9944. }
  9945. }
  9946. FILE *infile;
  9947. FILE *outfile;
  9948. // open file for writing
  9949. infile = fopen (filename, "r");
  9950. outfile = fopen (tempfile, "w");
  9951. //*检测到文件结束标识返回1,否则返回0。*/
  9952. //DEBUG_INFO("feof(infile) =%d\n",feof(infile));
  9953. int c;
  9954. c = fgetc(infile);
  9955. //DEBUG_INFO("c:%d\n",c);
  9956. rewind(infile);
  9957. if(c == EOF)
  9958. {
  9959. DEBUG_INFO("Orignal File is NULL\n");
  9960. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9961. {
  9962. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9963. }
  9964. else
  9965. {
  9966. strcpy(expiryDatestrtemp, "");
  9967. }
  9968. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9969. {
  9970. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9971. }
  9972. else
  9973. {
  9974. //write Authorize IdTag
  9975. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9976. }
  9977. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9978. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9979. fclose(infile);
  9980. fclose(outfile);
  9981. sprintf(rmFileCmd,"rm -f %s",filename);
  9982. system(rmFileCmd);
  9983. resultRename = rename(tempfile, filename);
  9984. if(resultRename == 0)
  9985. {
  9986. printf("File renamed successfully");
  9987. }
  9988. else
  9989. {
  9990. printf("Error: unable to rename the file");
  9991. }
  9992. }
  9993. else
  9994. {
  9995. char buf[160]={0};
  9996. while (fgets(buf, sizeof(buf), infile) != NULL)
  9997. {
  9998. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9999. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  10000. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  10001. memset(statusstr, 0, sizeof(statusstrtemp));
  10002. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  10003. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  10004. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  10005. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  10006. //------------------IdTag-----------------------
  10007. loc = strstr(buf, "idTag");
  10008. memset(sstr ,0, sizeof(sstr) );
  10009. c = 0;
  10010. while (loc[3+strlen("idTag")+c] != '\"')
  10011. {
  10012. sstr[c] = loc[3+strlen("idTag")+c];
  10013. c++;
  10014. }
  10015. sstr[c] = '\0';
  10016. strcpy(IdTagstrtemp,sstr);
  10017. //*********************expiryDate***************/
  10018. loc = strstr(buf, "expiryDate");
  10019. memset(sstr ,0, sizeof(sstr) );
  10020. c = 0;
  10021. while (loc[3+strlen("expiryDate")+c] != '\"')
  10022. {
  10023. sstr[c] = loc[3+strlen("expiryDate")+c];
  10024. c++;
  10025. }
  10026. sstr[c] = '\0';
  10027. strcpy(expiryDatestr,sstr);
  10028. //*********************parentIdTag***************/
  10029. loc = strstr(buf, "parentIdTag");
  10030. memset(sstr ,0, sizeof(sstr) );
  10031. c = 0;
  10032. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10033. {
  10034. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10035. c++;
  10036. }
  10037. sstr[c] = '\0';
  10038. strcpy(parentIdTagstr,sstr);
  10039. //*********************status***************/
  10040. loc = strstr(buf, "status");
  10041. memset(sstr ,0, sizeof(sstr) );
  10042. c = 0;
  10043. while (loc[3+strlen("status")+c] != '\"')
  10044. {
  10045. sstr[c] = loc[3+strlen("status")+c];
  10046. c++;
  10047. }
  10048. sstr[c] = '\0';
  10049. strcpy(statusstr,sstr);
  10050. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  10051. {
  10052. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  10053. responseIdTagInfoAsZero = 1;
  10054. }
  10055. else
  10056. {
  10057. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  10058. }
  10059. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  10060. {
  10061. //modify item
  10062. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  10063. {
  10064. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  10065. }
  10066. else
  10067. {
  10068. strcpy(expiryDatestrtemp, "");
  10069. }
  10070. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  10071. {
  10072. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  10073. }
  10074. else
  10075. {
  10076. strcpy(parentIdTagstrtemp, parentIdTagstr);
  10077. }
  10078. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  10079. }
  10080. else
  10081. {
  10082. //wrie original item
  10083. strcpy(expiryDatestrtemp, expiryDatestr);
  10084. strcpy(parentIdTagstrtemp, parentIdTagstr);
  10085. strcpy(statusstrtemp, statusstr);
  10086. }
  10087. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  10088. }
  10089. fclose(infile);
  10090. fclose(outfile);
  10091. sprintf(rmFileCmd,"rm -f %s",filename);
  10092. system(rmFileCmd);
  10093. resultRename = rename(tempfile, filename);
  10094. if(resultRename == 0)
  10095. {
  10096. DEBUG_INFO("File renamed successfully");
  10097. }
  10098. else
  10099. {
  10100. DEBUG_INFO("Error: unable to rename the file");
  10101. }
  10102. }
  10103. }
  10104. out:
  10105. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  10106. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  10107. authorizeRetryTimes = 0;
  10108. }
  10109. char * strtrimc( char * s )
  10110. {
  10111. char * p1 = s;
  10112. char * p2 = s;
  10113. while(*p1 != '\0')
  10114. {
  10115. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  10116. {
  10117. if(*p1 != ',')
  10118. {
  10119. p1 ++;
  10120. }
  10121. else
  10122. {
  10123. break;
  10124. }
  10125. }
  10126. if(*p1 != ',')
  10127. {
  10128. * p2 ++ = *p1 ++;
  10129. //printf("p2=%s\n",p2);
  10130. }
  10131. else
  10132. {
  10133. break;
  10134. }
  10135. }
  10136. *p2 = '\0';
  10137. return (s);
  10138. }
  10139. void handleBootNotificationResponse(char *payload, int gun_index)
  10140. {
  10141. mtrace();
  10142. char sstr[140]={0}, sstrtemp[140]={0};//sstr[200]={ 0 };
  10143. char statusStr[12]={0};
  10144. char currentTimeStr[30]={0};
  10145. char *loc;
  10146. int intervalInt = 0;
  10147. int c = 0;
  10148. //double diff_t;
  10149. struct tm tp;
  10150. char buf[28]={0};
  10151. char timebuf[50]={0};
  10152. DEBUG_INFO("handleBootNotificationResponse ...\n");
  10153. //Filter string space
  10154. strcpy(sstrtemp, stringtrimspace(payload));
  10155. //*** interval ****/
  10156. c = 0;
  10157. loc = strstr(sstrtemp, "interval");
  10158. //printf("loc=%s\n",loc);
  10159. memset(sstr ,0, sizeof(sstr) );
  10160. while ((loc != NULL) &&(loc[strlen("interval")+2+c] != ',') &&(loc[strlen("interval")+2+c] != '}') )
  10161. {
  10162. sstr[c] = loc[strlen("interval")+2+c];
  10163. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10164. c++;
  10165. }
  10166. sstr[c] = '\0';
  10167. //DEBUG_INFO("id=%d\n",atoi(sstr));
  10168. intervalInt = atoi(sstr);
  10169. //***status ****/
  10170. loc = strstr(sstrtemp, "status");
  10171. memset(sstr ,0, sizeof(sstr) );
  10172. c = 0;
  10173. while ((loc != NULL) &&(loc[3+strlen("status")+c] != '\"'))
  10174. {
  10175. sstr[c] = loc[3+strlen("status")+c];
  10176. c++;
  10177. }
  10178. sstr[c] = '\0';
  10179. strcpy(statusStr, sstr);
  10180. //***currentTime ****/
  10181. loc = strstr(sstrtemp, "currentTime");
  10182. //printf("loc=%s\n",loc);
  10183. memset(sstr ,0, sizeof(sstr) );
  10184. c = 0;
  10185. while ((loc != NULL) &&(loc[3+strlen("currentTime")+c] != '\"'))
  10186. {
  10187. sstr[c] = loc[3+strlen("currentTime")+c];
  10188. c++;
  10189. }
  10190. sstr[c] = '\0';
  10191. strcpy(currentTimeStr, sstr);
  10192. //BootNotificationInterval = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10193. //HeartBeatWaitTime = BootNotificationInterval;
  10194. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10195. BootNotificationInterval = intervalInt;
  10196. HeartBeatWaitTime = intervalInt;
  10197. clientTime.Heartbeat=time((time_t*)NULL);
  10198. //write back to ShmOCPP16Data->BootNotification
  10199. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  10200. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  10201. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  10202. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 )/* ||
  10203. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Pending]) == 0) ||
  10204. (strcmp(status, RegistrationStatusStr[RegistrationStatus_Rejected]) == 0)*/)
  10205. {
  10206. server_sign = TRUE;
  10207. server_pending =FALSE;
  10208. }
  10209. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  10210. {
  10211. server_pending = TRUE;
  10212. }
  10213. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10214. tp.tm_isdst = -1;
  10215. //time_t utc = mktime(&tp);
  10216. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10217. memset(timebuf, 0, sizeof timebuf);
  10218. sprintf(timebuf,"date -s '%s'",buf);
  10219. //DEBUG_INFO("timebuf=%s\n",timebuf);
  10220. system(timebuf);
  10221. //==============================================
  10222. // RTC sync
  10223. //==============================================
  10224. system("/sbin/hwclock -w --systohc");
  10225. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  10226. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  10227. }
  10228. void handleDataTransferResponse(char *payload, int gun_index)
  10229. {
  10230. char sstr[160]={0};//sstr[200]={ 0 };
  10231. int c = 0;
  10232. char *loc;
  10233. DEBUG_INFO("handleDataTransferResponse ...\n");
  10234. loc = strstr(payload, "status");
  10235. printf("loc=%s\n",loc);
  10236. c = 0;
  10237. while (loc[3+strlen("status")+c] != '\"')
  10238. {
  10239. sstr[c] = loc[3+strlen("status")+c];
  10240. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10241. c++;
  10242. }
  10243. sstr[c] = '\0';
  10244. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  10245. }
  10246. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  10247. {
  10248. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  10249. //struct json_object *obj;
  10250. // obj = json_tokener_parse(payload);
  10251. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  10252. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  10253. //No fields are defined.
  10254. }
  10255. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  10256. {
  10257. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  10258. //struct json_object *obj;
  10259. // obj = json_tokener_parse(payload);
  10260. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  10261. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  10262. //No fields are defined.
  10263. }
  10264. void handleHeartbeatResponse(char *payload, int gun_index)
  10265. {
  10266. mtrace();
  10267. //double diff_t;
  10268. struct tm tp;
  10269. char buf[28]={0};
  10270. char timebuf[50]={0},sstrtemp[100]={0};
  10271. char sstr[30]={ 0 };
  10272. int c = 0;
  10273. char *loc;
  10274. //[3,"9c2e3c41-ab34-409e-8902-f5f48b6de641",{"currentTime":"2018-09-06T02:22:57.171Z"}]
  10275. if(FirstHeartBeat == 0)
  10276. {
  10277. FirstHeartBeat = 1;
  10278. DEBUG_INFO("FirstHeartBeat \n");
  10279. }
  10280. HeartBeatWithNOResponse = 0;
  10281. strcpy(sstrtemp, stringtrimspace(payload));
  10282. c = 0;
  10283. loc = strstr(sstrtemp, "currentTime");
  10284. memset(sstr ,0, sizeof(sstr) );
  10285. while (loc[3+strlen("currentTime")+c] != '\"')
  10286. {
  10287. sstr[c] = loc[3+strlen("currentTime")+c];
  10288. c++;
  10289. }
  10290. sstr[c] = '\0';
  10291. strcpy((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime,sstr);
  10292. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10293. tp.tm_isdst = -1;
  10294. //time_t utc = mktime(&tp);
  10295. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10296. memset(timebuf, 0, sizeof timebuf);
  10297. sprintf(timebuf,"date -s '%s'",buf);
  10298. system(timebuf);
  10299. //==============================================
  10300. // RTC sync
  10301. //==============================================
  10302. system("/sbin/hwclock -w --systohc");
  10303. //===============================================
  10304. //Print Out HeartBeat log
  10305. //===============================================
  10306. {
  10307. double diff_t;
  10308. struct tm tp,tp1;
  10309. // BootNotification Receive Time
  10310. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10311. tp.tm_isdst = -1;
  10312. time_t BootNotificationReceiveTime = mktime(&tp);
  10313. //HeartBeat Receive Time
  10314. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10315. tp1.tm_isdst = -1;
  10316. time_t HeartBeatReceiveTime = mktime(&tp1);
  10317. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10318. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10319. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10320. {
  10321. HeartBeatCountPerHour = (int)diff_t / 3600;
  10322. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10323. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10324. }
  10325. }
  10326. }
  10327. void handleMeterValuesResponse(char *payload, int gun_index)
  10328. {
  10329. mtrace();
  10330. //struct json_object *obj;
  10331. DEBUG_INFO("handleMeterValuesResponse ...\n");
  10332. //No fields are defined.
  10333. }
  10334. void handleStartTransactionResponse(char *payload, int gun_index)
  10335. {
  10336. mtrace();
  10337. char sstr[28]={ 0 },sstrtemp[200]={ 0 };
  10338. int c = 0;
  10339. int copyTo = 0;
  10340. char *loc;
  10341. //int transactionIdInt = 0;
  10342. FILE *outfile;
  10343. char data[100]={0};
  10344. //char *delim = ":";
  10345. //char requestKey[2][50]={0};
  10346. //char * pch;
  10347. //[3,"f7da35db-9d9b-4362-841f-26424be1064f",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"},"transactionId":2146754131}]
  10348. DEBUG_INFO("handleStartTransactionResponse\n");
  10349. //****************expiryDate********************/
  10350. strcpy(sstrtemp, stringtrimspace(payload));
  10351. loc = strstr(sstrtemp, "expiryDate");
  10352. if(loc == NULL)
  10353. {
  10354. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  10355. }
  10356. else
  10357. {
  10358. #if 0
  10359. c = 0;
  10360. memset(sstr ,0, sizeof(sstr) );
  10361. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10362. memset(requestKey ,0, sizeof(requestKey) );
  10363. strcpy(sstrtemp,loc+strlen("expiryDate")+2); // 2: ":
  10364. //printf("sstrtemp=%s\n",sstrtemp);
  10365. //parsing strings to words
  10366. pch = strtok(sstrtemp,",");
  10367. while (pch != NULL)
  10368. {
  10369. strcpy(requestKey[c], pch);
  10370. pch = strtok (NULL, ",");
  10371. c = c + 1;
  10372. }
  10373. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10374. //strcpy(currentTimeStr, strtrimc(requestKey[0]));
  10375. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", stringtrim(requestKey[0]));
  10376. #endif
  10377. #if 1
  10378. c = 0;
  10379. memset(sstr ,0, sizeof(sstr) );
  10380. while (loc[3+strlen("expiryDate")+c] != '\"')
  10381. {
  10382. sstr[c] = loc[3+strlen("expiryDate")+c];
  10383. c++;
  10384. }
  10385. sstr[c] = '\0';
  10386. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10387. #endif
  10388. }
  10389. //****************parentIdTag********************/
  10390. loc = strstr(sstrtemp, "parentIdTag");
  10391. if(loc == NULL)
  10392. {
  10393. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  10394. }
  10395. else
  10396. {
  10397. #if 0
  10398. c = 0;
  10399. memset(sstr ,0, sizeof(sstr) );
  10400. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10401. memset(requestKey ,0, sizeof(requestKey) );
  10402. strcpy(sstrtemp,loc);
  10403. //printf("sstrtemp=%s\n",sstrtemp);
  10404. //parsing strings to words
  10405. pch = strtok(sstrtemp,delim);
  10406. while (pch != NULL)
  10407. {
  10408. strcpy(requestKey[c], pch);
  10409. pch = strtok (NULL, delim);
  10410. c = c + 1;
  10411. }
  10412. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10413. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", strtrimc(requestKey[1]));
  10414. #endif
  10415. #if 1
  10416. c = 0;
  10417. memset(sstr ,0, sizeof(sstr) );
  10418. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10419. {
  10420. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10421. c++;
  10422. }
  10423. sstr[c] = '\0';
  10424. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10425. #endif
  10426. }
  10427. //****************status********************/
  10428. loc = strstr(sstrtemp, "status");
  10429. if(loc == NULL)
  10430. {
  10431. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  10432. }
  10433. else
  10434. {
  10435. #if 0
  10436. c = 0;
  10437. memset(sstr ,0, sizeof(sstr) );
  10438. memset(sstrtemp ,0, sizeof(sstrtemp) );
  10439. memset(requestKey ,0, sizeof(requestKey) );
  10440. strcpy(sstrtemp,loc);
  10441. //printf("sstrtemp=%s\n",sstrtemp);
  10442. //parsing strings to words
  10443. pch = strtok(sstrtemp,delim);
  10444. while (pch != NULL)
  10445. {
  10446. strcpy(requestKey[c], pch);
  10447. pch = strtok (NULL, delim);
  10448. c = c + 1;
  10449. }
  10450. //printf("strtrimc=%s\n",strtrimc(requestKey[1]));
  10451. //strcpy(statusStr, strtrimc(requestKey[1]));
  10452. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", strtrimc(requestKey[1]));
  10453. #endif
  10454. #if 1
  10455. c = 0;
  10456. memset(sstr ,0, sizeof(sstr) );
  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->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10464. #endif
  10465. }
  10466. //****************transactionId********************/
  10467. c=0;
  10468. copyTo = 0;
  10469. loc = strstr(sstrtemp, "transactionId");
  10470. memset(sstr ,0, sizeof(sstr) );
  10471. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  10472. {
  10473. if(loc[strlen("transactionId")+2+c] != ' ')
  10474. {
  10475. sstr[copyTo] = loc[strlen("transactionId")+2+c];
  10476. copyTo = copyTo + 1;
  10477. }
  10478. c++;
  10479. }
  10480. sstr[copyTo] = '\0';
  10481. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = atoi(sstr);
  10482. //transactionIdInt = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  10483. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10484. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10485. //-----------Start : write to the Queue TransactionId file -----------------//
  10486. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10487. {
  10488. //DEBUG_INFO("QueueTransactionId exist.\n");
  10489. }
  10490. else
  10491. {
  10492. //DEBUG_INFO("QueueTransactionId not exist\n");
  10493. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10494. if(log == NULL)
  10495. {
  10496. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10497. return ;
  10498. }
  10499. else
  10500. {
  10501. fclose(log);
  10502. }
  10503. }
  10504. // open file for writing
  10505. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10506. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10507. {
  10508. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10509. //DEBUG_INFO("data=%s\n",data);
  10510. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10511. fputs(data, outfile);
  10512. //fputs("\n", outfile);
  10513. fclose (outfile);
  10514. }
  10515. //-------------End: write to the Queue TransactionId file------------------------------------------//
  10516. //TransactionId[gun_index] = transactionIdInt;
  10517. //DEBUG_INFO("gun_index: %d\n", gun_index);
  10518. //DEBUG_INFO("test TransactionId[gun_index]: %d\n", TransactionId[gun_index]);
  10519. #ifdef SystemLogMessage
  10520. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10521. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10522. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10523. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10524. #endif
  10525. }
  10526. void handleStatusNotificationResponse(char *payload, int gun_index)
  10527. {
  10528. mtrace();
  10529. printf("handleStatusNotificationResponse\n");
  10530. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10531. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10532. }
  10533. void handleStopTransactionnResponse(char *payload, int gun_index)
  10534. {
  10535. mtrace();
  10536. char sstr[30]={ 0 },sstrtemp[140]={ 0 };
  10537. int c = 0;
  10538. char *loc;
  10539. //char *delim = ":";
  10540. //char requestKey[3][50]={0};
  10541. //char * pch;
  10542. //[3,"e79c0728-dd4c-4038-a90e-bb0eb23e1ee0",{"idTagInfo":{"expiryDate":"2020-06-19T01:10:00.000Z","parentIdTag":"1UF1YvGvmNbLF17sP6LY","status":"Accepted"}}]
  10543. strcpy(sstrtemp, stringtrimspace(payload));
  10544. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10545. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10546. loc = strstr(sstrtemp, "idTagInfo");
  10547. //***********************idTagInfo************************/
  10548. if(loc != NULL)
  10549. {
  10550. //***********************expiryDate************************/
  10551. loc = strstr(sstrtemp, "expiryDate");
  10552. if(loc != NULL)
  10553. {
  10554. memset(sstr ,0, sizeof(sstr) );
  10555. c = 0;
  10556. while (loc[3+strlen("expiryDate")+c] != '\"')
  10557. {
  10558. sstr[c] = loc[3+strlen("expiryDate")+c];
  10559. c++;
  10560. }
  10561. sstr[c] = '\0';
  10562. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", sstr);
  10563. }
  10564. //***********************parentIdTag************************/
  10565. loc = strstr(sstrtemp, "parentIdTag");
  10566. if(loc != NULL)
  10567. {
  10568. memset(sstr ,0, sizeof(sstr) );
  10569. c = 0;
  10570. while (loc[3+strlen("parentIdTag")+c] != '\"')
  10571. {
  10572. sstr[c] = loc[3+strlen("parentIdTag")+c];
  10573. c++;
  10574. }
  10575. sstr[c] = '\0';
  10576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", sstr);
  10577. }
  10578. //***********************status************************/
  10579. loc = strstr(sstrtemp, "status");
  10580. memset(sstr ,0, sizeof(sstr) );
  10581. c = 0;
  10582. while (loc[3+strlen("status")+c] != '\"')
  10583. {
  10584. sstr[c] = loc[3+strlen("status")+c];
  10585. c++;
  10586. }
  10587. sstr[c] = '\0';
  10588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", sstr);
  10589. }
  10590. #ifdef SystemLogMessage
  10591. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10592. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10593. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10594. #endif
  10595. }
  10596. //==========================================
  10597. // Handle Error routine
  10598. //==========================================
  10599. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10600. {
  10601. mtrace();
  10602. #ifdef SystemLogMessage
  10603. DEBUG_INFO("errorCode: %s\n", errorCode);
  10604. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10605. DEBUG_INFO("errorDetails: %s\n", payload);
  10606. #endif
  10607. }
  10608. //===============================================
  10609. // Common routine
  10610. //===============================================
  10611. int initialConfigurationTable(void)
  10612. {
  10613. //clock_t start_t, end_t, total_t;
  10614. FILE *fp;
  10615. FILE *outfile;
  10616. char str[200]={0};
  10617. char sstr[100]={0};
  10618. int c = 0;
  10619. char *loc;
  10620. printf("initialConfigurationTable \n");
  10621. //start_t = clock();
  10622. //printf("Starting of the program, start_t = %ld\n", start_t);
  10623. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10624. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10625. {
  10626. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10627. if(outfile == NULL) {
  10628. DEBUG_INFO("Error opening file");
  10629. return FALSE;
  10630. }
  10631. /*Core Profile*/
  10632. //AllowOfflineTxForUnknownId
  10633. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10634. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10635. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10636. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10638. //AuthorizationCacheEnabled
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10643. //AuthorizeRemoteTxRequests
  10644. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10648. //BlinkRepeat
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10652. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10653. //ClockAlignedDataInterval
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10658. //ConnectionTimeOut
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10662. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10663. //GetConfigurationMaxKeys
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10668. // HeartbeatInterval
  10669. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10673. // LightIntensity
  10674. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10678. // LocalAuthorizeOffline
  10679. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10682. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10683. // LocalPreAuthorize
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10687. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10688. // MaxEnergyOnInvalidId
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10692. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10694. // MeterValuesAlignedData
  10695. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "" );
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "");
  10699. // MeterValuesAlignedDataMaxLength
  10700. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10701. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10703. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10704. // MeterValuesSampledData
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10708. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10709. // MeterValuesSampledDataMaxLength
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10713. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10714. // MeterValueSampleInterval
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10718. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10719. // MinimumStatusDuration
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10723. server_cycle_Status = 120; //StatusNotification cycle
  10724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10725. // NumberOfConnectors
  10726. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10729. {
  10730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10731. }
  10732. else
  10733. {
  10734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10735. }
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10737. // ResetRetries
  10738. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10741. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10742. // ConnectorPhaseRotation
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10746. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10747. // ConnectorPhaseRotationMaxLength
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10751. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10752. // StopTransactionOnEVSideDisconnect
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10756. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10757. // StopTransactionOnInvalidId
  10758. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10762. // StopTxnAlignedData
  10763. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10767. // StopTxnAlignedDataMaxLength
  10768. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10769. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10772. // StopTxnSampledData
  10773. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10777. // StopTxnSampledDataMaxLength
  10778. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10781. {
  10782. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10783. }
  10784. else
  10785. {
  10786. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10787. }
  10788. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10790. // SupportedFeatureProfiles
  10791. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10795. // SupportedFeatureProfilesMaxLength
  10796. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10800. // TransactionMessageAttempts
  10801. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10804. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10806. // TransactionMessageRetryInterval
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10810. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10812. // UnlockConnectorOnEVSideDisconnect
  10813. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10817. // WebSocketPingInterval
  10818. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10822. //* Local Auth List Management Profile*/
  10823. #if 0
  10824. //For OCTT Test Case
  10825. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10828. #endif
  10829. #if 1
  10830. //LocalAuthListEnabled
  10831. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10835. #endif
  10836. //LocalAuthListMaxLength
  10837. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10840. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10841. //SendLocalListMaxLength
  10842. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10846. //ReserveConnectorZeroSupported
  10847. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10851. //* Smart Charging Profile */
  10852. //ChargeProfileMaxStackLevel
  10853. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10856. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10857. // ChargingScheduleAllowedChargingRateUnit
  10858. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10862. // ChargingScheduleMaxPeriods
  10863. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10866. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10867. // ConnectorSwitch3to1PhaseSupported
  10868. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10872. // MaxChargingProfilesInstalled
  10873. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10877. fclose(outfile);
  10878. }
  10879. else
  10880. {
  10881. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10882. char keystr[60]={0};
  10883. char readonlystr[10]={0};
  10884. char valuestr[100]={0};
  10885. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10886. if(fp == NULL) {
  10887. DEBUG_INFO("Error opening file");
  10888. return FALSE;
  10889. }
  10890. while( fgets (str, sizeof(str), fp)!=NULL )
  10891. {
  10892. //DEBUG_INFO("Get Configuration \n");
  10893. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10894. //*************************key*********************************/
  10895. loc = strstr(str, "key");
  10896. c = 0;
  10897. memset(sstr ,0, sizeof(sstr) );
  10898. while (loc[strlen("key")+3+c] != '\"')
  10899. {
  10900. sstr[c] = loc[strlen("key")+3+c];
  10901. c++;
  10902. }
  10903. sstr[c] = '\0';
  10904. strcpy(keystr,sstr);
  10905. //*************************readonly*********************************/
  10906. loc = strstr(str, "readonly");
  10907. c = 0;
  10908. memset(sstr ,0, sizeof(sstr) );
  10909. while (loc[strlen("readonly")+2+c] != ',')
  10910. {
  10911. sstr[c] = loc[strlen("readonly")+2+c];
  10912. c++;
  10913. }
  10914. sstr[c] = '\0';
  10915. strcpy(readonlystr,sstr);
  10916. //*************************value*********************************/
  10917. loc = strstr(str, "value");
  10918. c = 0;
  10919. memset(sstr ,0, sizeof(sstr) );
  10920. while (loc[strlen("value")+3+c] != '\"')
  10921. {
  10922. sstr[c] = loc[strlen("value")+3+c];
  10923. c++;
  10924. }
  10925. sstr[c] = '\0';
  10926. strcpy(valuestr,sstr);
  10927. // DEBUG_INFO("keystr=%s\n",keystr);
  10928. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10929. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10930. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10931. {
  10932. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10934. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10935. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10936. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10937. }
  10938. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10939. {
  10940. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10941. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10942. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10943. }
  10944. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10945. {
  10946. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10947. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10948. }
  10949. if(strcmp(keystr, "BlinkRepeat") == 0)
  10950. {
  10951. //Charger.BlinkRepeat = Integer.parseInt(value);
  10952. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10954. }
  10955. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10956. {
  10957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10958. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10959. }
  10960. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10961. {
  10962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10964. }
  10965. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10966. {
  10967. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10969. }
  10970. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10971. {
  10972. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10973. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10974. HeartBeatWaitTime = atoi(valuestr);
  10975. }
  10976. if(strcmp(keystr, "LightIntensity") == 0)
  10977. {
  10978. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10979. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10980. }
  10981. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10982. {
  10983. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10984. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10985. }
  10986. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10987. {
  10988. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10989. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10990. }
  10991. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10992. {
  10993. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10995. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10996. }
  10997. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10998. {
  10999. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11000. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  11001. }
  11002. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  11003. {
  11004. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11005. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  11006. }
  11007. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  11008. {
  11009. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11010. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  11011. }
  11012. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  11013. {
  11014. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11015. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  11016. }
  11017. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  11018. {
  11019. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11020. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  11021. }
  11022. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  11023. {
  11024. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  11026. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  11027. }
  11028. if(strcmp(keystr, "NumberOfConnectors") == 0)
  11029. {
  11030. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  11032. }
  11033. if(strcmp(keystr, "ResetRetries") == 0)
  11034. {
  11035. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  11037. }
  11038. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  11039. {
  11040. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  11042. }
  11043. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  11044. {
  11045. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  11047. }
  11048. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  11049. {
  11050. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  11052. }
  11053. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  11054. {
  11055. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  11057. }
  11058. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  11059. {
  11060. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  11062. }
  11063. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  11064. {
  11065. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11067. }
  11068. if(strcmp(keystr, "StopTxnSampledData") == 0)
  11069. {
  11070. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11071. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  11072. }
  11073. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  11074. {
  11075. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11076. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  11077. }
  11078. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  11079. {
  11080. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  11082. }
  11083. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  11084. {
  11085. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11086. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  11087. }
  11088. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  11089. {
  11090. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11091. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  11092. TransactionMessageAttemptsValue = atoi(valuestr);
  11093. }
  11094. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  11095. {
  11096. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11097. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  11098. TransactionMessageRetryIntervalValue = atoi(valuestr);
  11099. }
  11100. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  11101. {
  11102. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11103. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  11104. }
  11105. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  11106. {
  11107. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11108. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  11109. }
  11110. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  11111. {
  11112. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11113. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  11114. }
  11115. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  11116. {
  11117. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11118. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  11119. }
  11120. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  11121. {
  11122. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11123. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  11124. }
  11125. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  11126. {
  11127. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11128. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  11129. }
  11130. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  11131. {
  11132. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11133. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  11134. }
  11135. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  11136. {
  11137. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11138. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  11139. }
  11140. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  11141. {
  11142. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  11144. }
  11145. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  11146. {
  11147. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11148. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  11149. }
  11150. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  11151. {
  11152. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  11153. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  11154. }
  11155. }
  11156. fclose(fp);
  11157. }
  11158. //end_t = clock();
  11159. //printf("End of the big loop, end_t = %ld\n", end_t);
  11160. //total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
  11161. //printf("Total time taken by CPU: %f\n", total_t );
  11162. return 0;
  11163. }
  11164. void StoreConfigurationTable(void)
  11165. {
  11166. FILE *outfile;
  11167. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  11168. if(outfile == NULL)
  11169. {
  11170. DEBUG_INFO("Error opening file");
  11171. return ;
  11172. }
  11173. /*Core Profile*/
  11174. //AllowOfflineTxForUnknownId
  11175. /*
  11176. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  11177. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  11178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  11179. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  11180. */
  11181. //DEBUG_INFO("data=%s\n",data);
  11182. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  11183. //AuthorizationCacheEnabled
  11184. /*
  11185. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  11186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  11187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  11188. */
  11189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  11190. //AuthorizeRemoteTxRequests
  11191. /*
  11192. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  11193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  11194. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  11195. */
  11196. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  11197. //BlinkRepeat
  11198. /*
  11199. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  11200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  11201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  11202. */
  11203. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  11204. //ClockAlignedDataInterval
  11205. /*
  11206. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  11207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  11208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  11209. */
  11210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  11211. //ConnectionTimeOut
  11212. /*
  11213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  11214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  11215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  11216. */
  11217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  11218. //GetConfigurationMaxKeys
  11219. /*
  11220. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  11221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  11222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  11223. */
  11224. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  11225. // HeartbeatInterval
  11226. /*
  11227. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  11228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  11229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  11230. */
  11231. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  11232. // LightIntensity
  11233. /*
  11234. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  11235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  11236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  11237. */
  11238. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  11239. // LocalAuthorizeOffline
  11240. /*
  11241. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  11242. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  11243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  11244. */
  11245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11246. // LocalPreAuthorize
  11247. /*
  11248. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  11249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  11250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  11251. */
  11252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  11253. // MaxEnergyOnInvalidId
  11254. /*
  11255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  11256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  11257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  11258. */
  11259. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  11260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  11261. // MeterValuesAlignedData
  11262. /*
  11263. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  11264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  11265. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11266. */
  11267. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  11268. // MeterValuesAlignedDataMaxLength
  11269. /*
  11270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  11271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  11272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  11273. */
  11274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  11275. // MeterValuesSampledData
  11276. /*
  11277. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  11278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  11279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  11280. */
  11281. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  11282. // MeterValuesSampledDataMaxLength
  11283. /*
  11284. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  11285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  11286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  11287. */
  11288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  11289. // MeterValueSampleInterval
  11290. /*
  11291. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  11292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  11293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  11294. */
  11295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  11296. // MinimumStatusDuration
  11297. /*
  11298. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  11299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  11300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  11301. */
  11302. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  11303. // NumberOfConnectors
  11304. /*
  11305. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  11306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  11307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11308. {
  11309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  11310. }
  11311. else
  11312. {
  11313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  11314. }
  11315. */
  11316. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  11317. // ResetRetries
  11318. /*
  11319. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  11320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  11321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  11322. */
  11323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  11324. // ConnectorPhaseRotation
  11325. /*
  11326. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  11327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  11328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  11329. */
  11330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  11331. // ConnectorPhaseRotationMaxLength
  11332. /*
  11333. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  11334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  11335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  11336. */
  11337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  11338. // StopTransactionOnEVSideDisconnect
  11339. /*
  11340. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  11341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  11342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  11343. */
  11344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  11345. // StopTransactionOnInvalidId
  11346. /*
  11347. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  11348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  11349. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  11350. */
  11351. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  11352. // StopTxnAlignedData
  11353. /*
  11354. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  11355. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  11356. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  11357. */
  11358. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  11359. // StopTxnAlignedDataMaxLength
  11360. /*
  11361. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  11362. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  11363. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  11364. */
  11365. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  11366. // StopTxnSampledData
  11367. /*
  11368. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  11369. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  11370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  11371. */
  11372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  11373. // StopTxnSampledDataMaxLength
  11374. /*
  11375. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  11376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  11377. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  11378. */
  11379. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  11380. // SupportedFeatureProfiles
  11381. /*
  11382. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  11383. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  11384. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  11385. */
  11386. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  11387. // SupportedFeatureProfilesMaxLength
  11388. /*
  11389. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  11390. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  11391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  11392. */
  11393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  11394. // TransactionMessageAttempts
  11395. /*
  11396. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  11397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  11398. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  11399. */
  11400. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  11401. // TransactionMessageRetryInterval
  11402. /*
  11403. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  11404. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  11405. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  11406. */
  11407. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  11408. // UnlockConnectorOnEVSideDisconnect
  11409. /*
  11410. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  11411. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  11412. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  11413. */
  11414. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  11415. // WebSocketPingInterval
  11416. /*
  11417. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  11418. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  11419. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  11420. */
  11421. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  11422. //* Local Auth List Management Profile*/
  11423. //LocalAuthListEnabled
  11424. /*
  11425. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  11426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  11427. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  11428. */
  11429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  11430. //LocalAuthListMaxLength
  11431. /*
  11432. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  11433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  11434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  11435. */
  11436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  11437. //SendLocalListMaxLength
  11438. /*
  11439. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  11440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  11441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  11442. */
  11443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  11444. //ReserveConnectorZeroSupported
  11445. /*
  11446. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  11447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  11448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11449. */
  11450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11451. //* Smart Charging Profile */
  11452. //ChargeProfileMaxStackLevel
  11453. /*
  11454. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11457. */
  11458. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11459. // ChargingScheduleAllowedChargingRateUnit
  11460. /*
  11461. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11464. */
  11465. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11466. // ChargingScheduleMaxPeriods
  11467. /*
  11468. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11471. */
  11472. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11473. // ConnectorSwitch3to1PhaseSupported
  11474. /*
  11475. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11478. */
  11479. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11480. // MaxChargingProfilesInstalled
  11481. /*
  11482. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11485. */
  11486. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11487. fclose(outfile);
  11488. }
  11489. void getKeyValue(char *keyReq)
  11490. {
  11491. int isEmpty = FALSE;
  11492. int isKnowKey = FALSE;
  11493. //int unKnowIndex = 0;
  11494. DEBUG_INFO("getKeyValue \n");
  11495. DEBUG_INFO("keyReq=%s \n",keyReq);
  11496. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11497. isEmpty = TRUE;
  11498. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11580. }
  11581. else
  11582. {
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11584. }
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11586. isKnowKey = TRUE;
  11587. }
  11588. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11595. }
  11596. else
  11597. {
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11599. }
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11601. isKnowKey = TRUE;
  11602. }
  11603. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11604. {
  11605. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11607. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11608. {
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11610. }
  11611. else
  11612. {
  11613. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11614. }
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11616. isKnowKey = TRUE;
  11617. }
  11618. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11619. {
  11620. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11622. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11623. {
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11625. }
  11626. else
  11627. {
  11628. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11629. }
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11631. isKnowKey = TRUE;
  11632. }
  11633. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11634. {
  11635. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11637. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11638. {
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11640. }
  11641. else
  11642. {
  11643. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11644. }
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11646. isKnowKey = TRUE;
  11647. }
  11648. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11649. {
  11650. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11651. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11652. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11653. {
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11655. }
  11656. else
  11657. {
  11658. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11659. }
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11661. isKnowKey = TRUE;
  11662. }
  11663. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11664. {
  11665. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11666. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11667. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11668. {
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11670. }
  11671. else
  11672. {
  11673. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11674. }
  11675. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11676. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11677. isKnowKey = TRUE;
  11678. }
  11679. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11680. {
  11681. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11682. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11684. {
  11685. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11686. }
  11687. else
  11688. {
  11689. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11690. }
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11692. isKnowKey = TRUE;
  11693. }
  11694. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11695. {
  11696. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11697. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11698. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11699. {
  11700. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11701. }
  11702. else
  11703. {
  11704. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11705. }
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11707. isKnowKey = TRUE;
  11708. }
  11709. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11710. {
  11711. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11712. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11713. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11714. {
  11715. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11716. }
  11717. else
  11718. {
  11719. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11720. }
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11722. isKnowKey = TRUE;
  11723. }
  11724. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11725. {
  11726. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11727. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11729. {
  11730. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11731. }
  11732. else
  11733. {
  11734. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11735. }
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11737. isKnowKey = TRUE;
  11738. }
  11739. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11740. {
  11741. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11742. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11744. {
  11745. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11746. }
  11747. else
  11748. {
  11749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11750. }
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11752. isKnowKey = TRUE;
  11753. }
  11754. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11755. {
  11756. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11757. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11758. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11759. {
  11760. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11761. }
  11762. else
  11763. {
  11764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11765. }
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11767. isKnowKey = TRUE;
  11768. }
  11769. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11770. {
  11771. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11772. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11774. {
  11775. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11776. }
  11777. else
  11778. {
  11779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11780. }
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11782. isKnowKey = TRUE;
  11783. }
  11784. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11785. {
  11786. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11787. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11789. {
  11790. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11791. }
  11792. else
  11793. {
  11794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11795. }
  11796. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11797. isKnowKey = TRUE;
  11798. }
  11799. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11800. {
  11801. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11802. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11803. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11804. {
  11805. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11806. }
  11807. else
  11808. {
  11809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11810. }
  11811. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11812. isKnowKey = TRUE;
  11813. }
  11814. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11815. {
  11816. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11817. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11819. {
  11820. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11821. }
  11822. else
  11823. {
  11824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11825. }
  11826. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11827. isKnowKey = TRUE;
  11828. }
  11829. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11830. {
  11831. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11832. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11833. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11834. {
  11835. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11836. }
  11837. else
  11838. {
  11839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11840. }
  11841. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11842. isKnowKey = TRUE;
  11843. }
  11844. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11845. {
  11846. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11847. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11848. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11849. {
  11850. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11851. }
  11852. else
  11853. {
  11854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11855. }
  11856. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11857. isKnowKey = TRUE;
  11858. }
  11859. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11860. {
  11861. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11862. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11863. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11864. {
  11865. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11866. }
  11867. else
  11868. {
  11869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11870. }
  11871. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11872. isKnowKey = TRUE;
  11873. }
  11874. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11875. {
  11876. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11877. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11878. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11879. {
  11880. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11881. }
  11882. else
  11883. {
  11884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11885. }
  11886. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11887. isKnowKey = TRUE;
  11888. }
  11889. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11890. {
  11891. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11892. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11893. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11894. {
  11895. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11896. }
  11897. else
  11898. {
  11899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11900. }
  11901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11902. isKnowKey = TRUE;
  11903. }
  11904. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11905. {
  11906. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11907. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11908. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11909. {
  11910. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11911. }
  11912. else
  11913. {
  11914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11915. }
  11916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11917. isKnowKey = TRUE;
  11918. }
  11919. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11920. {
  11921. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11922. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11924. {
  11925. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11926. }
  11927. else
  11928. {
  11929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11930. }
  11931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11932. isKnowKey = TRUE;
  11933. }
  11934. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11935. {
  11936. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11937. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11938. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11939. {
  11940. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11941. }
  11942. else
  11943. {
  11944. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11945. }
  11946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11947. isKnowKey = TRUE;
  11948. }
  11949. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11950. {
  11951. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11952. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11953. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11954. {
  11955. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11956. }
  11957. else
  11958. {
  11959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11960. }
  11961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11962. isKnowKey = TRUE;
  11963. }
  11964. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11965. {
  11966. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11967. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11969. {
  11970. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11971. }
  11972. else
  11973. {
  11974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11975. }
  11976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11977. isKnowKey = TRUE;
  11978. }
  11979. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11980. {
  11981. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11982. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11983. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11984. {
  11985. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11986. }
  11987. else
  11988. {
  11989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11990. }
  11991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11992. isKnowKey = TRUE;
  11993. }
  11994. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11995. {
  11996. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11997. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11998. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11999. {
  12000. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  12001. }
  12002. else
  12003. {
  12004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  12005. }
  12006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  12007. isKnowKey = TRUE;
  12008. }
  12009. #if 0
  12010. //For OCTT Test Case
  12011. if(isEmpty || strcmp(keyReq, "LocalAuthorizationListEnabled") == 0 )
  12012. {
  12013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthorizationListEnabled");
  12014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthorizationListEnabled");
  12015. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12016. {
  12017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12018. }
  12019. else
  12020. {
  12021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12022. }
  12023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12024. isKnowKey = TRUE;
  12025. }
  12026. #endif
  12027. #if 1
  12028. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  12029. {
  12030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  12031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  12032. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12033. {
  12034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  12035. }
  12036. else
  12037. {
  12038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  12039. }
  12040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  12041. isKnowKey = TRUE;
  12042. }
  12043. #endif
  12044. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  12045. {
  12046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  12047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  12048. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12049. {
  12050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12051. }
  12052. else
  12053. {
  12054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12055. }
  12056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  12057. isKnowKey = TRUE;
  12058. }
  12059. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  12060. {
  12061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  12062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  12063. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12064. {
  12065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  12066. }
  12067. else
  12068. {
  12069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  12070. }
  12071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  12072. isKnowKey = TRUE;
  12073. }
  12074. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  12075. {
  12076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  12077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  12078. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12079. {
  12080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  12081. }
  12082. else
  12083. {
  12084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  12085. }
  12086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  12087. isKnowKey = TRUE;
  12088. }
  12089. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  12090. {
  12091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  12092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  12093. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12094. {
  12095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  12096. }
  12097. else
  12098. {
  12099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  12100. }
  12101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  12102. isKnowKey = TRUE;
  12103. }
  12104. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  12105. {
  12106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  12107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  12108. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12109. {
  12110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  12111. }
  12112. else
  12113. {
  12114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  12115. }
  12116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  12117. isKnowKey = TRUE;
  12118. }
  12119. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  12120. {
  12121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  12122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  12123. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12124. {
  12125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  12126. }
  12127. else
  12128. {
  12129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  12130. }
  12131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  12132. isKnowKey = TRUE;
  12133. }
  12134. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  12135. {
  12136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  12137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  12138. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12139. {
  12140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  12141. }
  12142. else
  12143. {
  12144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  12145. }
  12146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  12147. isKnowKey = TRUE;
  12148. }
  12149. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  12150. {
  12151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  12152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  12153. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12154. {
  12155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  12156. }
  12157. else
  12158. {
  12159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  12160. }
  12161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  12162. isKnowKey = TRUE;
  12163. }
  12164. //=========================================================
  12165. if(!isEmpty && !isKnowKey)
  12166. {
  12167. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  12168. strcpy(unknownkey[UnknownKeynum], keyReq);
  12169. UnknownKeynum = UnknownKeynum + 1;
  12170. }
  12171. }
  12172. void processUnkownKey(void)
  12173. {
  12174. DEBUG_INFO("processUnkownKey\n");
  12175. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  12176. for(int index=0; index < UnknownKeynum; index++)
  12177. {
  12178. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  12179. {
  12180. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  12181. }
  12182. }
  12183. }
  12184. int setKeyValue(char *key, char *value)
  12185. {
  12186. int isSuccess = NotSupported;
  12187. int check_ascii=0;
  12188. char str[10]={0};
  12189. #ifdef Debug
  12190. DEBUG_INFO(" setKeyValue key-value=%s %s\n",key,value);
  12191. #endif
  12192. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  12193. {
  12194. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  12195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  12196. {
  12197. strcpy(str, (const char*)value);
  12198. for(int i = 0; str[i]; i++){
  12199. str[i] = tolower(str[i]);
  12200. }
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. else
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. }
  12209. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  12210. {
  12211. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  12212. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  12213. {
  12214. strcpy(str, (const char*)value);
  12215. for(int i = 0; str[i]; i++){
  12216. str[i] = tolower(str[i]);
  12217. }
  12218. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12219. isSuccess = ConfigurationStatus_Accepted;
  12220. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  12221. }
  12222. else
  12223. {
  12224. isSuccess = ConfigurationStatus_Rejected;
  12225. }
  12226. }
  12227. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  12228. {
  12229. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  12230. {
  12231. strcpy(str, (const char*)value);
  12232. for(int i = 0; str[i]; i++)
  12233. {
  12234. str[i] = tolower(str[i]);
  12235. }
  12236. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  12237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12238. isSuccess = ConfigurationStatus_Accepted;
  12239. }
  12240. else
  12241. {
  12242. isSuccess = ConfigurationStatus_Rejected;
  12243. }
  12244. }
  12245. if(strcmp(key, "BlinkRepeat") == 0)
  12246. {
  12247. //Charger.BlinkRepeat = Integer.parseInt(value);
  12248. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  12249. {
  12250. check_ascii = value[0];
  12251. if( (check_ascii < 48) || (check_ascii > 57) )
  12252. {
  12253. isSuccess = ConfigurationStatus_Rejected;
  12254. }
  12255. else
  12256. {
  12257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. }
  12261. else
  12262. {
  12263. isSuccess = ConfigurationStatus_Rejected;
  12264. }
  12265. }
  12266. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  12267. {
  12268. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  12269. {
  12270. check_ascii = value[0];
  12271. if( (check_ascii < 48) || (check_ascii > 57) )
  12272. {
  12273. isSuccess = ConfigurationStatus_Rejected;
  12274. }
  12275. else
  12276. {
  12277. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  12278. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  12279. isSuccess = ConfigurationStatus_Accepted;
  12280. }
  12281. }
  12282. else
  12283. {
  12284. isSuccess = ConfigurationStatus_Rejected;
  12285. }
  12286. }
  12287. if(strcmp(key, "ConnectionTimeOut") == 0 )
  12288. {
  12289. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  12290. {
  12291. check_ascii = value[0];
  12292. if( (check_ascii < 48) || (check_ascii > 57) )
  12293. {
  12294. isSuccess = ConfigurationStatus_Rejected;
  12295. }
  12296. else
  12297. {
  12298. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  12299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  12300. isSuccess = ConfigurationStatus_Accepted;
  12301. }
  12302. }
  12303. else
  12304. {
  12305. isSuccess = ConfigurationStatus_Rejected;
  12306. }
  12307. }
  12308. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  12309. {
  12310. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  12311. {
  12312. check_ascii = value[0];
  12313. if( (check_ascii < 48) || (check_ascii > 57) )
  12314. {
  12315. isSuccess = ConfigurationStatus_Rejected;
  12316. }
  12317. else
  12318. {
  12319. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12320. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  12321. isSuccess = ConfigurationStatus_Accepted;
  12322. }
  12323. }
  12324. else
  12325. {
  12326. isSuccess = ConfigurationStatus_Rejected;
  12327. }
  12328. }
  12329. if(strcmp(key, "HeartbeatInterval") == 0)
  12330. {
  12331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  12332. {
  12333. check_ascii = value[0];
  12334. if( (check_ascii < 48) || (check_ascii > 57) )
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. else
  12339. {
  12340. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  12341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  12342. HeartBeatWaitTime = atoi(value);
  12343. isSuccess = ConfigurationStatus_Accepted;
  12344. }
  12345. }
  12346. else
  12347. {
  12348. isSuccess = ConfigurationStatus_Rejected;
  12349. }
  12350. }
  12351. if(strcmp(key, "LightIntensity") == 0)
  12352. {
  12353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  12354. {
  12355. check_ascii = value[0];
  12356. if( (check_ascii < 48) || (check_ascii > 57) )
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. else
  12361. {
  12362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  12363. isSuccess = ConfigurationStatus_Accepted;
  12364. }
  12365. }
  12366. else
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. }
  12371. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12372. {
  12373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12374. {
  12375. strcpy(str, (const char*)value);
  12376. for(int i = 0; str[i]; i++)
  12377. {
  12378. str[i] = tolower(str[i]);
  12379. }
  12380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12381. isSuccess = ConfigurationStatus_Accepted;
  12382. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12383. }
  12384. else
  12385. {
  12386. isSuccess = ConfigurationStatus_Rejected;
  12387. }
  12388. }
  12389. if(strcmp(key, "LocalPreAuthorize") == 0)
  12390. {
  12391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12392. {
  12393. strcpy(str, (const char*)value);
  12394. for(int i = 0; str[i]; i++)
  12395. {
  12396. str[i] = tolower(str[i]);
  12397. }
  12398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12399. isSuccess = ConfigurationStatus_Accepted;
  12400. }
  12401. else
  12402. {
  12403. isSuccess = ConfigurationStatus_Rejected;
  12404. }
  12405. }
  12406. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12407. {
  12408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12409. {
  12410. check_ascii = value[0];
  12411. if( (check_ascii < 48) || (check_ascii > 57) )
  12412. {
  12413. isSuccess = ConfigurationStatus_Rejected;
  12414. }
  12415. else
  12416. {
  12417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12418. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12419. isSuccess = ConfigurationStatus_Accepted;
  12420. }
  12421. }
  12422. else
  12423. {
  12424. isSuccess = ConfigurationStatus_Rejected;
  12425. }
  12426. }
  12427. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12428. {
  12429. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12430. {
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. else
  12435. {
  12436. isSuccess = ConfigurationStatus_Rejected;
  12437. }
  12438. }
  12439. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12440. {
  12441. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12442. {
  12443. check_ascii = value[0];
  12444. if( (check_ascii < 48) || (check_ascii > 57) )
  12445. {
  12446. isSuccess = ConfigurationStatus_Rejected;
  12447. }
  12448. else
  12449. {
  12450. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12452. isSuccess = ConfigurationStatus_Accepted;
  12453. }
  12454. }
  12455. else
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. }
  12460. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12461. {
  12462. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12463. {
  12464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12465. isSuccess = ConfigurationStatus_Accepted;
  12466. }
  12467. else
  12468. {
  12469. isSuccess = ConfigurationStatus_Rejected;
  12470. }
  12471. }
  12472. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12473. {
  12474. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12475. {
  12476. check_ascii = value[0];
  12477. if( (check_ascii < 48) || (check_ascii > 57) )
  12478. {
  12479. isSuccess = ConfigurationStatus_Rejected;
  12480. }
  12481. else
  12482. {
  12483. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12485. isSuccess = ConfigurationStatus_Accepted;
  12486. }
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12494. {
  12495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12496. {
  12497. check_ascii = value[0];
  12498. if( (check_ascii < 48) || (check_ascii > 57) )
  12499. {
  12500. isSuccess = ConfigurationStatus_Rejected;
  12501. }
  12502. else
  12503. {
  12504. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12506. isSuccess = ConfigurationStatus_Accepted;
  12507. }
  12508. }
  12509. else
  12510. {
  12511. isSuccess = ConfigurationStatus_Rejected;
  12512. }
  12513. }
  12514. if(strcmp(key, "MinimumStatusDuration") == 0)
  12515. {
  12516. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12517. {
  12518. check_ascii = value[0];
  12519. if( (check_ascii < 48) || (check_ascii > 57) )
  12520. {
  12521. isSuccess = ConfigurationStatus_Rejected;
  12522. }
  12523. else
  12524. {
  12525. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12526. {
  12527. isSuccess = ConfigurationStatus_Rejected;
  12528. }
  12529. else
  12530. {
  12531. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12533. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12534. isSuccess = ConfigurationStatus_Accepted;
  12535. }
  12536. }
  12537. }
  12538. else
  12539. {
  12540. isSuccess = ConfigurationStatus_Rejected;
  12541. }
  12542. }
  12543. if(strcmp(key, "NumberOfConnectors") == 0)
  12544. {
  12545. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12546. {
  12547. check_ascii = value[0];
  12548. if( (check_ascii < 48) || (check_ascii > 57) )
  12549. {
  12550. isSuccess = ConfigurationStatus_Rejected;
  12551. }
  12552. else
  12553. {
  12554. //Charger.ResetRetries = Integer.parseInt(value);
  12555. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12556. isSuccess = ConfigurationStatus_Accepted;
  12557. }
  12558. }
  12559. else
  12560. {
  12561. isSuccess = ConfigurationStatus_Rejected;
  12562. }
  12563. }
  12564. if(strcmp(key, "ResetRetries") == 0)
  12565. {
  12566. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12567. {
  12568. check_ascii = value[0];
  12569. if( (check_ascii < 48) || (check_ascii > 57) )
  12570. {
  12571. isSuccess = ConfigurationStatus_Rejected;
  12572. }
  12573. else
  12574. {
  12575. //Charger.ResetRetries = Integer.parseInt(value);
  12576. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12577. isSuccess = ConfigurationStatus_Accepted;
  12578. }
  12579. }
  12580. else
  12581. {
  12582. isSuccess = ConfigurationStatus_Rejected;
  12583. }
  12584. }
  12585. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12586. {
  12587. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12588. {
  12589. strcpy(str, (const char*)value);
  12590. for(int i = 0; str[i]; i++)
  12591. {
  12592. str[i] = tolower(str[i]);
  12593. }
  12594. if(strcmp(str, "notapplicable")== 0)
  12595. {
  12596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12597. isSuccess = ConfigurationStatus_Accepted;
  12598. }
  12599. else if(strcmp(str, "unknown")== 0)
  12600. {
  12601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12602. isSuccess = ConfigurationStatus_Accepted;
  12603. }
  12604. else if(strcmp(str, "rst")== 0)
  12605. {
  12606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12607. isSuccess = ConfigurationStatus_Accepted;
  12608. }
  12609. else if(strcmp(str, "rts")== 0)
  12610. {
  12611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12612. isSuccess = ConfigurationStatus_Accepted;
  12613. }
  12614. else if(strcmp(str, "srt")== 0)
  12615. {
  12616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12617. isSuccess = ConfigurationStatus_Accepted;
  12618. }
  12619. else if(strcmp(str, "str")== 0)
  12620. {
  12621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12622. isSuccess = ConfigurationStatus_Accepted;
  12623. }
  12624. else if(strcmp(str, "trs")== 0)
  12625. {
  12626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12627. isSuccess = ConfigurationStatus_Accepted;
  12628. }
  12629. else if(strcmp(str, "tsr")== 0)
  12630. {
  12631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12632. isSuccess = ConfigurationStatus_Accepted;
  12633. }
  12634. else
  12635. {
  12636. isSuccess = ConfigurationStatus_Rejected;
  12637. }
  12638. }
  12639. else
  12640. {
  12641. isSuccess = ConfigurationStatus_Rejected;
  12642. }
  12643. }
  12644. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12645. {
  12646. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12647. {
  12648. check_ascii = value[0];
  12649. if( (check_ascii < 48) || (check_ascii > 57) )
  12650. {
  12651. isSuccess = ConfigurationStatus_Rejected;
  12652. }
  12653. else
  12654. {
  12655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12656. isSuccess = ConfigurationStatus_Accepted;
  12657. }
  12658. }
  12659. else
  12660. {
  12661. isSuccess = ConfigurationStatus_Rejected;
  12662. }
  12663. }
  12664. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12665. {
  12666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12667. {
  12668. strcpy(str, (const char*)value);
  12669. for(int i = 0; str[i]; i++)
  12670. {
  12671. str[i] = tolower(str[i]);
  12672. }
  12673. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12674. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12675. isSuccess = ConfigurationStatus_Accepted;
  12676. }
  12677. else
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. }
  12682. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12683. {
  12684. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12685. {
  12686. strcpy(str, (const char*)value);
  12687. for(int i = 0; str[i]; i++)
  12688. {
  12689. str[i] = tolower(str[i]);
  12690. }
  12691. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12693. isSuccess = ConfigurationStatus_Accepted;
  12694. }
  12695. else
  12696. {
  12697. isSuccess = ConfigurationStatus_Rejected;
  12698. }
  12699. }
  12700. if(strcmp(key, "StopTxnAlignedData") == 0)
  12701. {
  12702. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12703. {
  12704. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12705. isSuccess = ConfigurationStatus_Accepted;
  12706. }
  12707. else
  12708. {
  12709. isSuccess = ConfigurationStatus_Rejected;
  12710. }
  12711. }
  12712. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12713. {
  12714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12715. {
  12716. check_ascii = value[0];
  12717. if( (check_ascii < 48) || (check_ascii > 57) )
  12718. {
  12719. isSuccess = ConfigurationStatus_Rejected;
  12720. }
  12721. else
  12722. {
  12723. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12724. isSuccess = ConfigurationStatus_Accepted;
  12725. }
  12726. }
  12727. else
  12728. {
  12729. isSuccess = ConfigurationStatus_Rejected;
  12730. }
  12731. }
  12732. if(strcmp(key, "StopTxnSampledData") == 0)
  12733. {
  12734. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12735. {
  12736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12737. isSuccess = ConfigurationStatus_Accepted;
  12738. }
  12739. else
  12740. {
  12741. isSuccess = ConfigurationStatus_Rejected;
  12742. }
  12743. }
  12744. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12745. {
  12746. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12747. {
  12748. check_ascii = value[0];
  12749. if( (check_ascii < 48) || (check_ascii > 57) )
  12750. {
  12751. isSuccess = ConfigurationStatus_Rejected;
  12752. }
  12753. else
  12754. {
  12755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12756. isSuccess = ConfigurationStatus_Accepted;
  12757. }
  12758. }
  12759. else
  12760. {
  12761. isSuccess = ConfigurationStatus_Rejected;
  12762. }
  12763. }
  12764. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12765. {
  12766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12767. {
  12768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12769. isSuccess = ConfigurationStatus_Accepted;
  12770. }
  12771. else
  12772. {
  12773. isSuccess = ConfigurationStatus_Rejected;
  12774. }
  12775. }
  12776. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12777. {
  12778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12779. {
  12780. check_ascii = value[0];
  12781. if( (check_ascii < 48) || (check_ascii > 57) )
  12782. {
  12783. isSuccess = ConfigurationStatus_Rejected;
  12784. }
  12785. else
  12786. {
  12787. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12788. isSuccess = ConfigurationStatus_Accepted;
  12789. }
  12790. }
  12791. else
  12792. {
  12793. isSuccess = ConfigurationStatus_Rejected;
  12794. }
  12795. }
  12796. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12797. {
  12798. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12799. {
  12800. check_ascii = value[0];
  12801. if( (check_ascii < 48) || (check_ascii > 57) )
  12802. {
  12803. isSuccess = ConfigurationStatus_Rejected;
  12804. }
  12805. else
  12806. {
  12807. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12808. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12809. TransactionMessageAttemptsValue = atoi(value);
  12810. isSuccess = ConfigurationStatus_Accepted;
  12811. }
  12812. }
  12813. else
  12814. {
  12815. isSuccess = ConfigurationStatus_Rejected;
  12816. }
  12817. }
  12818. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12819. {
  12820. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12821. {
  12822. check_ascii = value[0];
  12823. if( (check_ascii < 48) || (check_ascii > 57) )
  12824. {
  12825. isSuccess = ConfigurationStatus_Rejected;
  12826. }
  12827. else
  12828. {
  12829. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12830. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12831. TransactionMessageRetryIntervalValue = atoi(value);
  12832. isSuccess = ConfigurationStatus_Accepted;
  12833. }
  12834. }
  12835. else
  12836. {
  12837. isSuccess = ConfigurationStatus_Rejected;
  12838. }
  12839. }
  12840. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12841. {
  12842. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12843. {
  12844. strcpy(str, (const char*)value);
  12845. for(int i = 0; str[i]; i++)
  12846. {
  12847. str[i] = tolower(str[i]);
  12848. }
  12849. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12851. isSuccess = ConfigurationStatus_Accepted;
  12852. }
  12853. else
  12854. {
  12855. isSuccess = ConfigurationStatus_Rejected;
  12856. }
  12857. }
  12858. if(strcmp(key, "WebSocketPingInterval") == 0)
  12859. {
  12860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12861. {
  12862. check_ascii = value[0];
  12863. if( (check_ascii < 48) || (check_ascii > 57) )
  12864. {
  12865. isSuccess = ConfigurationStatus_Rejected;
  12866. }
  12867. else
  12868. {
  12869. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12870. isSuccess = ConfigurationStatus_Accepted;
  12871. }
  12872. }
  12873. else
  12874. {
  12875. isSuccess = ConfigurationStatus_Rejected;
  12876. }
  12877. }
  12878. #if 0
  12879. //For OCPP Test Case
  12880. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12881. {
  12882. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12883. {
  12884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12885. isSuccess = ConfigurationStatus_Accepted;
  12886. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12887. }
  12888. else
  12889. {
  12890. isSuccess = ConfigurationStatus_Rejected;
  12891. }
  12892. }
  12893. #endif
  12894. #if 1
  12895. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12896. {
  12897. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12898. {
  12899. strcpy(str, (const char*)value);
  12900. for(int i = 0; str[i]; i++)
  12901. {
  12902. str[i] = tolower(str[i]);
  12903. }
  12904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12905. isSuccess = ConfigurationStatus_Accepted;
  12906. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12907. }
  12908. else
  12909. {
  12910. isSuccess = ConfigurationStatus_Rejected;
  12911. }
  12912. }
  12913. #endif
  12914. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12915. {
  12916. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12917. {
  12918. check_ascii = value[0];
  12919. if( (check_ascii < 48) || (check_ascii > 57) )
  12920. {
  12921. isSuccess = ConfigurationStatus_Rejected;
  12922. }
  12923. else
  12924. {
  12925. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12926. isSuccess = ConfigurationStatus_Accepted;
  12927. }
  12928. }
  12929. else
  12930. {
  12931. isSuccess = ConfigurationStatus_Rejected;
  12932. }
  12933. }
  12934. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12935. {
  12936. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12937. {
  12938. check_ascii = value[0];
  12939. if( (check_ascii < 48) || (check_ascii > 57) )
  12940. {
  12941. isSuccess = ConfigurationStatus_Rejected;
  12942. }
  12943. else
  12944. {
  12945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12946. isSuccess = ConfigurationStatus_Accepted;
  12947. }
  12948. }
  12949. else
  12950. {
  12951. isSuccess = ConfigurationStatus_Rejected;
  12952. }
  12953. }
  12954. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12955. {
  12956. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12957. {
  12958. strcpy(str, (const char*)value);
  12959. for(int i = 0; str[i]; i++)
  12960. {
  12961. str[i] = tolower(str[i]);
  12962. }
  12963. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12964. isSuccess = ConfigurationStatus_Accepted;
  12965. }
  12966. else
  12967. {
  12968. isSuccess = ConfigurationStatus_Rejected;
  12969. }
  12970. }
  12971. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12972. {
  12973. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12974. {
  12975. check_ascii = value[0];
  12976. if( (check_ascii < 48) || (check_ascii > 57) )
  12977. {
  12978. isSuccess = ConfigurationStatus_Rejected;
  12979. }
  12980. else
  12981. {
  12982. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12983. isSuccess = ConfigurationStatus_Accepted;
  12984. }
  12985. }
  12986. else
  12987. {
  12988. isSuccess = ConfigurationStatus_Rejected;
  12989. }
  12990. }
  12991. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12992. {
  12993. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12994. {
  12995. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12996. isSuccess = ConfigurationStatus_Accepted;
  12997. }
  12998. else
  12999. {
  13000. isSuccess = ConfigurationStatus_Rejected;
  13001. }
  13002. }
  13003. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  13004. {
  13005. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  13006. {
  13007. check_ascii = value[0];
  13008. if( (check_ascii < 48) || (check_ascii > 57) )
  13009. {
  13010. isSuccess = ConfigurationStatus_Rejected;
  13011. }
  13012. else
  13013. {
  13014. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  13015. isSuccess = ConfigurationStatus_Accepted;
  13016. }
  13017. }
  13018. else
  13019. {
  13020. isSuccess = ConfigurationStatus_Rejected;
  13021. }
  13022. }
  13023. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  13024. {
  13025. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  13026. {
  13027. strcpy(str, (const char*)value);
  13028. for(int i = 0; str[i]; i++)
  13029. {
  13030. str[i] = tolower(str[i]);
  13031. }
  13032. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  13033. isSuccess = ConfigurationStatus_Accepted;
  13034. }
  13035. else
  13036. {
  13037. isSuccess = ConfigurationStatus_Rejected;
  13038. }
  13039. }
  13040. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  13041. {
  13042. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  13043. {
  13044. check_ascii = value[0];
  13045. if( (check_ascii < 48) || (check_ascii > 57) )
  13046. {
  13047. isSuccess = ConfigurationStatus_Rejected;
  13048. }
  13049. else
  13050. {
  13051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  13052. isSuccess = ConfigurationStatus_Accepted;
  13053. }
  13054. }
  13055. else
  13056. {
  13057. isSuccess = ConfigurationStatus_Rejected;
  13058. }
  13059. }
  13060. return isSuccess;
  13061. }
  13062. int updateSetting(char *key, char *value)
  13063. {
  13064. mtrace();
  13065. int isSuccess = FALSE;
  13066. char string[1000]={0}, buffer[1000]={0};
  13067. char strtemp[50]={0};
  13068. char sstr[50]={ 0 };//sstr[200]={ 0 };
  13069. int pos, c = 0;
  13070. char *loc;
  13071. int pos1=0;
  13072. FILE *f = fopen("/var/www/settings1", "r");
  13073. if(f == NULL)
  13074. {
  13075. #ifdef Debug
  13076. DEBUG_ERROR("/var/www/settings1 does not exist!\n");
  13077. #endif
  13078. return isSuccess;
  13079. }
  13080. fseek(f, 0, SEEK_END);
  13081. long fsize = ftell(f);
  13082. fseek(f, 0, SEEK_SET); /* same as rewind(f); */
  13083. fread(string, 1, fsize, f);
  13084. fclose(f);
  13085. string[fsize] = 0;
  13086. loc = strstr(string, key);
  13087. if(loc != NULL)
  13088. {
  13089. DEBUG_INFO("key exist!\n");
  13090. pos = loc - string-1;
  13091. f = fopen("/var/www/settings1", "w");
  13092. strncpy(buffer, string, pos);
  13093. fprintf(f, "%s", buffer);
  13094. memset(sstr ,0, sizeof(sstr) );
  13095. c = 0;
  13096. while (loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c] != '\"')
  13097. {
  13098. sstr[c] = loc[3+strlen(key/*"LocalAuthListEnabled"*/)+c];
  13099. //printf("i=%d sstr=%c\n",c, sstr[c]);
  13100. c++;
  13101. }
  13102. sstr[c] = '\0';
  13103. pos1 = fsize -pos -(3+strlen(key/*"LocalAuthListEnabled"*/)+c)-1;
  13104. sprintf(strtemp,"\"%s\":\"%s\"",key,value);
  13105. fprintf(f, "%s", strtemp /*"\"LocalAuthListEnabled\":\"fault\""*/);
  13106. memset(buffer ,0, sizeof(buffer) );
  13107. strncpy(buffer, loc+(3+strlen(key/*"LocalAuthListEnabled"*/)+c)+1, pos1);
  13108. //printf("buffer=%s",buffer);
  13109. fprintf(f, "%s", buffer);
  13110. fclose(f);
  13111. }
  13112. else
  13113. {
  13114. printf("key not exist!\n");
  13115. f = fopen("/var/www/settings1", "w+");
  13116. fputs(string, f);
  13117. fseek(f, -1, SEEK_CUR);
  13118. //fprintf(f, "%s", ",\"LocalAuthListEnabled\":\"true\"}");
  13119. sprintf(strtemp,",\"%s\":\"%s\"}",key,value);
  13120. fputs(strtemp/*",\"LocalAuthListEnabled\":\"true\"}"*/, f);
  13121. fclose(f);
  13122. }
  13123. isSuccess = TRUE;
  13124. return isSuccess;
  13125. }
  13126. int TransactionMessageAttemptsGet(void)
  13127. {
  13128. return TransactionMessageAttemptsValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13129. }
  13130. int FirstHeartBeatResponse(void)
  13131. {
  13132. return FirstHeartBeat;
  13133. }
  13134. int TransactionMessageRetryIntervalGet(void)
  13135. {
  13136. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13137. }
  13138. #define SA struct sockaddr
  13139. #define MAXBUF 1024
  13140. //static int m_socket_data;
  13141. //static int sockfd;
  13142. int ReadHttpStatus(int sock){
  13143. //char c;
  13144. char buff[1024]="",*ptr=buff+1;
  13145. int bytes_received, status;
  13146. DEBUG_INFO("Begin Response ..\n");
  13147. while((bytes_received = recv(sock, ptr, 1, 0))){
  13148. if(bytes_received==-1){
  13149. perror("ReadHttpStatus");
  13150. exit(1);
  13151. }
  13152. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  13153. ptr++;
  13154. }
  13155. *ptr=0;
  13156. ptr=buff+1;
  13157. sscanf(ptr,"%*s %d ", &status);
  13158. DEBUG_INFO("%s\n",ptr);
  13159. DEBUG_INFO("status=%d\n",status);
  13160. DEBUG_INFO("End Response ..\n");
  13161. return (bytes_received>0)?status:0;
  13162. }
  13163. //the only filed that it parsed is 'Content-Length'
  13164. int ParseHeader(int sock){
  13165. //char c;
  13166. char buff[1024]="",*ptr=buff+4;
  13167. int bytes_received;
  13168. DEBUG_INFO("Begin HEADER ..\n");
  13169. while((bytes_received = recv(sock, ptr, 1, 0))){
  13170. if(bytes_received==-1){
  13171. perror("Parse Header");
  13172. exit(1);
  13173. }
  13174. if(
  13175. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  13176. (ptr[-1]=='\r') && (*ptr=='\n' )
  13177. ) break;
  13178. ptr++;
  13179. }
  13180. *ptr=0;
  13181. ptr=buff+4;
  13182. //printf("%s",ptr);
  13183. if(bytes_received){
  13184. ptr=strstr(ptr,"Content-Length:");
  13185. if(ptr){
  13186. sscanf(ptr,"%*s %d",&bytes_received);
  13187. }else
  13188. bytes_received=-1; //unknown size
  13189. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  13190. }
  13191. DEBUG_INFO("End HEADER ..\n");
  13192. return bytes_received ;
  13193. }
  13194. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  13195. {
  13196. char rmFileCmd[100]={0};
  13197. char FilePath[100]={0};
  13198. char ftpbuf[200];
  13199. int systemresult;
  13200. //DEBUG_INFO("filename=%s\n",filename);
  13201. //DEBUG_INFO("url=%s\n",url);
  13202. sprintf(FilePath,"/mnt/%s",filename);
  13203. if((access(FilePath,F_OK))!=-1)
  13204. {
  13205. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13206. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13207. system(rmFileCmd);
  13208. }
  13209. memset(ftpbuf, 0, sizeof(ftpbuf));
  13210. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13211. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13212. systemresult = system(ftpbuf);
  13213. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13214. if(systemresult != 0)
  13215. {
  13216. DEBUG_INFO("http DownLoad error!\n");
  13217. return FALSE;
  13218. }
  13219. return TRUE;
  13220. }
  13221. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  13222. {
  13223. char rmFileCmd[100]={0};
  13224. char FilePath[100]={0};
  13225. char ftpbuf[200];
  13226. int systemresult;
  13227. //char temp[100];
  13228. #if 0
  13229. struct hostent* server;
  13230. char *IPbuffer;
  13231. server = gethostbyname(location);
  13232. // To convert an Internet network
  13233. // address into ASCII string
  13234. IPbuffer = inet_ntoa(*((struct in_addr*)
  13235. server->h_addr_list[0]));
  13236. #endif
  13237. sprintf(FilePath,"/mnt/%s",filename);
  13238. if((access(FilePath,F_OK))!=-1)
  13239. {
  13240. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13241. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13242. system(rmFileCmd);
  13243. }
  13244. memset(ftpbuf, 0, sizeof(ftpbuf));
  13245. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  13246. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  13247. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13248. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13249. systemresult = system(ftpbuf);
  13250. //DEBUG_INFO("systemresult=%d\n",systemresult);
  13251. if(systemresult != 0)
  13252. {
  13253. printf("wget error!\n");
  13254. return FALSE;
  13255. }
  13256. return TRUE;
  13257. }
  13258. int httpUploadFile(char *location, char *path, char *filename,char *url)
  13259. {
  13260. char rmFileCmd[100]={0};
  13261. char FilePath[100]={0};
  13262. char ftpbuf[200];
  13263. char filenametemp[60]={0};
  13264. int systemresult;
  13265. //DEBUG_INFO("filename=%s\n",filename);
  13266. //DEBUG_INFO("url=%s\n",url);
  13267. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  13268. if((access(FilePath,F_OK))!=-1)
  13269. {
  13270. DEBUG_INFO("filename=%s exist.\n",FilePath);
  13271. sprintf(rmFileCmd,"rm -f %s",FilePath);
  13272. system(rmFileCmd);
  13273. }
  13274. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  13275. if(fp == NULL)
  13276. {
  13277. DEBUG_INFO("log is NULL\n");
  13278. return FALSE;
  13279. }
  13280. else
  13281. {
  13282. fprintf(fp, "%s\n", url);
  13283. sscanf(filename, "%*2[.]%s", filenametemp);
  13284. fprintf(fp, "%s\n", filenametemp);
  13285. fclose(fp);
  13286. }
  13287. memset(ftpbuf, 0, sizeof(ftpbuf));
  13288. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  13289. systemresult = system(ftpbuf);
  13290. DEBUG_INFO("systemresult=%d\n",systemresult);
  13291. if(systemresult != 0)
  13292. {
  13293. DEBUG_INFO("http upload error!\n");
  13294. return FALSE;
  13295. }
  13296. return TRUE;
  13297. }
  13298. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  13299. {
  13300. struct hostent* server;
  13301. char *IPbuffer;
  13302. char ftpbuf[200];
  13303. int systemresult;
  13304. // To retrieve host information
  13305. server = gethostbyname(location);
  13306. // To convert an Internet network
  13307. // address into ASCII string
  13308. IPbuffer = inet_ntoa(*((struct in_addr*)
  13309. server->h_addr_list[0]));
  13310. memset(ftpbuf, 0, sizeof(ftpbuf));
  13311. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  13312. /* format : ftpput -u username -p passwd IP target source*/
  13313. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  13314. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  13315. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  13316. systemresult = system(ftpbuf);
  13317. DEBUG_INFO("systemresult=%d\n",systemresult);
  13318. if(systemresult != 0)
  13319. {
  13320. DEBUG_INFO("ftpput error!\n");
  13321. return FALSE;
  13322. }
  13323. return TRUE;
  13324. }
  13325. int SettingChargingRecord(int target, int transactionId)
  13326. {
  13327. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13328. {
  13329. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13330. {
  13331. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13332. {
  13333. addBuff(target, transactionId, 0);
  13334. return TRUE;
  13335. }
  13336. }
  13337. for (int index = 0; index < CCS_QUANTITY; index++)
  13338. {
  13339. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13340. {
  13341. addBuff(target, transactionId, 0);
  13342. return TRUE;
  13343. }
  13344. }
  13345. for (int index = 0; index < GB_QUANTITY; index++)
  13346. {
  13347. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13348. {
  13349. addBuff(target, transactionId, 0);
  13350. return TRUE;
  13351. }
  13352. }
  13353. }
  13354. else
  13355. {
  13356. for (int index = 0; index < AC_QUANTITY; index++)
  13357. {
  13358. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == target)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  13359. {
  13360. addBuff(target, transactionId, 0);
  13361. return TRUE;
  13362. }
  13363. }
  13364. }
  13365. return FALSE;
  13366. }
  13367. int addBuff(int gun_idx, int user_id, int cmd_sn)
  13368. {
  13369. int isSuccess = FALSE;
  13370. //char *query = NULL;
  13371. sqlite3_stmt *stmt;
  13372. int rc; // return code
  13373. char str[20];
  13374. sprintf(str,"%d",user_id);
  13375. 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 */
  13376. sqlite3_bind_text(stmt, 1, str, -1, SQLITE_STATIC); /* 2 */
  13377. rc = sqlite3_step(stmt); /* 3 */
  13378. if (rc != SQLITE_DONE) {
  13379. printf("ERROR inserting data: %s\n", sqlite3_errmsg(db));
  13380. goto out;
  13381. }
  13382. sqlite3_finalize(stmt);
  13383. // free(query);
  13384. out:
  13385. //----------------------
  13386. // close SQLite database
  13387. //----------------------
  13388. sqlite3_close(db);
  13389. printf("database closed.\n");
  13390. return isSuccess;
  13391. }
  13392. /**
  13393. * Place the contents of the specified file into a memory buffer
  13394. *
  13395. * @param[in] filename The path and name of the file to read
  13396. * @param[out] filebuffer A pointer to the contents in memory
  13397. * @return status 0 success, 1 on failure
  13398. */
  13399. int get_file_contents(const char* filename, char** outbuffer) {
  13400. FILE* file = NULL;
  13401. long filesize;
  13402. const int blocksize = 1;
  13403. size_t readsize;
  13404. char* filebuffer;
  13405. // Open the file
  13406. file = fopen(filename, "r");
  13407. if (NULL == file)
  13408. {
  13409. printf("'%s' not opened\n", filename);
  13410. exit(EXIT_FAILURE);
  13411. }
  13412. // Determine the file size
  13413. fseek(file, 0, SEEK_END);
  13414. filesize = ftell(file);
  13415. rewind (file);
  13416. // Allocate memory for the file contents
  13417. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13418. *outbuffer = filebuffer;
  13419. if (filebuffer == NULL)
  13420. {
  13421. fputs ("malloc out-of-memory", stderr);
  13422. exit(EXIT_FAILURE);
  13423. }
  13424. // Read in the file
  13425. readsize = fread(filebuffer, blocksize, filesize, file);
  13426. if (readsize != filesize)
  13427. {
  13428. fputs ("didn't read file completely",stderr);
  13429. exit(EXIT_FAILURE);
  13430. }
  13431. // Clean exit
  13432. fclose(file);
  13433. return EXIT_SUCCESS;
  13434. }
  13435. static int selectSqlCount = 0;
  13436. static int callback(void *data, int argc, char **argv, char **azColName){
  13437. int i;
  13438. //printf("%s: ", (const char*)data);
  13439. selectSqlCount = argc;
  13440. for(i = 0; i<argc; i++){
  13441. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13442. }
  13443. //printf("\n");
  13444. return 0;
  13445. }
  13446. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13447. //int i;
  13448. //printf("%s:\n", (const char*)data);
  13449. localversion = argv[5] ? atoi(argv[5]) : 0;
  13450. //printf("localversion=%d\n", localversion);
  13451. return 0;
  13452. }
  13453. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13454. //int i;
  13455. //printf("%s:\n", (const char*)data);
  13456. //idTag
  13457. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13458. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13459. //parentIdTag
  13460. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13461. //expir_date
  13462. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13463. //status
  13464. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13465. //version
  13466. idTagQuery.listVersionInt = atoi(argv[5]);
  13467. DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13468. return 0;
  13469. }
  13470. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName){
  13471. #if 0
  13472. int i;
  13473. //printf("%s:\n", (const char*)data);
  13474. for(i=0; i<argc; i++){
  13475. DEBUG_INFO("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
  13476. }
  13477. //printf("");
  13478. #endif
  13479. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13480. // printf("localversion=%d\n", localversion);
  13481. return 0;
  13482. }
  13483. /** sqlite3_exec的回调。
  13484. *
  13485. * 向控制台打印查询的结果。
  13486. *
  13487. * @param in data 传递给回调函数的数据。
  13488. * @param in n_columns sqlite3_exec执行结果集中列的数量。
  13489. * @param in col_values sqlite3_exec执行结果集中每一列的数据。
  13490. * @param in col_names sqlite3_exec执行结果集中每一列的名称。
  13491. * @return 状态码。
  13492. */
  13493. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13494. {
  13495. for (int i = 0; i < n_columns; i++)
  13496. {
  13497. DEBUG_INFO("%s/t", col_values[i]);
  13498. }
  13499. DEBUG_INFO("/n");
  13500. return 0;
  13501. }
  13502. void OCPP_getListVerion()
  13503. {
  13504. int rc = 0;
  13505. // const char* data = "Callback function called";
  13506. char sql[100];
  13507. char zErrMsg[100];
  13508. memset(sql, 0, 100);
  13509. memset(zErrMsg, 0, 100);
  13510. // strcpy(sql, "select * from ocpp_auth_local order by idx desc");
  13511. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13512. /* Execute SQL statement */
  13513. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13514. DEBUG_INFO("rc=%d\n",rc);
  13515. if( rc != SQLITE_OK ){
  13516. DEBUG_INFO("SQL error: %s", zErrMsg);
  13517. //sqlite3_free(zErrMsg);
  13518. }
  13519. }
  13520. void OCPP_getIdTag(char idTag[])
  13521. {
  13522. int rc = 0;
  13523. // const char* data = "Callback function called";
  13524. char sql[100];
  13525. char zErrMsg[100];
  13526. memset(sql, 0, 100);
  13527. memset(zErrMsg, 0, 100);
  13528. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  13529. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13530. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13531. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13532. /* Execute SQL statement */
  13533. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13534. if( rc != SQLITE_OK ){
  13535. DEBUG_INFO("SQL error: %s", zErrMsg);
  13536. //sqlite3_free(zErrMsg);
  13537. }
  13538. //return ver;
  13539. }
  13540. void OCPP_get_TableAuthlocalAllData(void)
  13541. {
  13542. int rc = 0;
  13543. // const char* data = "Callback function called";
  13544. char sql[100];
  13545. char zErrMsg[100];
  13546. memset(sql, 0, 100);
  13547. memset(zErrMsg, 0, 100);
  13548. sprintf(sql,"select * from ocpp_auth_local ");
  13549. /* Execute SQL statement */
  13550. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13551. // rc = sqlite3_exec(db, sql, IdTagcallback, 0, &zErrMsg);
  13552. if( rc != SQLITE_OK ){
  13553. DEBUG_INFO("SQL error: %s", zErrMsg);
  13554. //sqlite3_free(zErrMsg);
  13555. }
  13556. //return ver;
  13557. }
  13558. int OCPP_cleanLocalList()
  13559. {
  13560. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13561. char *errMsg = 0;
  13562. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13563. if (SQLITE_OK != rc)
  13564. {
  13565. DEBUG_INFO("%s\n",errMsg);
  13566. return FALSE;
  13567. }
  13568. else
  13569. {
  13570. DEBUG_INFO("delete ocpp_auth_local table successfully\n");
  13571. }
  13572. return TRUE;
  13573. }
  13574. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13575. {
  13576. int isSuccess = FALSE;
  13577. int ret = 0;
  13578. //const char* data = "Callback function called";
  13579. char sql[300];
  13580. char zErrMsg[200];
  13581. memset(sql, 0, 300);
  13582. memset(zErrMsg, 0, 200);
  13583. 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);
  13584. //* Execute SQL statement */
  13585. //zErrMsg = 0;
  13586. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13587. if( ret != SQLITE_OK ){
  13588. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13589. // free(zErrMsg);
  13590. // free(sql);
  13591. return isSuccess;
  13592. }
  13593. memset(sql, 0, 300);
  13594. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13595. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13596. if( ret != SQLITE_OK ){
  13597. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13598. // free(zErrMsg);
  13599. // free(sql);
  13600. return isSuccess;
  13601. }
  13602. // DEBUG_INFO("successfully Insert records created\n");
  13603. isSuccess = TRUE;
  13604. return isSuccess;
  13605. }
  13606. void OCPP_deleteIdTag(char idTag[])
  13607. {
  13608. //int ver = 0;
  13609. //int isSuccess = FALSE;
  13610. int rc = 0;
  13611. char sql[100];
  13612. char zErrMsg[100];
  13613. memset(sql, 0, 100);
  13614. memset(zErrMsg, 0, 100);
  13615. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13616. //* Execute SQL statement */
  13617. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13618. if( rc != SQLITE_OK ){
  13619. DEBUG_INFO("SQL error: %s", zErrMsg);
  13620. //sqlite3_free(zErrMsg);
  13621. }
  13622. }
  13623. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13624. {
  13625. int isSuccess = FALSE;
  13626. int ret = 0;
  13627. const char* data = "Callback function called";
  13628. char sql[200];
  13629. char zErrMsg[100];
  13630. memset(sql, 0, 200);
  13631. memset(zErrMsg, 0, 100);
  13632. //* selectFromTable */
  13633. // sql = select * from ocpp_auth_local where starring='Jodie Foster';
  13634. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13635. //* Execute SQL statement */
  13636. selectSqlCount = 0;
  13637. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13638. if( ret != SQLITE_OK ){
  13639. printf("Error SQL: %s\n", zErrMsg);
  13640. }
  13641. printf("successfully select operation done\n");
  13642. memset(sql, 0, 200);
  13643. memset(zErrMsg, 0, 100);
  13644. if(selectSqlCount == 0)
  13645. {
  13646. //Insert
  13647. //sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " "VALUES (1, ? Paul?? 32, ? California?? 20000.00 ); ";
  13648. 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);
  13649. DEBUG_INFO("sql:%s\n", sql);
  13650. //* Execute SQL statement */
  13651. //zErrMsg = 0;
  13652. ret = sqlite3_exec(db, sql, callback, 0,(char **)&zErrMsg);
  13653. if( ret != SQLITE_OK ){
  13654. printf("SQL error: %s\n", zErrMsg);
  13655. return isSuccess;
  13656. }
  13657. DEBUG_INFO("successfully Insert records created\n");
  13658. isSuccess = TRUE;
  13659. }
  13660. else
  13661. {
  13662. //Update
  13663. //* Create merged SQL statement */
  13664. 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);
  13665. /* Execute SQL statement */
  13666. ret = sqlite3_exec(db, sql, callback, (void*)data,(char **)&zErrMsg);
  13667. if( ret != SQLITE_OK ){
  13668. printf("SQL error: %s\n", zErrMsg);
  13669. //sqlite3_free(zErrMsg);
  13670. //sqlite3_free(sql);
  13671. return isSuccess;
  13672. }
  13673. DEBUG_INFO("Successfully operation done \n");
  13674. isSuccess = TRUE;
  13675. }
  13676. return isSuccess;
  13677. }
  13678. int GetOcppServerURL()
  13679. {
  13680. int result = FALSE;
  13681. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  13682. memset(OcppHost, 0, sizeof(OcppHost));
  13683. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  13684. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13685. {
  13686. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.OcppServerURL =%s\n",ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  13687. #if 1
  13688. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13689. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13690. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13691. #endif
  13692. #if 0
  13693. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13694. "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]",
  13695. OcppProtocol, OcppHost, OcppTempPath);
  13696. OcppPort = 443;
  13697. #endif
  13698. result = TRUE;
  13699. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13700. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13701. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13702. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13703. goto End;
  13704. }
  13705. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13706. {
  13707. //DEBUG_INFO("ShmOCPP16Data->OcppServerURL =%s\n",ShmOCPP16Data->OcppServerURL);
  13708. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13709. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13710. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13711. result = TRUE;
  13712. // DEBUG_INFO("OcppProtocol =%s\n",OcppProtocol);
  13713. // DEBUG_INFO("OcppHost =%s\n",OcppHost);
  13714. // DEBUG_INFO("OcppPort =%d\n",OcppPort);
  13715. // DEBUG_INFO("OcppTempPath =%s\n",OcppTempPath);
  13716. goto End;
  13717. }
  13718. else
  13719. {
  13720. strcpy(OcppHost,"");
  13721. }
  13722. End:
  13723. return result;
  13724. }
  13725. int GetOcppPath()
  13726. {
  13727. int result = FALSE;
  13728. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13729. {
  13730. if(OcppTempPath == NULL)
  13731. {
  13732. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13733. }
  13734. else
  13735. {
  13736. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13737. }
  13738. result = TRUE;
  13739. goto End;
  13740. }
  13741. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13742. {
  13743. if(OcppTempPath == NULL)
  13744. {
  13745. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13746. }
  13747. else
  13748. {
  13749. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13750. }
  13751. result = TRUE;
  13752. goto End;
  13753. }
  13754. else
  13755. {
  13756. strcpy(OcppPath,"");
  13757. }
  13758. End:
  13759. //DEBUG_INFO("OcppPath=%s\n",OcppPath);
  13760. return result;
  13761. }
  13762. int GetOcppPort()
  13763. {
  13764. return OcppPort;
  13765. }
  13766. int GetOcppConnStatus(void)
  13767. {
  13768. return ShmOCPP16Data->OcppConnStatus;
  13769. }
  13770. void SetOcppConnStatus(uint8_t status)
  13771. {
  13772. ShmOCPP16Data->OcppConnStatus = status;
  13773. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13774. }
  13775. int GetHeartBeatWithNOResponse(void)
  13776. {
  13777. return HeartBeatWithNOResponse;
  13778. }
  13779. void SetHeartBeatWithNOResponse(void)
  13780. {
  13781. HeartBeatWithNOResponse = 0;
  13782. }
  13783. void GetStartTransactionIdTag(int gun_index)
  13784. {
  13785. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  13786. strcpy(StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13787. }
  13788. void splitstring(char *src,const char *separator,char **dest,int *num) {
  13789. /*
  13790. src 源字串的首地址(buf的地址)
  13791. separator 指定的分割字元
  13792. dest 接收子字串的陣列
  13793. num 分割後子字串的個數
  13794. */
  13795. char *pNext;
  13796. int count = 0;
  13797. if (src == NULL || strlen(src) == 0) //如果傳入的地址為空或長度為0,直接終止
  13798. return;
  13799. if (separator == NULL || strlen(separator) == 0) //如未指定分割的字串,直接終止
  13800. return;
  13801. pNext = (char *)strtok(src,separator); //必須使用(char *)進行強制型別轉換(雖然不寫有的編譯器中不會出現指標錯誤)
  13802. while(pNext != NULL) {
  13803. *dest++ = pNext;
  13804. ++count;
  13805. pNext = (char *)strtok(NULL,separator); //必須使用(char *)進行強制型別轉換
  13806. }
  13807. *num = count;
  13808. }
  13809. int GetTransactionId(int gunindex, unsigned char idTag[])
  13810. {
  13811. char ch;
  13812. FILE *fptr1;
  13813. int temptransactionId;
  13814. char str[100]={0};
  13815. temptransactionId = 0;
  13816. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13817. {
  13818. return temptransactionId;
  13819. }
  13820. /*------ Read the file ----------------*/
  13821. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13822. if (!fptr1)
  13823. {
  13824. //printf(" File not found or unable to open the input file!!\n");
  13825. return temptransactionId;
  13826. }
  13827. ch=fgetc(fptr1);
  13828. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13829. rewind(fptr1);
  13830. if(ch!=EOF)
  13831. {
  13832. // printf("%c",ch);
  13833. while (fgets(str, 100, fptr1) != NULL)
  13834. {
  13835. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13836. if(str[0]=='\0')
  13837. {
  13838. break;
  13839. }
  13840. char *revbuf[8] = {0}; //存放分割後的子字串
  13841. int num = 0;//分割後子字串的個數
  13842. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13843. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13844. {
  13845. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13846. {
  13847. temptransactionId = atoi(revbuf[2]);
  13848. break;
  13849. }
  13850. }
  13851. }
  13852. }
  13853. fclose(fptr1);
  13854. /*------- End of reading ---------------*/
  13855. return temptransactionId;
  13856. }
  13857. void SetTransactionIdZero(int transactionId)
  13858. {
  13859. //TransactionId[gunindex] = 0;
  13860. char ch;
  13861. FILE *fptr1, *fptr2;
  13862. int temptransactionId = 0;
  13863. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13864. printf("\n Delete a specific line from a file :\n");
  13865. printf("-----------------------------------------\n");
  13866. //scanf("%s",fname);
  13867. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13868. if (!fptr1)
  13869. {
  13870. //printf(" File not found or unable to open the input file!!\n");
  13871. return ;
  13872. }
  13873. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13874. if (!fptr2)
  13875. {
  13876. printf("Unable to open a temporary file to write!!\n");
  13877. fclose(fptr1);
  13878. return ;
  13879. }
  13880. ch=fgetc(fptr1);
  13881. //printf(" Now the content of the file %s is : \n",fname);
  13882. rewind(fptr1);
  13883. if(ch!=EOF)
  13884. {
  13885. // copy all contents to the temporary file except the specific line
  13886. while (fgets(str, 100, fptr1) != NULL)
  13887. {
  13888. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13889. if(str[0]=='\0')
  13890. {
  13891. break;
  13892. }
  13893. char *revbuf[8] = {0}; //存放分割後的子字串
  13894. int num = 0;//分割後子字串的個數
  13895. strcpy(strtemp, str);
  13896. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13897. if(revbuf[2][0] != '\0')
  13898. {
  13899. temptransactionId = atoi(revbuf[2]);
  13900. if(transactionId != temptransactionId)
  13901. {
  13902. fprintf(fptr2, "%s\n", strtemp);
  13903. }
  13904. }
  13905. }
  13906. }
  13907. fclose(fptr1);
  13908. fclose(fptr2);
  13909. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13910. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13911. printf("\n Delete a specific line from a file End\n");
  13912. printf("-----------------------------------------\n");
  13913. /*------ Read the file ----------------*/
  13914. }
  13915. int InternetDisconnect(void)
  13916. {
  13917. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi);
  13918. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet);
  13919. //DEBUG_INFO("ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi=%d\n",ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi);
  13920. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13921. }
  13922. void GetChargingProfileRequest(int gunindex)
  13923. {
  13924. mtrace();
  13925. //int connectorIdInt, durationInt;
  13926. //char chargingRateUnitStr[4]={0};
  13927. int tempdurationInt = 0;
  13928. int tempchargingProfileId = 0;
  13929. int tempstackLevel = 0;
  13930. int temptransactionId = 0;
  13931. float tempminChargingRateFloat = 0.0;
  13932. char tempchargingProfilePurposeStr[24]={0};
  13933. char tempchargingProfileKindStr[12]={0};
  13934. char temprecurrencyKindStr[8]={0};
  13935. char tempvalidFromStr[28]={0},tempchargingRateUnitStr[4]={0}, tempstartScheduleStr[30]={0};
  13936. char tempvalidToStr[28]={0};
  13937. int tempStartPeriodInt = 0;
  13938. float tempLimitInt = 0.0;//0.1;
  13939. int tempNumberPhasesInt=0;
  13940. char fname[200];
  13941. //char comfirmstr[20];
  13942. float MinChargingRate =0.0;
  13943. double diff_t;
  13944. struct tm tp;
  13945. FILE *fptr1;//, *fptr2;
  13946. int c = 0;
  13947. char * pch;
  13948. char *loc;
  13949. char sstr[200]={ 0 };
  13950. int n_chargingProfile = 0;
  13951. int n_SchedulePeriods = 0;
  13952. char SchedulePeriodList[10][200]={0};
  13953. char sLineWord[1600]={0};
  13954. char word[1000]={0};
  13955. int confirmPeriods = 0;
  13956. struct StructProfile ChargePointMaxProfile;
  13957. struct StructProfile TxDefaultProfile;
  13958. struct StructProfile TxProfile;
  13959. struct StructProfile TxDefaultProfiletemp[2]={0};
  13960. struct StructChargingProfile ChargePointMaxProfile_TEMP={0};
  13961. struct StructChargingProfile TxDefaultProfile_TEMP={0};
  13962. struct StructChargingProfile TxProfile_TEMP={0};
  13963. int TxDefaultProfileFileIsNull=FALSE;
  13964. int ChargePointMaxProfileIsNull=FALSE;
  13965. int TxProfileIsNull=FALSE;
  13966. // int CompositeSceduleIndex = 0;
  13967. char ChargePointMaxProfileScheduleStr[30]={0};
  13968. char TxDefaultProfileScheduleStr[30]={0};
  13969. char TxProfileScheduleStr[30]={0};
  13970. memset(&ChargePointMaxProfile,0,sizeof(struct StructProfile));
  13971. memset(&TxDefaultProfile,0,sizeof(struct StructProfile));
  13972. memset(&TxProfile,0,sizeof(struct StructProfile));
  13973. memset(&ShmOCPP16Data->SmartChargingProfile[gunindex],0,sizeof(struct StructChargingProfile));
  13974. DEBUG_INFO("GetChargingProfileRequest\n");
  13975. //*****************************ChargePointMaxProfile******************************************/
  13976. strcpy(fname, ChargePointMaxProfile_JSON);
  13977. ChargePointMaxProfileIsNull=TRUE;
  13978. DEBUG_INFO("test 1\n");
  13979. if((access(ChargePointMaxProfile_JSON,F_OK))!=-1)
  13980. {
  13981. fptr1 = fopen(fname, "r");
  13982. int c;
  13983. c = fgetc(fptr1);
  13984. //DEBUG_INFO("c:%d\n",c);
  13985. rewind(fptr1);
  13986. if(c == EOF)
  13987. {
  13988. DEBUG_INFO("\n End of file reached.");
  13989. ChargePointMaxProfileIsNull=TRUE;
  13990. fclose(fptr1);
  13991. }
  13992. else
  13993. {
  13994. DEBUG_INFO("test 2\n");
  13995. ChargePointMaxProfileIsNull=FALSE;
  13996. while(fscanf(fptr1, "%s", word) != EOF)
  13997. {
  13998. if(strcmp(word, "chargingProfileId") == 0)
  13999. {
  14000. n_chargingProfile = n_chargingProfile + 1;
  14001. }
  14002. }
  14003. rewind(fptr1);
  14004. //search Charging Profile Element
  14005. int i = 0;
  14006. int j = 0;
  14007. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14008. //***********chargingProfileId**************/
  14009. c = 0;
  14010. loc = strstr(sLineWord, "chargingProfileId");
  14011. //DEBUG_INFO("loc=%s\n",loc);
  14012. memset(sstr ,0, sizeof(sstr) );
  14013. if(loc != NULL)
  14014. {
  14015. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14016. {
  14017. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14018. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14019. c++;
  14020. }
  14021. sstr[c] = '\0';
  14022. tempchargingProfileId = atoi(sstr);
  14023. }
  14024. else
  14025. {
  14026. tempchargingProfileId = 0;
  14027. }
  14028. //***********stackLevel**************/
  14029. c = 0;
  14030. loc = strstr(sLineWord, "stackLevel");
  14031. //DEBUG_INFO("loc=%s\n",loc);
  14032. memset(sstr ,0, sizeof(sstr) );
  14033. if(loc != NULL)
  14034. {
  14035. while (loc[2+strlen("stackLevel")+c] != '\"')
  14036. {
  14037. sstr[c] = loc[2+strlen("stackLevel")+c];
  14038. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14039. c++;
  14040. }
  14041. sstr[c] = '\0';
  14042. tempstackLevel = atoi(sstr);
  14043. }
  14044. else
  14045. {
  14046. tempstackLevel = 0;
  14047. }
  14048. //***********chargingProfilePurpose **************/
  14049. c = 0;
  14050. loc = strstr(sLineWord, "chargingProfilePurpose");
  14051. //DEBUG_INFO("loc=%s\n",loc);
  14052. memset(sstr ,0, sizeof(sstr) );
  14053. if(loc != NULL)
  14054. {
  14055. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14056. {
  14057. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14059. c++;
  14060. }
  14061. sstr[c] = '\0';
  14062. strcpy(tempchargingProfilePurposeStr,sstr);
  14063. }
  14064. else
  14065. {
  14066. strcpy(tempchargingProfilePurposeStr,"");
  14067. }
  14068. //***********chargingProfileKind **************/
  14069. c = 0;
  14070. loc = strstr(sLineWord, "chargingProfileKind");
  14071. //DEBUG_INFO("loc=%s\n",loc);
  14072. memset(sstr ,0, sizeof(sstr) );
  14073. if(loc != NULL)
  14074. {
  14075. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14076. {
  14077. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14078. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14079. c++;
  14080. }
  14081. sstr[c] = '\0';
  14082. strcpy(tempchargingProfileKindStr,sstr);
  14083. }
  14084. else
  14085. {
  14086. strcpy(tempchargingProfileKindStr,"");
  14087. }
  14088. //***********recurrencyKind **************/
  14089. c = 0;
  14090. loc = strstr(sLineWord, "recurrencyKind");
  14091. //DEBUG_INFO("loc=%s\n",loc);
  14092. memset(sstr ,0, sizeof(sstr) );
  14093. if(loc != NULL)
  14094. {
  14095. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14096. {
  14097. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14098. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14099. c++;
  14100. }
  14101. sstr[c] = '\0';
  14102. strcpy(temprecurrencyKindStr,sstr);
  14103. }
  14104. else
  14105. {
  14106. strcpy(temprecurrencyKindStr,"");
  14107. }
  14108. //***********validFrom**************/
  14109. c = 0;
  14110. loc = strstr(sLineWord, "validFrom");
  14111. //DEBUG_INFO("loc=%s\n",loc);
  14112. memset(sstr ,0, sizeof(sstr) );
  14113. if(loc != NULL)
  14114. {
  14115. while (loc[3+strlen("validFrom")+c] != '\"')
  14116. {
  14117. sstr[c] = loc[3+strlen("validFrom")+c];
  14118. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14119. c++;
  14120. }
  14121. sstr[c] = '\0';
  14122. strcpy(tempvalidFromStr,sstr);
  14123. }
  14124. else
  14125. {
  14126. strcpy(tempvalidFromStr,"");
  14127. }
  14128. //***********validTo **************/
  14129. c = 0;
  14130. loc = strstr(sLineWord, "validTo");
  14131. //DEBUG_INFO("loc=%s\n",loc);
  14132. memset(sstr ,0, sizeof(sstr) );
  14133. if(loc != NULL)
  14134. {
  14135. while (loc[3+strlen("validTo")+c] != '\"')
  14136. {
  14137. sstr[c] = loc[3+strlen("validTo")+c];
  14138. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14139. c++;
  14140. }
  14141. sstr[c] = '\0';
  14142. strcpy(tempvalidToStr,sstr);
  14143. }
  14144. else
  14145. {
  14146. strcpy(tempvalidToStr,"");
  14147. }
  14148. //***********validFrom**************/
  14149. c = 0;
  14150. loc = strstr(sLineWord, "validFrom");
  14151. if(loc != NULL)
  14152. {
  14153. memset(sstr ,0, sizeof(sstr) );
  14154. while (loc[3+strlen("validFrom")+c] != '\"')
  14155. {
  14156. sstr[c] = loc[3+strlen("validFrom")+c];
  14157. c++;
  14158. }
  14159. sstr[c] = '\0';
  14160. strcpy(tempvalidFromStr,sstr);
  14161. }
  14162. else
  14163. {
  14164. strcpy(tempvalidFromStr,"");
  14165. }
  14166. //***********validTo **************/
  14167. c = 0;
  14168. loc = strstr(sLineWord, "validTo");
  14169. if(loc != NULL)
  14170. {
  14171. memset(sstr ,0, sizeof(sstr) );
  14172. while (loc[3+strlen("validTo")+c] != '\"')
  14173. {
  14174. sstr[c] = loc[3+strlen("validTo")+c];
  14175. c++;
  14176. }
  14177. sstr[c] = '\0';
  14178. strcpy(tempvalidToStr,sstr);
  14179. }
  14180. else
  14181. {
  14182. strcpy(tempvalidToStr,"");
  14183. }
  14184. //***********duration**************/
  14185. c = 0;
  14186. loc = strstr(sLineWord, "duration");
  14187. if(loc != NULL)
  14188. {
  14189. memset(sstr ,0, sizeof(sstr) );
  14190. while (loc[2+strlen("duration")+c] != ',')
  14191. {
  14192. sstr[c] = loc[2+strlen("duration")+c];
  14193. c++;
  14194. }
  14195. sstr[c] = '\0';
  14196. tempdurationInt = atoi(sstr);
  14197. }
  14198. else
  14199. {
  14200. tempdurationInt = 0;
  14201. }
  14202. //**********startSchedule**********/
  14203. c = 0;
  14204. loc = strstr(sLineWord, "startSchedule");
  14205. if(loc != NULL)
  14206. {
  14207. memset(sstr ,0, sizeof(sstr) );
  14208. while (loc[3+strlen("startSchedule")+c] != '\"')
  14209. {
  14210. sstr[c] = loc[3+strlen("startSchedule")+c];
  14211. c++;
  14212. }
  14213. sstr[c] = '\0';
  14214. strcpy(tempstartScheduleStr, sstr);
  14215. strcpy(ChargePointMaxProfileScheduleStr, sstr);
  14216. }
  14217. else
  14218. {
  14219. strcpy(tempstartScheduleStr, "");
  14220. strcpy(ChargePointMaxProfileScheduleStr, "");
  14221. }
  14222. //**********chargingRateUnit**********/
  14223. c = 0;
  14224. loc = strstr(sLineWord, "chargingRateUnit");
  14225. memset(sstr ,0, sizeof(sstr) );
  14226. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14227. {
  14228. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14229. c++;
  14230. }
  14231. sstr[c] = '\0';
  14232. strcpy(tempchargingRateUnitStr, sstr);
  14233. //**********minChargingRate*******/
  14234. c = 0;
  14235. loc = strstr(sLineWord, "minChargingRate");
  14236. if(loc != NULL)
  14237. {
  14238. memset(sstr ,0, sizeof(sstr) );
  14239. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14240. {
  14241. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14242. c++;
  14243. }
  14244. sstr[c] = '\0';
  14245. tempminChargingRateFloat = atof(sstr);
  14246. }
  14247. else
  14248. {
  14249. tempminChargingRateFloat = 0.0;
  14250. }
  14251. //
  14252. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14253. tp.tm_isdst = -1;
  14254. time_t utc = mktime(&tp);
  14255. time_t t = time(NULL);
  14256. diff_t = difftime(t, utc);
  14257. //DEBUG_INFO("diff_t=%f\n",diff_t);
  14258. //parsing strings to words
  14259. i = 0;
  14260. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14261. loc = loc+3+strlen("chargingSchedulePeriod");
  14262. pch = strtok(loc ,"{");
  14263. while (pch != NULL)
  14264. {
  14265. strcpy(SchedulePeriodList[i], pch);
  14266. pch = strtok (NULL, "{");
  14267. i = i + 1;
  14268. }
  14269. n_SchedulePeriods = i;
  14270. for(int i=0;i<n_SchedulePeriods;i++)
  14271. {
  14272. //*************startPeriod****************/
  14273. c = 0;
  14274. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14275. memset(sstr ,0, sizeof(sstr) );
  14276. while (loc[strlen("startPeriod")+2+c] != ',')
  14277. {
  14278. sstr[c] = loc[strlen("startPeriod")+2+c];
  14279. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14280. c++;
  14281. }
  14282. sstr[c] = '\0';
  14283. tempStartPeriodInt = atoi(sstr);
  14284. //*************limit****************/
  14285. c = 0;
  14286. loc = strstr(SchedulePeriodList[i], "limit");
  14287. memset(sstr ,0, sizeof(sstr) );
  14288. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14289. {
  14290. sstr[c] = loc[strlen("limit")+2+c];
  14291. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14292. c++;
  14293. }
  14294. sstr[c] = '\0';
  14295. tempLimitInt = atof(sstr);
  14296. //*************numberPhases****************/
  14297. c = 0;
  14298. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14299. memset(sstr ,0, sizeof(sstr) );
  14300. if(loc != NULL)
  14301. {
  14302. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14303. {
  14304. sstr[c] = loc[strlen("numberPhases")+2+c];
  14305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14306. c++;
  14307. }
  14308. sstr[c] = '\0';
  14309. tempNumberPhasesInt = atoi(sstr);
  14310. }
  14311. else
  14312. {
  14313. tempNumberPhasesInt = 0;
  14314. }
  14315. if(j == 0)
  14316. {
  14317. ChargePointMaxProfile.Duration = tempdurationInt;
  14318. ChargePointMaxProfile.TotalPeriod = n_SchedulePeriods;
  14319. ChargePointMaxProfile.Period[i].Limit = tempLimitInt;
  14320. ChargePointMaxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14321. ChargePointMaxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14322. ChargePointMaxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14323. ChargePointMaxProfile_TEMP.StackLevel = tempstackLevel;
  14324. ChargePointMaxProfile_TEMP.TransactionId = 0;
  14325. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14326. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14327. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14328. strcpy((char *)ChargePointMaxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14329. strcpy((char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14330. strcpy((char *)ChargePointMaxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14331. strcpy((char *)ChargePointMaxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14332. }
  14333. }
  14334. if(MinChargingRate < tempminChargingRateFloat)
  14335. {
  14336. MinChargingRate = tempminChargingRateFloat;
  14337. }
  14338. ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14339. if(confirmPeriods < n_SchedulePeriods)
  14340. {
  14341. confirmPeriods = n_SchedulePeriods;
  14342. }
  14343. j = j + 1;
  14344. } //end of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14345. fclose(fptr1);
  14346. }// end else
  14347. }// the end of access file ChargePointMaxProfile
  14348. DEBUG_INFO("test 3\n");
  14349. //****************************TxDefaultProfile************************************************/
  14350. memset(fname, 0, sizeof fname);
  14351. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", (gunindex + 1));
  14352. TxDefaultProfileFileIsNull=TRUE;
  14353. if((access(fname,F_OK))!=-1)
  14354. {
  14355. fptr1 = fopen(fname, "r");
  14356. c = 0;
  14357. c = fgetc(fptr1);
  14358. //DEBUG_INFO("c:%d\n",c);
  14359. rewind(fptr1);
  14360. if(c == EOF)
  14361. {
  14362. DEBUG_INFO("\n End of file reached.");
  14363. TxDefaultProfileFileIsNull=TRUE;
  14364. fclose(fptr1);
  14365. }
  14366. else
  14367. {
  14368. TxDefaultProfileFileIsNull=FALSE;
  14369. while(fscanf(fptr1, "%s", word) != EOF)
  14370. {
  14371. if(strcmp(word, "chargingProfileId") == 0)
  14372. {
  14373. n_chargingProfile = n_chargingProfile + 1;
  14374. }
  14375. }
  14376. rewind(fptr1);
  14377. //search Charging Profile Element
  14378. int i = 0;
  14379. int j = 0;
  14380. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  14381. {
  14382. #if 0
  14383. //***********connectorId****************/
  14384. c = 0;
  14385. loc = strstr(sLineWord, "connectorId");
  14386. memset(sstr ,0, sizeof(sstr) );
  14387. while (loc[strlen("connectorId")+2+c] != ',')
  14388. {
  14389. sstr[c] = loc[strlen("connectorId")+2+c];
  14390. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14391. c++;
  14392. }
  14393. sstr[c] = '\0';
  14394. tempconnectorIdInt = atoi(sstr);
  14395. #endif
  14396. //***********chargingProfileId**************/
  14397. c = 0;
  14398. loc = strstr(sLineWord, "chargingProfileId");
  14399. //DEBUG_INFO("loc=%s\n",loc);
  14400. memset(sstr ,0, sizeof(sstr) );
  14401. if(loc != NULL)
  14402. {
  14403. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14404. {
  14405. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14406. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14407. c++;
  14408. }
  14409. sstr[c] = '\0';
  14410. tempchargingProfileId = atoi(sstr);
  14411. }
  14412. else
  14413. {
  14414. tempchargingProfileId = 0;
  14415. }
  14416. //***********stackLevel**************/
  14417. c = 0;
  14418. loc = strstr(sLineWord, "stackLevel");
  14419. //DEBUG_INFO("loc=%s\n",loc);
  14420. memset(sstr ,0, sizeof(sstr) );
  14421. if(loc != NULL)
  14422. {
  14423. while (loc[2+strlen("stackLevel")+c] != '\"')
  14424. {
  14425. sstr[c] = loc[2+strlen("stackLevel")+c];
  14426. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14427. c++;
  14428. }
  14429. sstr[c] = '\0';
  14430. tempstackLevel = atoi(sstr);
  14431. }
  14432. else
  14433. {
  14434. tempstackLevel = 0;
  14435. }
  14436. //***********chargingProfilePurpose **************/
  14437. c = 0;
  14438. loc = strstr(sLineWord, "chargingProfilePurpose");
  14439. //DEBUG_INFO("loc=%s\n",loc);
  14440. memset(sstr ,0, sizeof(sstr) );
  14441. if(loc != NULL)
  14442. {
  14443. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14444. {
  14445. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14446. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14447. c++;
  14448. }
  14449. sstr[c] = '\0';
  14450. strcpy(tempchargingProfilePurposeStr,sstr);
  14451. }
  14452. else
  14453. {
  14454. strcpy(tempchargingProfilePurposeStr,"");
  14455. }
  14456. //***********chargingProfileKind **************/
  14457. c = 0;
  14458. loc = strstr(sLineWord, "chargingProfileKind");
  14459. //DEBUG_INFO("loc=%s\n",loc);
  14460. memset(sstr ,0, sizeof(sstr) );
  14461. if(loc != NULL)
  14462. {
  14463. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14464. {
  14465. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14466. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14467. c++;
  14468. }
  14469. sstr[c] = '\0';
  14470. strcpy(tempchargingProfileKindStr,sstr);
  14471. }
  14472. else
  14473. {
  14474. strcpy(tempchargingProfileKindStr,"");
  14475. }
  14476. //***********recurrencyKind **************/
  14477. c = 0;
  14478. loc = strstr(sLineWord, "recurrencyKind");
  14479. //DEBUG_INFO("loc=%s\n",loc);
  14480. memset(sstr ,0, sizeof(sstr) );
  14481. if(loc != NULL)
  14482. {
  14483. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14484. {
  14485. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14486. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14487. c++;
  14488. }
  14489. sstr[c] = '\0';
  14490. strcpy(temprecurrencyKindStr,sstr);
  14491. }
  14492. else
  14493. {
  14494. strcpy(temprecurrencyKindStr,"");
  14495. }
  14496. //***********validFrom**************/
  14497. c = 0;
  14498. loc = strstr(sLineWord, "validFrom");
  14499. if(loc != NULL)
  14500. {
  14501. memset(sstr ,0, sizeof(sstr) );
  14502. while (loc[3+strlen("validFrom")+c] != '\"')
  14503. {
  14504. sstr[c] = loc[3+strlen("validFrom")+c];
  14505. c++;
  14506. }
  14507. sstr[c] = '\0';
  14508. strcpy(tempvalidFromStr,sstr);
  14509. }
  14510. else
  14511. {
  14512. strcpy(tempvalidFromStr,"");
  14513. }
  14514. //***********validTo **************/
  14515. c = 0;
  14516. loc = strstr(sLineWord, "validTo");
  14517. if(loc != NULL)
  14518. {
  14519. memset(sstr ,0, sizeof(sstr) );
  14520. while (loc[3+strlen("validTo")+c] != '\"')
  14521. {
  14522. sstr[c] = loc[3+strlen("validTo")+c];
  14523. c++;
  14524. }
  14525. sstr[c] = '\0';
  14526. strcpy(tempvalidToStr,sstr);
  14527. }
  14528. else
  14529. {
  14530. strcpy(tempvalidToStr,"");
  14531. }
  14532. //***********duration**************/
  14533. c = 0;
  14534. loc = strstr(sLineWord, "duration");
  14535. if(loc != NULL)
  14536. {
  14537. memset(sstr ,0, sizeof(sstr) );
  14538. while (loc[2+strlen("duration")+c] != ',')
  14539. {
  14540. sstr[c] = loc[2+strlen("duration")+c];
  14541. c++;
  14542. }
  14543. sstr[c] = '\0';
  14544. tempdurationInt = atoi(sstr);
  14545. }
  14546. else
  14547. {
  14548. tempdurationInt = 0;
  14549. }
  14550. //**********startSchedule**********/
  14551. c = 0;
  14552. loc = strstr(sLineWord, "startSchedule");
  14553. if(loc != NULL)
  14554. {
  14555. memset(sstr ,0, sizeof(sstr) );
  14556. while (loc[3+strlen("startSchedule")+c] != '\"')
  14557. {
  14558. sstr[c] = loc[3+strlen("startSchedule")+c];
  14559. c++;
  14560. }
  14561. sstr[c] = '\0';
  14562. strcpy(tempstartScheduleStr, sstr);
  14563. strcpy(TxDefaultProfileScheduleStr, sstr);
  14564. }
  14565. else
  14566. {
  14567. strcpy(tempstartScheduleStr, "");
  14568. strcpy(TxDefaultProfileScheduleStr, "");
  14569. }
  14570. //**********chargingRateUnit**********/
  14571. c = 0;
  14572. loc = strstr(sLineWord, "chargingRateUnit");
  14573. memset(sstr ,0, sizeof(sstr) );
  14574. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14575. {
  14576. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14577. c++;
  14578. }
  14579. sstr[c] = '\0';
  14580. strcpy(tempchargingRateUnitStr, sstr);
  14581. //**********minChargingRate*******/
  14582. c = 0;
  14583. loc = strstr(sLineWord, "minChargingRate");
  14584. if(loc != NULL)
  14585. {
  14586. memset(sstr ,0, sizeof(sstr) );
  14587. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14588. {
  14589. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14590. c++;
  14591. }
  14592. sstr[c] = '\0';
  14593. tempminChargingRateFloat = atof(sstr);
  14594. }
  14595. else
  14596. {
  14597. tempminChargingRateFloat = 0.0;
  14598. }
  14599. //
  14600. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  14601. tp.tm_isdst = -1;
  14602. time_t utc = mktime(&tp);
  14603. time_t t = time(NULL);
  14604. diff_t = difftime(t, utc);
  14605. printf("diff between startScheduleStr and now =%f\n",diff_t);
  14606. //parsing strings to words
  14607. i = 0;
  14608. loc = strstr(sLineWord, "chargingSchedulePeriod");
  14609. loc = loc+3+strlen("chargingSchedulePeriod");
  14610. pch = strtok(loc ,"{");
  14611. while (pch != NULL)
  14612. {
  14613. strcpy(SchedulePeriodList[i], pch);
  14614. pch = strtok (NULL, "{");
  14615. i = i + 1;
  14616. }
  14617. n_SchedulePeriods = i;
  14618. for(int i=0;i<n_SchedulePeriods;i++)
  14619. {
  14620. //*************startPeriod****************/
  14621. c = 0;
  14622. loc = strstr(SchedulePeriodList[i], "startPeriod");
  14623. memset(sstr ,0, sizeof(sstr) );
  14624. while (loc[strlen("startPeriod")+2+c] != ',')
  14625. {
  14626. sstr[c] = loc[strlen("startPeriod")+2+c];
  14627. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14628. c++;
  14629. }
  14630. sstr[c] = '\0';
  14631. tempStartPeriodInt = atoi(sstr);
  14632. //*************limit****************/
  14633. c = 0;
  14634. loc = strstr(SchedulePeriodList[i], "limit");
  14635. memset(sstr ,0, sizeof(sstr) );
  14636. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  14637. {
  14638. sstr[c] = loc[strlen("limit")+2+c];
  14639. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14640. c++;
  14641. }
  14642. sstr[c] = '\0';
  14643. tempLimitInt = atof(sstr);
  14644. //*************numberPhases****************/
  14645. c = 0;
  14646. loc = strstr(SchedulePeriodList[i], "numberPhases");
  14647. memset(sstr ,0, sizeof(sstr) );
  14648. if(loc != NULL)
  14649. {
  14650. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  14651. {
  14652. sstr[c] = loc[strlen("numberPhases")+2+c];
  14653. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14654. c++;
  14655. }
  14656. sstr[c] = '\0';
  14657. tempNumberPhasesInt = atoi(sstr);
  14658. }
  14659. else
  14660. {
  14661. tempNumberPhasesInt = 0;
  14662. }
  14663. if(j == 0)
  14664. {
  14665. TxDefaultProfile.Duration = tempdurationInt;
  14666. TxDefaultProfile.TotalPeriod = n_SchedulePeriods;
  14667. TxDefaultProfile.Period[i].Limit = tempLimitInt;
  14668. TxDefaultProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  14669. TxDefaultProfile.Period[i].StartPeriod = tempStartPeriodInt;
  14670. TxDefaultProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  14671. TxDefaultProfile_TEMP.StackLevel = tempstackLevel;
  14672. TxDefaultProfile_TEMP.TransactionId = 0;
  14673. TxDefaultProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  14674. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  14675. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  14676. strcpy((char *)TxDefaultProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  14677. strcpy((char *)TxDefaultProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  14678. strcpy((char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  14679. strcpy((char *)TxDefaultProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  14680. strcpy((char *)TxDefaultProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  14681. }
  14682. else
  14683. {
  14684. //other stack level charging Profile
  14685. TxDefaultProfiletemp[j-1].Period[i].Limit = tempLimitInt;
  14686. TxDefaultProfiletemp[j-1].Period[i].NumberPhases = tempNumberPhasesInt;
  14687. TxDefaultProfiletemp[j-1].Period[i].StartPeriod = tempStartPeriodInt;
  14688. TxDefaultProfiletemp[j-1].Duration = tempdurationInt;
  14689. TxDefaultProfiletemp[j-1].TotalPeriod = n_SchedulePeriods;
  14690. }
  14691. }
  14692. if(MinChargingRate < tempminChargingRateFloat)
  14693. {
  14694. MinChargingRate = tempminChargingRateFloat;
  14695. }
  14696. TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  14697. if(confirmPeriods < n_SchedulePeriods)
  14698. confirmPeriods = n_SchedulePeriods;
  14699. j = j + 1;
  14700. }
  14701. fclose(fptr1);
  14702. //Stacking Charging Profiles
  14703. for(int l=0; l <(j-1) ;l++)
  14704. {
  14705. for(int k=0; k < TxDefaultProfiletemp[l].TotalPeriod; k++)
  14706. {
  14707. if(TxDefaultProfiletemp[l].Period[k].StartPeriod > TxDefaultProfile.Duration)
  14708. {
  14709. if((k >0) && ((TxDefaultProfiletemp[l].Period[k-1].StartPeriod < TxDefaultProfile.Duration) &&(TxDefaultProfiletemp[l].Period[k-1].StartPeriod >= TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod-1].StartPeriod )))
  14710. {
  14711. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k-1].Limit;
  14712. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k-1].NumberPhases;
  14713. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfile.Duration;
  14714. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14715. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14716. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14717. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14718. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14719. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14720. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14721. }
  14722. else
  14723. {
  14724. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].Limit = TxDefaultProfiletemp[l].Period[k].Limit;
  14725. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].NumberPhases = TxDefaultProfiletemp[l].Period[k].NumberPhases;
  14726. TxDefaultProfile.Period[TxDefaultProfile.TotalPeriod].StartPeriod = TxDefaultProfiletemp[l].Period[k].StartPeriod;
  14727. TxDefaultProfile.TotalPeriod = TxDefaultProfile.TotalPeriod + 1;
  14728. TxDefaultProfile.Duration = TxDefaultProfiletemp[l].Duration;
  14729. }
  14730. }
  14731. }
  14732. }//end of Stacking Charging Profiles
  14733. }// end else
  14734. }// the end of ACCESS TxDefaultProfile
  14735. //****************************TxProfile************************************************/
  14736. memset(fname, 0, sizeof fname);
  14737. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", (gunindex + 1));
  14738. TxProfileIsNull=TRUE;
  14739. if((access(fname,F_OK))!=-1)
  14740. {
  14741. fptr1 = fopen(fname, "r");
  14742. c = 0;
  14743. c = fgetc(fptr1);
  14744. //DEBUG_INFO("c:%d\n",c);
  14745. rewind(fptr1);
  14746. if(c == EOF)
  14747. {
  14748. DEBUG_INFO("\n End of file reached.");
  14749. TxProfileIsNull=TRUE;
  14750. fclose(fptr1);
  14751. }
  14752. else
  14753. {
  14754. TxProfileIsNull=FALSE;
  14755. while(fscanf(fptr1, "%s", word) != EOF)
  14756. {
  14757. if(strcmp(word, "chargingProfileId") == 0)
  14758. {
  14759. n_chargingProfile = n_chargingProfile + 1;
  14760. }
  14761. }
  14762. rewind(fptr1);
  14763. //search Charging Profile Element
  14764. int i= 0;
  14765. int j= 0;
  14766. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL ) {
  14767. #if 0
  14768. /***********connectorId****************/
  14769. c = 0;
  14770. loc = strstr(sLineWord, "connectorId");
  14771. memset(sstr ,0, sizeof(sstr) );
  14772. while (loc[strlen("connectorId")+2+c] != ',')
  14773. {
  14774. sstr[c] = loc[strlen("connectorId")+2+c];
  14775. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14776. c++;
  14777. }
  14778. sstr[c] = '\0';
  14779. tempconnectorIdInt = atoi(sstr);
  14780. #endif
  14781. //***********chargingProfileId**************/
  14782. c = 0;
  14783. loc = strstr(sLineWord, "chargingProfileId");
  14784. memset(sstr ,0, sizeof(sstr) );
  14785. if(loc != NULL)
  14786. {
  14787. while (loc[2+strlen("chargingProfileId")+c] != '\"')
  14788. {
  14789. sstr[c] = loc[2+strlen("chargingProfileId")+c];
  14790. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14791. c++;
  14792. }
  14793. sstr[c] = '\0';
  14794. tempchargingProfileId = atoi(sstr);
  14795. }
  14796. else
  14797. {
  14798. tempchargingProfileId = 0;
  14799. }
  14800. //***********transactionId **************/
  14801. c = 0;
  14802. loc = strstr(sLineWord, "transactionId");
  14803. //DEBUG_INFO("loc=%s\n",loc);
  14804. memset(sstr ,0, sizeof(sstr) );
  14805. if(loc != NULL)
  14806. {
  14807. while (loc[2+strlen("transactionId")+c] != '\"')
  14808. {
  14809. sstr[c] = loc[2+strlen("transactionId")+c];
  14810. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14811. c++;
  14812. }
  14813. sstr[c] = '\0';
  14814. temptransactionId = atoi(sstr);
  14815. }
  14816. else
  14817. {
  14818. temptransactionId = 0;
  14819. }
  14820. //***********stackLevel**************/
  14821. c = 0;
  14822. loc = strstr(sLineWord, "stackLevel");
  14823. //DEBUG_INFO("loc=%s\n",loc);
  14824. memset(sstr ,0, sizeof(sstr) );
  14825. if(loc != NULL)
  14826. {
  14827. while (loc[2+strlen("stackLevel")+c] != '\"')
  14828. {
  14829. sstr[c] = loc[2+strlen("stackLevel")+c];
  14830. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14831. c++;
  14832. }
  14833. sstr[c] = '\0';
  14834. tempstackLevel = atoi(sstr);
  14835. }
  14836. else
  14837. {
  14838. tempstackLevel = 0;
  14839. }
  14840. //***********chargingProfilePurpose **************/
  14841. c = 0;
  14842. loc = strstr(sLineWord, "chargingProfilePurpose");
  14843. //DEBUG_INFO("loc=%s\n",loc);
  14844. memset(sstr ,0, sizeof(sstr) );
  14845. if(loc != NULL)
  14846. {
  14847. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  14848. {
  14849. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  14850. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14851. c++;
  14852. }
  14853. sstr[c] = '\0';
  14854. strcpy(tempchargingProfilePurposeStr,sstr);
  14855. }
  14856. else
  14857. {
  14858. strcpy(tempchargingProfilePurposeStr,"");
  14859. }
  14860. //***********chargingProfileKind **************/
  14861. c = 0;
  14862. loc = strstr(sLineWord, "chargingProfileKind");
  14863. //DEBUG_INFO("loc=%s\n",loc);
  14864. memset(sstr ,0, sizeof(sstr) );
  14865. if(loc != NULL)
  14866. {
  14867. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  14868. {
  14869. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  14870. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14871. c++;
  14872. }
  14873. sstr[c] = '\0';
  14874. strcpy(tempchargingProfileKindStr,sstr);
  14875. }
  14876. else
  14877. {
  14878. strcpy(tempchargingProfileKindStr,"");
  14879. }
  14880. //***********recurrencyKind **************/
  14881. c = 0;
  14882. loc = strstr(sLineWord, "recurrencyKind");
  14883. //DEBUG_INFO("loc=%s\n",loc);
  14884. memset(sstr ,0, sizeof(sstr) );
  14885. if(loc != NULL)
  14886. {
  14887. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  14888. {
  14889. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  14890. //printf("i=%d sstr=%c\n",c, sstr[c]);
  14891. c++;
  14892. }
  14893. sstr[c] = '\0';
  14894. strcpy(temprecurrencyKindStr,sstr);
  14895. }
  14896. else
  14897. {
  14898. strcpy(temprecurrencyKindStr,"");
  14899. }
  14900. //***********validFrom**************/
  14901. c = 0;
  14902. loc = strstr(sLineWord, "validFrom");
  14903. if(loc != NULL)
  14904. {
  14905. memset(sstr ,0, sizeof(sstr) );
  14906. while (loc[3+strlen("validFrom")+c] != '\"')
  14907. {
  14908. sstr[c] = loc[3+strlen("validFrom")+c];
  14909. c++;
  14910. }
  14911. sstr[c] = '\0';
  14912. strcpy(tempvalidFromStr,sstr);
  14913. }
  14914. else
  14915. {
  14916. strcpy(tempvalidFromStr,"");
  14917. }
  14918. //***********validTo**************/
  14919. c = 0;
  14920. loc = strstr(sLineWord, "validTo");
  14921. if(loc != NULL)
  14922. {
  14923. memset(sstr ,0, sizeof(sstr) );
  14924. while (loc[3+strlen("validTo")+c] != '\"')
  14925. {
  14926. sstr[c] = loc[3+strlen("validTo")+c];
  14927. c++;
  14928. }
  14929. sstr[c] = '\0';
  14930. strcpy(tempvalidToStr,sstr);
  14931. }
  14932. else
  14933. {
  14934. strcpy(tempvalidToStr,"");
  14935. }
  14936. //***********duration**************/
  14937. c = 0;
  14938. loc = strstr(sLineWord, "duration");
  14939. //DEBUG_INFO("loc=%s\n",loc);
  14940. memset(sstr ,0, sizeof(sstr) );
  14941. if(loc != NULL)
  14942. {
  14943. while (loc[2+strlen("duration")+c] != '\"')
  14944. {
  14945. sstr[c] = loc[2+strlen("duration")+c];
  14946. c++;
  14947. }
  14948. sstr[c] = '\0';
  14949. tempdurationInt = atoi(sstr);
  14950. }
  14951. else
  14952. {
  14953. tempdurationInt = 0;
  14954. }
  14955. //**********startSchedule**********/
  14956. c = 0;
  14957. loc = strstr(sLineWord, "startSchedule");
  14958. if(loc != NULL)
  14959. {
  14960. memset(sstr ,0, sizeof(sstr) );
  14961. while (loc[3+strlen("startSchedule")+c] != '\"')
  14962. {
  14963. sstr[c] = loc[3+strlen("startSchedule")+c];
  14964. c++;
  14965. }
  14966. sstr[c] = '\0';
  14967. strcpy(tempstartScheduleStr, sstr);
  14968. strcpy(TxProfileScheduleStr, sstr);
  14969. }
  14970. else
  14971. {
  14972. strcpy(tempstartScheduleStr, "");
  14973. strcpy(TxProfileScheduleStr, "");
  14974. }
  14975. //**********chargingRateUnit**********/
  14976. c = 0;
  14977. loc = strstr(sLineWord, "chargingRateUnit");
  14978. memset(sstr ,0, sizeof(sstr) );
  14979. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  14980. {
  14981. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  14982. c++;
  14983. }
  14984. sstr[c] = '\0';
  14985. strcpy(tempchargingRateUnitStr, sstr);
  14986. //**********minChargingRate*******/
  14987. c = 0;
  14988. loc = strstr(sLineWord, "minChargingRate");
  14989. if(loc != NULL)
  14990. {
  14991. memset(sstr ,0, sizeof(sstr) );
  14992. while ((loc[2+strlen("minChargingRate")+c] != ',')&&(loc[2+strlen("minChargingRate")+c] != '}'))
  14993. {
  14994. sstr[c] = loc[2+strlen("minChargingRate")+c];
  14995. c++;
  14996. }
  14997. sstr[c] = '\0';
  14998. tempminChargingRateFloat = atof(sstr);
  14999. }
  15000. else
  15001. {
  15002. tempminChargingRateFloat = 0.0;
  15003. }
  15004. //
  15005. strptime(tempstartScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15006. tp.tm_isdst = -1;
  15007. time_t utc = mktime(&tp);
  15008. time_t t = time(NULL);
  15009. diff_t = difftime(t, utc);
  15010. //DEBUG_INFO("diff_t=%f\n",diff_t);
  15011. //parsing strings to words
  15012. i = 0;
  15013. loc = strstr(sLineWord, "chargingSchedulePeriod");
  15014. loc = loc+3+strlen("chargingSchedulePeriod");
  15015. pch = strtok(loc ,"{");
  15016. while (pch != NULL)
  15017. {
  15018. strcpy(SchedulePeriodList[i], pch);
  15019. pch = strtok (NULL, "{");
  15020. i = i + 1;
  15021. }
  15022. n_SchedulePeriods = i;
  15023. for(int i=0;i<n_SchedulePeriods;i++)
  15024. {
  15025. //*************startPeriod****************/
  15026. c = 0;
  15027. loc = strstr(SchedulePeriodList[i], "startPeriod");
  15028. memset(sstr ,0, sizeof(sstr) );
  15029. while (loc[strlen("startPeriod")+2+c] != ',')
  15030. {
  15031. sstr[c] = loc[strlen("startPeriod")+2+c];
  15032. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15033. c++;
  15034. }
  15035. sstr[c] = '\0';
  15036. tempStartPeriodInt = atoi(sstr);
  15037. //*************limit****************/
  15038. c = 0;
  15039. loc = strstr(SchedulePeriodList[i], "limit");
  15040. memset(sstr ,0, sizeof(sstr) );
  15041. while ((loc[strlen("limit")+2+c] != ',')&&(loc[strlen("limit")+2+c] != '}'))
  15042. {
  15043. sstr[c] = loc[strlen("limit")+2+c];
  15044. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15045. c++;
  15046. }
  15047. sstr[c] = '\0';
  15048. tempLimitInt = atof(sstr);
  15049. //*************numberPhases****************/
  15050. c = 0;
  15051. loc = strstr(SchedulePeriodList[i], "numberPhases");
  15052. memset(sstr ,0, sizeof(sstr) );
  15053. if(loc != NULL)
  15054. {
  15055. while ((loc[strlen("numberPhases")+2+c] != ',')&&(loc[strlen("numberPhases")+2+c] != '}'))
  15056. {
  15057. sstr[c] = loc[strlen("numberPhases")+2+c];
  15058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  15059. c++;
  15060. }
  15061. sstr[c] = '\0';
  15062. tempNumberPhasesInt = atoi(sstr);
  15063. }
  15064. else
  15065. {
  15066. tempNumberPhasesInt = 0;
  15067. }
  15068. //TxProfile.Duration = durationInt;
  15069. TxProfile.TotalPeriod = n_SchedulePeriods;
  15070. TxProfile.Period[i].Limit = tempLimitInt;
  15071. TxProfile.Period[i].NumberPhases = tempNumberPhasesInt;
  15072. TxProfile.Period[i].StartPeriod = tempStartPeriodInt;
  15073. }
  15074. if(MinChargingRate < tempminChargingRateFloat)
  15075. {
  15076. MinChargingRate = tempminChargingRateFloat;
  15077. }
  15078. TxProfile_TEMP.ChargingSchedule.MinChargingRate = MinChargingRate;
  15079. if(confirmPeriods < n_SchedulePeriods)
  15080. confirmPeriods = n_SchedulePeriods;
  15081. if(j == 0)
  15082. {
  15083. TxProfile_TEMP.ChargingProfileId = tempchargingProfileId;
  15084. TxProfile_TEMP.StackLevel = tempstackLevel;
  15085. TxProfile_TEMP.TransactionId = 0;
  15086. TxProfile_TEMP.ChargingSchedule.Duration = tempdurationInt;
  15087. strcpy((char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit, (const char *)tempchargingRateUnitStr);
  15088. strcpy((char *)TxProfile_TEMP.ChargingProfileKind, (const char *)tempchargingProfileKindStr);
  15089. strcpy((char *)TxProfile_TEMP.ChargingProfilePurpose, (const char *)tempchargingProfilePurposeStr);
  15090. strcpy((char *)TxProfile_TEMP.RecurrencyKind, (const char *)temprecurrencyKindStr);
  15091. strcpy((char *)TxProfile_TEMP.ChargingSchedule.StartSchedule, (const char *)tempstartScheduleStr);
  15092. strcpy((char *)TxProfile_TEMP.ValidFrom, (const char *)tempvalidFromStr);
  15093. strcpy((char *)TxProfile_TEMP.ValidTo, (const char *)tempvalidToStr);
  15094. }
  15095. }
  15096. fclose(fptr1);
  15097. }
  15098. }// the end of ACCESS TxProfile
  15099. //-----------------------------------------------CompositeSchedule--------------------------//
  15100. int period=0;
  15101. if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==FALSE) )
  15102. {
  15103. //TxProfile
  15104. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15105. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15106. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15107. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15108. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15109. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15110. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15111. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15112. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15113. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15114. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15115. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15116. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15117. for(int k=0; k < TxProfile.TotalPeriod;k++)
  15118. {
  15119. if(TxProfile.Period[k].Limit < ChargePointMaxProfile.Period[0].Limit)
  15120. {
  15121. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15122. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15123. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15124. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxProfile.Period[k].Limit;
  15125. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15126. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15127. period = period + 1;
  15128. }
  15129. else
  15130. {
  15131. if( (TxProfile.Period[k-1].Limit >= ChargePointMaxProfile.Period[0].Limit) && (TxProfile.Period[k].Limit >= ChargePointMaxProfile.Period[0].Limit))
  15132. {
  15133. }
  15134. else
  15135. {
  15136. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15137. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15138. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15139. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15140. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxProfile.Period[k].NumberPhases;
  15141. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxProfile.Period[k].StartPeriod;
  15142. period = period + 1;
  15143. }
  15144. }
  15145. }
  15146. struct tm tp;
  15147. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15148. tp.tm_isdst = -1;
  15149. time_t utc = mktime(&tp);
  15150. time_t t = time(NULL);
  15151. double diff_f = difftime(t, utc);
  15152. int diff_i;// = (int)diff_f;
  15153. int quotient; // = diff_i / 86400;//86400 seconds/day
  15154. if(diff_f >= 0)
  15155. {
  15156. diff_i = (int)diff_f;
  15157. quotient = diff_i / 86400;//86400 seconds/day
  15158. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15159. {
  15160. if(((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)&&((TxDefaultProfile.Period[l].StartPeriod % 86400) > ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period-1].StartPeriod))
  15161. {
  15162. if(TxDefaultProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15163. {
  15164. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15165. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15166. }
  15167. else
  15168. {
  15169. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15170. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15171. }
  15172. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15173. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15174. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15175. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15176. period = period + 1;
  15177. }
  15178. }
  15179. }// end of if(diff_f >= 0)
  15180. }
  15181. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15182. {
  15183. //TxDefaultProfile
  15184. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15185. struct tm tp;
  15186. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15187. tp.tm_isdst = -1;
  15188. time_t utc = mktime(&tp);
  15189. time_t t = time(NULL);
  15190. double diff_f = difftime(t, utc);
  15191. int diff_i;// = (int)diff_f;
  15192. int quotient; // = diff_i / 86400;//86400 seconds/day
  15193. int remainder;
  15194. //---- Define StartSchedule----/
  15195. struct tm *gtime;
  15196. time_t now;
  15197. char buf[28];
  15198. //---Read the current system time---/
  15199. time(&now);
  15200. //---Convert the system time to GMT (now UTC)---/
  15201. gtime = gmtime(&now);
  15202. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15203. if(diff_f >= 0)
  15204. {
  15205. diff_i = (int)diff_f;
  15206. quotient = diff_i / 86400;//86400 seconds/day
  15207. remainder = diff_i % 86400;
  15208. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15209. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15210. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15211. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400 - remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration ;
  15212. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15213. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15214. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15215. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15216. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);//strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15217. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15218. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15219. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15220. for(int l=0; l < TxDefaultProfile.TotalPeriod;l++)
  15221. {
  15222. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15223. {
  15224. if(TxProfile.Period[l].Limit < ChargePointMaxProfile.Period[0].Limit)
  15225. {
  15226. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15227. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15228. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15229. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15230. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15231. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15232. period = period + 1;
  15233. }
  15234. else
  15235. {
  15236. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = ChargePointMaxProfile.Period[0].Limit;
  15237. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15238. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15239. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[0].Limit;
  15240. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15241. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15242. period = period + 1;
  15243. }
  15244. }
  15245. }
  15246. } // end of diff_f >= 0
  15247. }
  15248. else if((TxDefaultProfileFileIsNull==FALSE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==TRUE) )
  15249. {
  15250. //TxDefaultProfile
  15251. strcpy(CurrentChargingProfileScheduleStr,TxDefaultProfileScheduleStr);
  15252. struct tm tp;
  15253. strptime((const char *)CurrentChargingProfileScheduleStr, "%Y-%m-%dT%H:%M:%S", &tp);
  15254. tp.tm_isdst = -1;
  15255. time_t utc = mktime(&tp);
  15256. time_t t = time(NULL);
  15257. double diff_f = difftime(t, utc);
  15258. int diff_i;// = (int)diff_f;
  15259. int quotient; // = diff_i / 86400;//86400 seconds/day
  15260. int remainder;
  15261. //---- Define StartSchedule----/
  15262. struct tm *gtime;
  15263. time_t now;
  15264. char buf[28];
  15265. //---Read the current system time---/
  15266. time(&now);
  15267. //---Convert the system time to GMT (now UTC)---/
  15268. gtime = gmtime(&now);
  15269. strftime(buf, 28, "%Y-%m-%dT%H:%M:%SZ", gtime);
  15270. if(diff_f >= 0)
  15271. {
  15272. diff_i = (int)diff_f;
  15273. quotient = diff_i / 86400;//86400 seconds/day
  15274. remainder = diff_i % 86400;
  15275. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxDefaultProfile_TEMP.ChargingProfileId;
  15276. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15277. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxDefaultProfile_TEMP.StackLevel;
  15278. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = (86400- remainder);//TxDefaultProfile_TEMP.ChargingSchedule.Duration;
  15279. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxDefaultProfile_TEMP.ChargingSchedule.MinChargingRate;
  15280. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15281. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxDefaultProfile_TEMP.ChargingProfileKind );
  15282. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxDefaultProfile_TEMP.ChargingProfilePurpose );
  15283. // strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)TxDefaultProfile_TEMP.ChargingSchedule.StartSchedule);
  15284. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, buf);
  15285. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxDefaultProfile_TEMP.RecurrencyKind);
  15286. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxDefaultProfile_TEMP.ValidFrom);
  15287. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxDefaultProfile_TEMP.ValidTo);
  15288. for(int l=0; l < TxDefaultProfile.TotalPeriod; l++)
  15289. {
  15290. if((TxDefaultProfile.Period[l].StartPeriod / 86400) == quotient)
  15291. {
  15292. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].Limit = TxDefaultProfile.Period[l].Limit;
  15293. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15294. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[period].StartPeriod = (TxDefaultProfile.Period[l].StartPeriod % 86400);
  15295. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].Limit = TxDefaultProfile.Period[l].Limit;
  15296. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxDefaultProfile.Period[l].NumberPhases;
  15297. //ShmOCPP16Data->GetCompositeSchedule[CompositeSceduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxDefaultProfile.Period[l].StartPeriod;
  15298. period = period + 1;
  15299. }
  15300. }
  15301. } //end of diff_f >= 0
  15302. }
  15303. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==FALSE) && (TxProfileIsNull==TRUE) )
  15304. {
  15305. //ChargePointMaxProfile
  15306. strcpy(CurrentChargingProfileScheduleStr,ChargePointMaxProfileScheduleStr);
  15307. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = ChargePointMaxProfile_TEMP.ChargingProfileId;
  15308. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = 0;
  15309. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = ChargePointMaxProfile_TEMP.StackLevel;
  15310. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = 86400 ;
  15311. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = ChargePointMaxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15312. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.ChargingRateUnit );
  15313. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)ChargePointMaxProfile_TEMP.ChargingProfileKind );
  15314. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)ChargePointMaxProfile_TEMP.ChargingProfilePurpose );
  15315. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule, (const char *)ChargePointMaxProfile_TEMP.ChargingSchedule.StartSchedule);
  15316. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)ChargePointMaxProfile_TEMP.RecurrencyKind);
  15317. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)ChargePointMaxProfile_TEMP.ValidFrom);
  15318. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)ChargePointMaxProfile_TEMP.ValidTo);
  15319. for(int l=0; l < ChargePointMaxProfile.TotalPeriod; l++)
  15320. {
  15321. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = ChargePointMaxProfile.Period[l].Limit;
  15322. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = ChargePointMaxProfile.Period[l].NumberPhases;
  15323. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = ChargePointMaxProfile.Period[l].StartPeriod;
  15324. period = period + 1;
  15325. }
  15326. }
  15327. else if((TxDefaultProfileFileIsNull==TRUE) && (ChargePointMaxProfileIsNull==TRUE) && (TxProfileIsNull==FALSE) )
  15328. {
  15329. //TxProfile Daily
  15330. strcpy(CurrentChargingProfileScheduleStr,TxProfileScheduleStr);
  15331. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId = TxProfile_TEMP.ChargingProfileId;
  15332. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId = temptransactionId;
  15333. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel = TxProfile_TEMP.StackLevel;
  15334. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration = TxProfile_TEMP.ChargingSchedule.Duration ;
  15335. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate = TxProfile_TEMP.ChargingSchedule.MinChargingRate;
  15336. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit, (const char *)TxProfile_TEMP.ChargingSchedule.ChargingRateUnit);
  15337. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind, (const char *)TxProfile_TEMP.ChargingProfileKind );
  15338. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose, (const char *)TxProfile_TEMP.ChargingProfilePurpose );
  15339. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,(const char *)TxProfile_TEMP.ChargingSchedule.StartSchedule);
  15340. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind, (const char *)TxProfile_TEMP.RecurrencyKind);
  15341. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom, (const char *)TxProfile_TEMP.ValidFrom);
  15342. strcpy((char *)ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo, (const char *)TxProfile_TEMP.ValidTo);
  15343. for(int l=0; l< TxProfile.TotalPeriod; l++)
  15344. {
  15345. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].Limit = TxProfile.Period[l].Limit;
  15346. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].NumberPhases = TxProfile.Period[l].NumberPhases;
  15347. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[l].StartPeriod = TxProfile.Period[l].StartPeriod;
  15348. }
  15349. }
  15350. confirmPeriods = period;
  15351. if(confirmPeriods != 0)
  15352. {
  15353. DEBUG_INFO("confirmPeriods=%d\n",confirmPeriods);
  15354. 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,"
  15355. "startPeriod0 =%d, limit0=%f, numberPhases0=%d\n"
  15356. "startPeriod1 =%d, limit1=%f, numberPhases1=%d\n"
  15357. "startPeriod2 =%d, limit2=%f, numberPhases2=%d\n"
  15358. "startPeriod3 =%d, limit3=%f, numberPhases3=%d\n"
  15359. "startPeriod4 =%d, limit4=%f, numberPhases4=%d\n"
  15360. "startPeriod5 =%d, limit5=%f, numberPhases5=%d\n"
  15361. "startPeriod6 =%d, limit6=%f, numberPhases6=%d\n"
  15362. "startPeriod7 =%d, limit7=%f, numberPhases7=%d\n"
  15363. "startPeriod8 =%d, limit8=%f, numberPhases8=%d\n"
  15364. "startPeriod9 =%d, limit9=%f, numberPhases9=%d\n",
  15365. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileId,
  15366. ShmOCPP16Data->SmartChargingProfile[gunindex].TransactionId,
  15367. ShmOCPP16Data->SmartChargingProfile[gunindex].StackLevel,
  15368. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfilePurpose,
  15369. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingProfileKind,
  15370. ShmOCPP16Data->SmartChargingProfile[gunindex].RecurrencyKind,
  15371. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidFrom,
  15372. ShmOCPP16Data->SmartChargingProfile[gunindex].ValidTo,
  15373. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.Duration,
  15374. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.StartSchedule,
  15375. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingRateUnit,
  15376. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.MinChargingRate,
  15377. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].StartPeriod,
  15378. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].Limit,
  15379. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[0].NumberPhases,
  15380. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].StartPeriod,
  15381. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].Limit,
  15382. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[1].NumberPhases,
  15383. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].StartPeriod,
  15384. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].Limit,
  15385. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[2].NumberPhases,
  15386. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].StartPeriod,
  15387. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].Limit,
  15388. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[3].NumberPhases,
  15389. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].StartPeriod,
  15390. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].Limit,
  15391. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[4].NumberPhases,
  15392. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].StartPeriod,
  15393. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].Limit,
  15394. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[5].NumberPhases,
  15395. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].StartPeriod,
  15396. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].Limit,
  15397. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[6].NumberPhases,
  15398. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].StartPeriod,
  15399. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].Limit,
  15400. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[7].NumberPhases,
  15401. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].StartPeriod,
  15402. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].Limit,
  15403. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[8].NumberPhases,
  15404. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].StartPeriod,
  15405. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].Limit,
  15406. ShmOCPP16Data->SmartChargingProfile[gunindex].ChargingSchedule.ChargingSchedulePeriod[9].NumberPhases);
  15407. }
  15408. }
  15409. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  15410. void storeTempStopTransaction(int gun_index)
  15411. {
  15412. //int result = FAIL;
  15413. //char message[1500]={0};
  15414. char guid[37]={0};
  15415. int tempIndex = 0;
  15416. //char tempdata[65]={0};
  15417. //int idx_sample=0;
  15418. DEBUG_ERROR("sendStopTransactionRequest \n");
  15419. memset(queuedata, 0, sizeof(queuedata));
  15420. //ENERGY_ACTIVE_IMPORT_REGISTER
  15421. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15422. if(gunType[gun_index] == 'J')
  15423. {
  15424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15425. {
  15426. tempIndex = ((gun_index==2) ? 1: 0);
  15427. }
  15428. else
  15429. {
  15430. tempIndex = gun_index;
  15431. }
  15432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15433. {
  15434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15435. {
  15436. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  15437. }
  15438. }// END OF CHAdeMO_QUANTITY
  15439. }
  15440. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  15451. {
  15452. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15453. {
  15454. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  15455. }
  15456. }// END OF CCS_QUANTITY
  15457. }
  15458. else if(gunType[gun_index] == 'G')
  15459. {
  15460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15461. {
  15462. tempIndex = ((gun_index==2) ? 1: 0);
  15463. }
  15464. else
  15465. {
  15466. tempIndex = gun_index;
  15467. }
  15468. for (int index = 0; index < GB_QUANTITY; index++)
  15469. {
  15470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15471. {
  15472. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  15473. }
  15474. }// END OF GB_QUANTITY
  15475. }
  15476. else
  15477. {
  15478. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15479. {
  15480. tempIndex = 2;
  15481. }
  15482. else
  15483. {
  15484. tempIndex = gun_index;
  15485. }
  15486. for (int index = 0; index < AC_QUANTITY; index++)
  15487. {
  15488. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15489. {
  15490. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  15491. }
  15492. }// END OF AC_QUANTITY
  15493. }
  15494. //Stop Transaction Time
  15495. struct timeval tmnow;
  15496. struct tm *tm;
  15497. char buf[28];//, usec_buf[6];
  15498. gettimeofday(&tmnow, NULL);
  15499. time_t t;
  15500. t = time(NULL);
  15501. /*UTC time and date*/
  15502. tm = gmtime(&t);
  15503. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  15504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  15505. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  15506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  15507. random_uuid(guid);
  15508. /***********************************transactionData******************************************************/
  15509. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  15510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  15511. //=================================
  15512. //1. Transaction_Begin
  15513. //=================================
  15514. // Energy.Active.Export.Interval
  15515. //idx_sample=0;
  15516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  15517. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  15518. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  15519. 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*/]);
  15520. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15521. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15522. {
  15523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  15524. }
  15525. else
  15526. {
  15527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  15528. }
  15529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  15530. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15531. //=================================
  15532. //2. Transaction_End
  15533. //=================================
  15534. //2.1 Current.Export
  15535. //idx_sample=1;
  15536. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  15537. if(gunType[gun_index] == 'J')
  15538. {
  15539. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15540. {
  15541. tempIndex = ((gun_index==2) ? 1: 0);
  15542. }
  15543. else
  15544. {
  15545. tempIndex = gun_index;
  15546. }
  15547. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15548. {
  15549. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15550. {
  15551. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15552. }
  15553. }// End of for CHAdeMO_QUANTITY
  15554. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15555. }
  15556. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15557. {
  15558. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15559. {
  15560. tempIndex = ((gun_index==2) ? 1: 0);
  15561. }
  15562. else
  15563. {
  15564. tempIndex = gun_index;
  15565. }
  15566. for (int index = 0; index < CCS_QUANTITY; index++)
  15567. {
  15568. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15569. {
  15570. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15571. }
  15572. }// End of for CCS_QUANTITY
  15573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15574. }
  15575. else if(gunType[gun_index] == 'G')
  15576. {
  15577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15578. {
  15579. tempIndex = ((gun_index==2) ? 1: 0);
  15580. }
  15581. else
  15582. {
  15583. tempIndex = gun_index;
  15584. }
  15585. for (int index = 0; index < GB_QUANTITY; index++)
  15586. {
  15587. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15588. {
  15589. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  15590. }
  15591. }// End of for GB_QUANTITY
  15592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  15593. }
  15594. else
  15595. {
  15596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15597. {
  15598. tempIndex = 2;
  15599. }
  15600. else
  15601. {
  15602. tempIndex = gun_index;
  15603. }
  15604. for (int index = 0; index < AC_QUANTITY; index++)
  15605. {
  15606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15607. {
  15608. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  15609. }
  15610. }// End of for AC_QUANTITY
  15611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15612. }
  15613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  15615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  15616. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  15617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  15618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  15619. //2.2 Energy.Active.Export.Interval
  15620. //idx_sample=2;
  15621. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15622. if(gunType[gun_index] == 'J')
  15623. {
  15624. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15625. {
  15626. tempIndex = ((gun_index==2) ? 1: 0);
  15627. }
  15628. else
  15629. {
  15630. tempIndex = gun_index;
  15631. }
  15632. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15633. {
  15634. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15635. {
  15636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15637. }
  15638. }// END OF CHAdeMO_QUANTITY
  15639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15640. }
  15641. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15642. {
  15643. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15644. {
  15645. tempIndex = ((gun_index==2) ? 1: 0);
  15646. }
  15647. else
  15648. {
  15649. tempIndex = gun_index;
  15650. }
  15651. for (int index = 0; index < CCS_QUANTITY; index++)
  15652. {
  15653. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15654. {
  15655. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15656. }
  15657. }// END OF CCS_QUANTITY
  15658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15659. }
  15660. else if(gunType[gun_index] == 'G')
  15661. {
  15662. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15663. {
  15664. tempIndex = ((gun_index==2) ? 1: 0);
  15665. }
  15666. else
  15667. {
  15668. tempIndex = gun_index;
  15669. }
  15670. for (int index = 0; index < GB_QUANTITY; index++)
  15671. {
  15672. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15673. {
  15674. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15675. }
  15676. }// END OF GB_QUANTITY
  15677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  15678. }
  15679. else
  15680. {
  15681. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15682. {
  15683. tempIndex = 2;
  15684. }
  15685. else
  15686. {
  15687. tempIndex = gun_index;
  15688. }
  15689. for (int index = 0; index < AC_QUANTITY; index++)
  15690. {
  15691. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15692. {
  15693. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  15694. }
  15695. }// END OF AC_QUANTITY
  15696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15697. }
  15698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  15700. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  15701. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  15702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  15703. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  15704. //2.3 Power.Active.Export
  15705. //idx_sample=3;
  15706. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15707. if(gunType[gun_index] == 'J')
  15708. {
  15709. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15710. {
  15711. tempIndex = ((gun_index==2) ? 1: 0);
  15712. }
  15713. else
  15714. {
  15715. tempIndex = gun_index;
  15716. }
  15717. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15718. {
  15719. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15720. {
  15721. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15722. }
  15723. } // End for CHAdeMO_QUANTITY
  15724. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15725. }
  15726. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15727. {
  15728. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15729. {
  15730. tempIndex = ((gun_index==2) ? 1: 0);
  15731. }
  15732. else
  15733. {
  15734. tempIndex = gun_index;
  15735. }
  15736. for (int index = 0; index < CCS_QUANTITY; index++)
  15737. {
  15738. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15739. {
  15740. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15741. }
  15742. } // END for CCS_QUANTITY
  15743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15744. }
  15745. else if(gunType[gun_index] == 'G')
  15746. {
  15747. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15748. {
  15749. tempIndex = ((gun_index==2) ? 1: 0);
  15750. }
  15751. else
  15752. {
  15753. tempIndex = gun_index;
  15754. }
  15755. for (int index = 0; index < GB_QUANTITY; index++)
  15756. {
  15757. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15758. {
  15759. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15760. }
  15761. }// END for GB_QUANTITY
  15762. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  15763. }
  15764. else
  15765. {
  15766. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15767. {
  15768. tempIndex = 2;
  15769. }
  15770. else
  15771. {
  15772. tempIndex = gun_index;
  15773. }
  15774. for (int index = 0; index < AC_QUANTITY; index++)
  15775. {
  15776. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15777. {
  15778. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  15779. }
  15780. } // END for AC_QUANTITY
  15781. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15782. }
  15783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  15785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  15786. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  15787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  15788. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  15789. //2.4 Voltage
  15790. //idx_sample=4;
  15791. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15792. if(gunType[gun_index] == 'J')
  15793. {
  15794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15795. {
  15796. tempIndex = ((gun_index==2) ? 1: 0);
  15797. }
  15798. else
  15799. {
  15800. tempIndex = gun_index;
  15801. }
  15802. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15803. {
  15804. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15805. {
  15806. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15807. }
  15808. } // END OF FOR CHAdeMO_QUANTITY
  15809. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15810. }
  15811. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15812. {
  15813. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15814. {
  15815. tempIndex = ((gun_index==2) ? 1: 0);
  15816. }
  15817. else
  15818. {
  15819. tempIndex = gun_index;
  15820. }
  15821. for (int index = 0; index < CCS_QUANTITY; index++)
  15822. {
  15823. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15824. {
  15825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15826. }
  15827. } // END OF FOR CCS_QUANTITY
  15828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15829. }
  15830. else if(gunType[gun_index] == 'G')
  15831. {
  15832. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15833. {
  15834. tempIndex = ((gun_index==2) ? 1: 0);
  15835. }
  15836. else
  15837. {
  15838. tempIndex = gun_index;
  15839. }
  15840. for (int index = 0; index < GB_QUANTITY; index++)
  15841. {
  15842. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15843. {
  15844. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  15845. }
  15846. } // END OF FOR GB_QUANTITY
  15847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  15848. }
  15849. else
  15850. {
  15851. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15852. {
  15853. tempIndex = 2;
  15854. }
  15855. else
  15856. {
  15857. tempIndex = gun_index;
  15858. }
  15859. for (int index = 0; index < AC_QUANTITY; index++)
  15860. {
  15861. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15862. {
  15863. 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
  15864. }
  15865. } // END OF FOR AC_QUANTITY
  15866. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15867. }
  15868. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  15870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  15871. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  15872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  15873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  15874. //2.5 SoC
  15875. //idx_sample=5;
  15876. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  15877. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15878. {
  15879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15880. {
  15881. tempIndex = ((gun_index==2) ? 1: 0);
  15882. }
  15883. else
  15884. {
  15885. tempIndex = gun_index;
  15886. }
  15887. if(gunType[gun_index] == 'J')
  15888. {
  15889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15890. {
  15891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15892. {
  15893. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  15894. }
  15895. }
  15896. }
  15897. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  15898. {
  15899. for (int index = 0; index < CCS_QUANTITY; index++)
  15900. {
  15901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15902. {
  15903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  15904. }
  15905. }
  15906. }
  15907. else if(gunType[gun_index] == 'G')
  15908. {
  15909. for (int index = 0; index < GB_QUANTITY; index++)
  15910. {
  15911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15912. {
  15913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  15914. }
  15915. }
  15916. }
  15917. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  15918. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  15919. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  15920. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  15921. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  15922. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  15923. } // END FOR DC CASE
  15924. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  15925. {
  15926. 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\"}]}]}]"
  15927. ,MESSAGE_TYPE_CALL
  15928. ,guid
  15929. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15930. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15931. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15933. ,"PowerLoss"
  15934. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  15945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  15946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  15947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  15948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  15949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  15950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  15951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  15952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  15953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  15954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  15955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  15956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  15957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  15958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  15959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  15960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  15961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  15962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  15963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  15964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  15965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  15966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  15967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  15968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  15969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  15970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  15971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  15972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  15973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  15974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  15975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  15976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  15977. );
  15978. }
  15979. else
  15980. {
  15981. 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\"}]}]}]"
  15982. ,MESSAGE_TYPE_CALL
  15983. ,guid
  15984. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  15985. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  15986. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  15987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  15988. ,"PowerLoss"
  15989. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  15990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  15991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  15992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  15993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  15994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  15995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  15996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  15997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  15998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  15999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  16000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  16001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  16002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  16003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  16004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  16005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  16006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  16007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  16008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  16009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  16010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  16011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  16012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  16013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  16014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  16015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  16016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  16017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  16018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  16019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  16020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  16021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  16022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  16023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  16024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  16025. );
  16026. }
  16027. // Check File "TempStopTransaction" Exist
  16028. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  16029. {
  16030. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  16031. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  16032. }
  16033. else
  16034. {
  16035. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  16036. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  16037. if(log == NULL)
  16038. {
  16039. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  16040. return ;
  16041. }
  16042. else
  16043. {
  16044. fclose(log);
  16045. }
  16046. }
  16047. //Add TempStopTransaction | Update TempStopTransaction
  16048. // open file for writing
  16049. FILE *outfile;
  16050. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  16051. DEBUG_INFO("data=%s\n",queuedata);
  16052. fputs(queuedata, outfile);
  16053. fputs("\n", outfile);
  16054. fclose (outfile);
  16055. }
  16056. void checkTempStopTransaction(int gun_index)
  16057. {
  16058. FILE *fptr1;
  16059. char ch;
  16060. char str[1200]={0};
  16061. char guid[37]={0};
  16062. char tempdata[65]={0};
  16063. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  16064. if (!fptr1)
  16065. {
  16066. //printf(" File not found or unable to open the input file!!\n");
  16067. return ;
  16068. }
  16069. ch=fgetc(fptr1);
  16070. //printf(" Now the content of the file %s is : \n",fname);
  16071. rewind(fptr1);
  16072. if(ch!=EOF)
  16073. {
  16074. // copy all contents to the temporary file except the specific line
  16075. while (fgets(str, 1200, fptr1) != NULL)
  16076. {
  16077. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16078. if(str[0]=='\0')
  16079. {
  16080. break;
  16081. }
  16082. random_uuid(guid);
  16083. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  16084. if(hashmap_operation(0, guid, tempdata) == 1)
  16085. {
  16086. DEBUG_INFO("StopTransaction mapitem pass\n");
  16087. }
  16088. queue_operation(4, guid, str );//addq(guid, queuedata); ---> remove temporally
  16089. memset(str,0,sizeof str);
  16090. }
  16091. }
  16092. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16093. fclose(fptr1);
  16094. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  16095. }
  16096. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  16097. {
  16098. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  16099. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  16100. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  16101. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  16102. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  16103. }
  16104. int GetWebSocketPingInterval(void)
  16105. {
  16106. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  16107. }
  16108. int GetServerSign(void)
  16109. {
  16110. return server_sign;
  16111. }
  16112. void SetServerSign(int value)
  16113. {
  16114. server_sign = value;
  16115. }
  16116. int GetBootNotificationInterval(void)
  16117. {
  16118. return BootNotificationInterval;
  16119. }
  16120. int GetInternetConn(void)
  16121. {
  16122. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16123. }
  16124. void InitialSystemValue(void)
  16125. {
  16126. int connectorIndex = 0;
  16127. //int valueASCII = 0;
  16128. server_cycle_Status = 120;
  16129. gunTotalNumber=0;
  16130. SystemInitial = 0;
  16131. localversion=0;
  16132. BootNotificationInterval = 0;
  16133. authorizeRetryTimes = 0;
  16134. GunStatusInterval = 10;
  16135. TransactionMessageAttemptsValue = 0;
  16136. TransactionMessageRetryIntervalValue = 0;
  16137. //Hear Beat
  16138. HeartBeatWithNOResponse = 0;
  16139. HeartBeatCountPerHour = 0;
  16140. HeartBeatWaitTime = 10;
  16141. FirstHeartBeat = 0;
  16142. FirmwareStatusNotificationStatus = 3; // Idle
  16143. DiagnosticsStatusNotificationStatus = 0; // Idle
  16144. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  16145. memset(statusModeChage, 0, sizeof(statusModeChage));
  16146. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  16147. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  16148. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  16149. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  16150. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  16151. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  16152. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  16153. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  16154. memset(gunType, 0, sizeof(gunType));
  16155. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  16156. {
  16157. //check connector / socket type (index: 8, 9, 10)
  16158. for(int index=7; index <10 ; index++)
  16159. {
  16160. if(index != 8)
  16161. {
  16162. // DC Connector
  16163. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  16164. {
  16165. SystemInitial = SystemInitial + 1;
  16166. gunTotalNumber = gunTotalNumber + 1;
  16167. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16168. connectorIndex = connectorIndex + 1;
  16169. }
  16170. }
  16171. else
  16172. {
  16173. // AC Connector
  16174. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16175. {
  16176. SystemInitial = SystemInitial + 1;
  16177. gunTotalNumber = gunTotalNumber + 1;
  16178. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16179. connectorIndex = connectorIndex + 1;
  16180. }
  16181. }
  16182. }
  16183. //DEBUG_INFO("DC ...\n");
  16184. }
  16185. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  16186. {
  16187. //check connector / socket type (index: 8, 9, 10)
  16188. for(int index=7; index <10 ; index++)
  16189. {
  16190. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  16191. {
  16192. SystemInitial = SystemInitial + 1;
  16193. gunTotalNumber = gunTotalNumber + 1;
  16194. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  16195. connectorIndex = connectorIndex + 1;
  16196. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  16197. }
  16198. }
  16199. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  16200. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  16201. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  16202. //DEBUG_INFO("AC ...\n");
  16203. }
  16204. //Status && ConnectorPlugIn Setting
  16205. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16206. {
  16207. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16208. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16209. }
  16210. for (int index = 0; index < CCS_QUANTITY; index++)
  16211. {
  16212. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16213. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16214. }
  16215. for (int index = 0; index < GB_QUANTITY; index++)
  16216. {
  16217. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16218. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16219. }
  16220. for (int index = 0; index < AC_QUANTITY; index++)
  16221. {
  16222. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16223. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16224. }
  16225. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16226. {
  16227. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  16228. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  16229. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16230. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  16231. }
  16232. // Charger PRE_SYS_MODE
  16233. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  16234. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  16235. clientTime.Heartbeat=time((time_t*)NULL);
  16236. sleep(1);
  16237. }
  16238. void LWS_Send(char * str)
  16239. {
  16240. //=====================================================
  16241. // Check InternetConn 0: disconnected, 1: connected
  16242. //====================================================
  16243. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  16244. {
  16245. DEBUG_INFO("\n offline now !!!\n");
  16246. return;
  16247. }
  16248. pthread_mutex_lock(&lock);
  16249. memset(SendBuffer,0,SendBufLen);
  16250. sprintf((char *)SendBuffer, "%s", str);
  16251. pthread_mutex_unlock(&lock);
  16252. lws_callback_on_writable(wsi_client);
  16253. lws_service(context, 10000);//timeout_ms
  16254. }