MessageHandler.c 624 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. //===================================
  18. // Define CP State constant
  19. //===================================
  20. #define CP_STATE_UNKNOWN 0
  21. #define CP_STATE_A 1
  22. #define CP_STATE_B 2
  23. #define CP_STATE_C 3
  24. #define CP_STATE_D 4
  25. #define CP_STATE_E 5
  26. #define CP_STATE_F 6
  27. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  28. struct StatusCodeData *ShmStatusCodeData;
  29. struct PsuData *ShmPsuData ;
  30. struct OCPP16Data *ShmOCPP16Data;
  31. #define MACROSTR(k) #k
  32. //ConfigurationMaxKeys
  33. #define GetConfigurationMaxKeysNUM 43
  34. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  35. char queuedata[2600] = {0};
  36. //=================================
  37. // StatusNotification cycle
  38. //=================================
  39. static int server_cycle_Status = 120;
  40. //===============================
  41. // Configuration: unknownkey
  42. //===============================
  43. static char unknownkey[10][20] = {0};
  44. static int UnknownKeynum = 0;
  45. //===============================
  46. // Gun Total Numbers
  47. //===============================
  48. static int gunTotalNumber = 0;
  49. static unsigned char gunType[4] = {0};
  50. //===============================
  51. // Local List Version
  52. //===============================
  53. static int localversion=0;
  54. static char idTagAuthorization[32] = {0};
  55. //===============================
  56. // OCPP sign variable
  57. //===============================
  58. static int server_sign = FALSE;
  59. int server_pending = FALSE;
  60. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  61. static int BootNotificationInterval = 0;
  62. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  63. //===============================
  64. // OCPP auth variable
  65. //===============================
  66. static int authorizeRetryTimes = 0; //number of Retry times
  67. //===============================
  68. // OCPP other variables
  69. //===============================
  70. //int isUpdateRequest = FALSE;
  71. static int HeartBeatWaitTime = 10;
  72. static int FirstHeartBeat = 0;
  73. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  74. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  75. static char CurrentChargingProfileScheduleStr[30] = {0};
  76. //========================================
  77. // OCPP status/previous related variables
  78. //========================================
  79. static int GunStatusInterval = 10;
  80. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  81. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  82. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  83. static int GbPreviousSystemStatus[GB_QUANTITY];
  84. static int AcPreviousSystemStatus[AC_QUANTITY];
  85. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  86. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  87. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  88. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  89. static int TransactionMessageAttemptsValue = 0;
  90. static int TransactionMessageRetryIntervalValue = 0;
  91. static int TempMeterValueInterval = 0;
  92. static struct OCPPAuthLocalElemet
  93. {
  94. int listVersionInt;
  95. char idTagstr[20];
  96. char parentIdTag[20];
  97. char expiryDate[30];
  98. char idTagstatus[16];
  99. }idTagQuery;
  100. //=============================================
  101. // OCPP HeartBeat Response Not Receive Counts
  102. //============================================
  103. static int HeartBeatWithNOResponse = 0;
  104. static int HeartBeatCountPerHour = 0;
  105. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  106. extern int GetTransactionQueueNum(void);
  107. extern pthread_mutex_t mutex1;
  108. extern struct Charger_Info Charger;
  109. extern sqlite3 *db;
  110. int TransactionMessageAttemptsGet(void);
  111. int TransactionMessageRetryIntervalGet(void);
  112. int GetOcppConnStatus(void);
  113. void SetOcppConnStatus(uint8_t status);
  114. int setKeyValue(char *key, char *value);
  115. void OCPP_get_TableAuthlocalAllData(void);
  116. void processUnkownKey(void);
  117. struct StructOCPPMeterValue
  118. {
  119. unsigned char TimeStamp[28];
  120. struct StructSampledValue SampledValue[10];
  121. };
  122. struct ClientTime
  123. {
  124. unsigned int Heartbeat;
  125. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  126. unsigned int StartTransaction;
  127. unsigned int StopTransaction;
  128. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  129. }clientTime;
  130. typedef union
  131. {
  132. //Operations Initiated by Central System
  133. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  134. struct
  135. {
  136. //CsMsgValue[0]
  137. unsigned char StatusNotificationReq :1; //bit 0,
  138. unsigned char StatusNotificationConf :1; //bit 0,
  139. unsigned char :6; //bit 2~7
  140. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  141. }CpinitiateMsg;
  142. CpinitiateMsg cpinitateMsg;
  143. //==========================================
  144. // Init all Enumeration & Mapping String
  145. //==========================================
  146. /*ChargePointErrorCode*/
  147. typedef enum {
  148. ConnectorLockFailure,
  149. EVCommunicationError,
  150. GroundFailure,
  151. HighTemperature,
  152. InternalError,
  153. LocalListConflict,
  154. NoError,
  155. OtherError,
  156. OverCurrentFailure,
  157. OverVoltage,
  158. PowerMeterFailure,
  159. PowerSwitchFailure,
  160. ReaderFailure,
  161. ResetFailure,
  162. UnderVoltage,
  163. WeakSignal
  164. } ChargePointErrorCode;
  165. #if 0
  166. static char *ChargePointErrorCodeStr[] = {
  167. MACROSTR(ConnectorLockFailure),
  168. MACROSTR(EVCommunicationError),
  169. MACROSTR(GroundFailure),
  170. MACROSTR(HighTemperature),
  171. MACROSTR(InternalError),
  172. MACROSTR(LocalListConflict),
  173. MACROSTR(NoError),
  174. MACROSTR(OtherError),
  175. MACROSTR(OverCurrentFailure),
  176. MACROSTR(OverVoltage),
  177. MACROSTR(PowerMeterFailure),
  178. MACROSTR(PowerSwitchFailure),
  179. MACROSTR(ReaderFailure),
  180. MACROSTR(ResetFailure),
  181. MACROSTR(UnderVoltage),
  182. MACROSTR(WeakSignal)
  183. };
  184. #endif
  185. /*ChargePointStatus*/
  186. typedef enum {
  187. Available =0,
  188. Preparing,
  189. Charging,
  190. SuspendedEVSE,
  191. SuspendedEV,
  192. Finishing,
  193. Reserved,
  194. Unavailable,
  195. Faulted
  196. } ChargePointStatus;
  197. static char * ChargePointStatusStr[] = {
  198. MACROSTR(Available),
  199. MACROSTR(Preparing),
  200. MACROSTR(Charging),
  201. MACROSTR(SuspendedEVSE),
  202. MACROSTR(SuspendedEV),
  203. MACROSTR(Finishing),
  204. MACROSTR(Reserved),
  205. MACROSTR(Unavailable),
  206. MACROSTR(Faulted)
  207. };
  208. /*AvailabilityType*/
  209. typedef enum {
  210. RegistrationStatus_Accepted,
  211. RegistrationStatus_Pending,
  212. RegistrationStatus_Rejected
  213. } RegistrationStatus;
  214. static char *RegistrationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Pending),
  217. MACROSTR(Rejected)
  218. };
  219. /*AvailabilityType*/
  220. typedef enum {
  221. Inoperative,
  222. Operative
  223. } AvailabilityType;
  224. static char *AvailabilityTypeStr[] = {
  225. MACROSTR(Inoperative),
  226. MACROSTR(Operative)
  227. };
  228. /*AvailabilityStatus*/
  229. typedef enum {
  230. Accepted,
  231. Rejected,
  232. Scheduled
  233. } AvailabilityStatus;
  234. static char *AvailabilityStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(Scheduled)
  238. };
  239. /*ConfigurationStatus*/
  240. typedef enum {
  241. ConfigurationStatus_Accepted,
  242. ConfigurationStatus_Rejected,
  243. RebootRequired,
  244. NotSupported
  245. } ConfigurationStatus;
  246. static char *ConfigurationStatusStr[] = {
  247. MACROSTR(Accepted),
  248. MACROSTR(Rejected),
  249. MACROSTR(RebootRequired),
  250. MACROSTR(NotSupported)
  251. };
  252. /*ClearCacheStatus*/
  253. typedef enum {
  254. ClearCacheStatus_Accepted,
  255. ClearCacheStatus_Rejected
  256. } ClearCacheStatus;
  257. static char *ClearCacheStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected)
  260. };
  261. /*ChargingProfilePurposeType*/
  262. typedef enum {
  263. ChargePointMaxProfile,
  264. TxDefaultProfile,
  265. TxProfile
  266. } ChargingProfilePurposeType;
  267. static char *ChargingProfilePurposeTypeStr[] = {
  268. MACROSTR(ChargePointMaxProfile),
  269. MACROSTR(TxDefaultProfile),
  270. MACROSTR(TxProfile)
  271. };
  272. /*ChargingProfileStatus*/
  273. typedef enum {
  274. ChargingProfileStatus_Accepted,
  275. ChargingProfileStatus_Rejected,
  276. ChargingProfileStatus_NotSupported
  277. } ChargingProfileStatus;
  278. static char *ChargingProfileStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Rejected),
  281. MACROSTR(NotSupported)
  282. };
  283. /*ClearChargingProfileStatus*/
  284. typedef enum {
  285. ClearChargingProfileStatus_Accepted,
  286. ClearChargingProfileStatus_Unknown
  287. } ClearChargingProfileStatus;
  288. static char *ClearChargingProfileStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Unknown)
  291. };
  292. /*GetCompositeScheduleStatus*/
  293. typedef enum {
  294. GetCompositeScheduleStatus_Accepted,
  295. GetCompositeScheduleStatus_Rejected
  296. } GetCompositeScheduleStatus;
  297. static char *GetCompositeScheduleStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected)
  300. };
  301. /*ChargingRateUnitType*/
  302. typedef enum {
  303. ChargingRateUnitType_W,
  304. ChargingRateUnitType_A
  305. } ChargingRateUnitType;
  306. /*AuthorizationStatus*/
  307. typedef enum {
  308. AuthorizationStatus_Accepted ,
  309. AuthorizationStatus_Blocked ,
  310. AuthorizationStatus_Expired ,
  311. AuthorizationStatus_Invalid ,
  312. AuthorizationStatus_ConcurrentTx
  313. } AuthorizationStatus;
  314. /*UpdateType*/
  315. typedef enum {
  316. Differential ,
  317. Full
  318. } UpdateType;
  319. static char *UpdateTypeStr[] = {
  320. MACROSTR(Differential),
  321. MACROSTR(Full)
  322. };
  323. /*UpdateStatus*/
  324. typedef enum {
  325. UpdateStatus_Accepted ,
  326. UpdateStatus_Failed ,
  327. UpdateStatus_NotSupported ,
  328. UpdateStatus_VersionMismatch
  329. } UpdateStatus;
  330. static char *UpdateStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Failed),
  333. MACROSTR(NotSupported),
  334. MACROSTR(VersionMismatch)
  335. };
  336. /*RemoteStartStopStatus*/
  337. typedef enum {
  338. RemoteStartStopStatus_Accepted,
  339. RemoteStartStopStatus_Rejected
  340. } RemoteStartStopStatus;
  341. static char *RemoteStartStopStatusStr[] = {
  342. MACROSTR(Accepted),
  343. MACROSTR(Rejected)
  344. };
  345. /*ReservationStatus*/
  346. typedef enum {
  347. ReservationStatus_Accepted,
  348. ReservationStatus_Faulted,
  349. ReservationStatus_Occupied,
  350. ReservationStatus_Rejected,
  351. ReservationStatus_Unavailable
  352. } ReservationStatus;
  353. static char *ReservationStatusStr[] = {
  354. MACROSTR(Accepted),
  355. MACROSTR(Faulted),
  356. MACROSTR(Occupied),
  357. MACROSTR(Rejected),
  358. MACROSTR(Unavailable)
  359. };
  360. /*ResetType*/
  361. typedef enum {
  362. Hard,
  363. Soft
  364. } ResetType;
  365. static char *ResetTypeStr[] = {
  366. MACROSTR(Hard),
  367. MACROSTR(Soft)
  368. };
  369. /*ResetStatus*/
  370. typedef enum {
  371. ResetStatus_Accepted,
  372. ResetStatus_Rejected
  373. } ResetStatus;
  374. static char *ResetStatusStr[] = {
  375. MACROSTR(Accepted),
  376. MACROSTR(Rejected)
  377. };
  378. /*DiagnosticsStatus*/
  379. typedef enum {
  380. DiagnosticsStatus_Idle,
  381. DiagnosticsStatus_Uploaded,
  382. DiagnosticsStatus_UploadFailed,
  383. DiagnosticsStatus_Uploading
  384. } DiagnosticsStatus;
  385. static char * DiagnosticsStatusStr[] = {
  386. MACROSTR(Idle),
  387. MACROSTR(Uploaded),
  388. MACROSTR(UploadFailed),
  389. MACROSTR(Uploading)
  390. };
  391. /*FirmwareStatus*/
  392. typedef enum {
  393. FirmwareStatus_Downloaded,
  394. FirmwareStatus_DownloadFailed,
  395. FirmwareStatus_Downloading,
  396. FirmwareStatus_Idle,
  397. FirmwareStatus_InstallationFailed,
  398. FirmwareStatus_Installing,
  399. FirmwareStatus_Installed
  400. } FirmwareStatus;
  401. static char * FirmwareStatusStr[] = {
  402. MACROSTR(Downloaded),
  403. MACROSTR(DownloadFailed),
  404. MACROSTR(Downloading),
  405. MACROSTR(Idle),
  406. MACROSTR(InstallationFailed),
  407. MACROSTR(Installing),
  408. MACROSTR(Installed)
  409. };
  410. /*MessageTrigger*/
  411. typedef enum {
  412. BootNotification,
  413. DiagnosticsStatusNotification,
  414. FirmwareStatusNotification,
  415. Heartbeat,
  416. MeterValues,
  417. StatusNotification
  418. } MessageTrigger;
  419. static char * MessageTriggerStr[] = {
  420. MACROSTR(BootNotification),
  421. MACROSTR(DiagnosticsStatusNotification),
  422. MACROSTR(FirmwareStatusNotification),
  423. MACROSTR(Heartbeat),
  424. MACROSTR(MeterValues),
  425. MACROSTR(StatusNotification)
  426. };
  427. /*TriggerMessageStatus*/
  428. typedef enum {
  429. TriggerMessageStatus_Accepted ,
  430. TriggerMessageStatus_Rejected ,
  431. TriggerMessageStatus_NotImplemented
  432. } TriggerMessageStatus;
  433. static char * TriggerMessageStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected),
  436. MACROSTR(NotImplemented)
  437. };
  438. /*UnlockStatus*/
  439. typedef enum {
  440. Unlocked,
  441. UnlockFailed,
  442. UnlockStatus_NotSupported
  443. } UnlockStatus;
  444. static char * UnlockStatusStr[] = {
  445. MACROSTR(Unlocked),
  446. MACROSTR(UnlockFailed),
  447. MACROSTR(NotSupported)
  448. };
  449. /*StopTransactionReason*/
  450. typedef enum {
  451. EmergencyStop,
  452. EVDisconnected,
  453. HardReset,
  454. Local,
  455. Other,
  456. PowerLoss,
  457. Reboot,
  458. Remote,
  459. SoftReset,
  460. UnlockCommand,
  461. DeAuthorized
  462. } StopTransactionReason;
  463. #if 0
  464. static char * StopTransactionReasonStr[] = {
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EVDisconnected),
  467. MACROSTR(HardReset),
  468. MACROSTR(Local),
  469. MACROSTR(Other),
  470. MACROSTR(PowerLoss),
  471. MACROSTR(Reboot),
  472. MACROSTR(Remote),
  473. MACROSTR(SoftReset),
  474. MACROSTR(UnlockCommand),
  475. MACROSTR(DeAuthorized)
  476. };
  477. #endif
  478. /*CancelReservationStatus*/
  479. typedef enum {
  480. CancelReservationStatus_Accepted,
  481. CancelReservationStatus_Rejected
  482. } CancelReservationStatus;
  483. static char * CancelReservationStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected)
  486. };
  487. /*ReadingContext*/
  488. typedef enum {
  489. ReadingContext_Interruption_Begin,
  490. ReadingContext_Interruption_End,
  491. ReadingContext_Other,
  492. ReadingContext_Sample_Clock,
  493. ReadingContext_Sample_Periodic ,
  494. ReadingContext_Transaction_Begin ,
  495. ReadingContext_Transaction_End,
  496. ReadingContext_Trigger
  497. } ReadingContext;
  498. static char * ReadingContextStr[] = {
  499. MACROSTR(Interruption.Begin),
  500. MACROSTR(Interruption.End),
  501. MACROSTR(Other),
  502. MACROSTR(Sample.Clock),
  503. MACROSTR(Sample.Periodic),
  504. MACROSTR(Transaction.Begin),
  505. MACROSTR(Transaction.End),
  506. MACROSTR(Trigger)
  507. };
  508. /*ValueFormat*/
  509. typedef enum {
  510. Raw,
  511. SignedData
  512. } ValueFormat;
  513. static char * ValueFormatStr[] = {
  514. MACROSTR(Raw),
  515. MACROSTR(SignedData)
  516. };
  517. /*Measurand*/
  518. typedef enum {
  519. Current_Export ,
  520. Current_Import,
  521. Current_Offered,
  522. Energy_Active_Export_Register,
  523. Energy_Active_Import_Register,
  524. Energy_Reactive_Export_Register,
  525. Energy_Reactive_Import_Register,
  526. Energy_Active_Export_Interval,
  527. Energy_Active_Import_Interval,
  528. Energy_Reactive_Export_Interval,
  529. Energy_Reactive_Import_Interval,
  530. Frequency,
  531. Power_Active_Export ,
  532. Power_Active_Import,
  533. Power_Factor,
  534. Power_Offered,
  535. Power_Reactive_Export,
  536. Power_Reactive_Import,
  537. RPM,
  538. SoC,
  539. Temperature ,
  540. Voltage
  541. } Measurand;
  542. static char * MeasurandStr[] = {
  543. MACROSTR(Current.Export),
  544. MACROSTR(Current.Import),
  545. MACROSTR(Current.Offered),
  546. MACROSTR(Energy.Active.Export.Register),
  547. MACROSTR(Energy.Active.Import.Register),
  548. MACROSTR(Energy.Reactive.Export.Register),
  549. MACROSTR(Energy.Reactive.Import.Register),
  550. MACROSTR(Energy.Active.Export.Interval),
  551. MACROSTR(Energy.Active.Import.Interval),
  552. MACROSTR(Energy.Reactive.Export.Interval),
  553. MACROSTR(Energy.Reactive.Import.Interval),
  554. MACROSTR(Frequency),
  555. MACROSTR(Power.Active.Export),
  556. MACROSTR(Power.Active.Import),
  557. MACROSTR(Power.Factor),
  558. MACROSTR(Power.Offered),
  559. MACROSTR(Power.Reactive.ExportMACROSTR),
  560. MACROSTR(Power.Reactive.Import),
  561. MACROSTR(RPM),
  562. MACROSTR(SoC),
  563. MACROSTR(Temperature),
  564. MACROSTR(Voltage)
  565. };
  566. /*Location*/
  567. typedef enum {
  568. Location_Body,
  569. Location_Cable,
  570. Location_EV,
  571. Location_Inlet ,
  572. Location_Outlet
  573. } Location;
  574. static char * LocationStr[] = {
  575. MACROSTR(Body),
  576. MACROSTR(Cable),
  577. MACROSTR(EV),
  578. MACROSTR(Inlet),
  579. MACROSTR(Outlet)
  580. };
  581. /*Phase*/
  582. typedef enum {
  583. L1,
  584. L2,
  585. L3,
  586. N,
  587. L1_N,
  588. L2_N,
  589. L3_N,
  590. L1_L2,
  591. L2_L3,
  592. L3_L1
  593. } Phase;
  594. static char * PhaseStr[] = {
  595. MACROSTR(L1),
  596. MACROSTR(L2),
  597. MACROSTR(L3),
  598. MACROSTR(N),
  599. MACROSTR(L1-N),
  600. MACROSTR(L2-N),
  601. MACROSTR(L3-N),
  602. MACROSTR(L1-L2),
  603. MACROSTR(L2-L3),
  604. MACROSTR(L3-L1)
  605. };
  606. /*UnitOfMeasure*/
  607. typedef enum {
  608. UnitOfMeasure_Wh,
  609. UnitOfMeasure_kWh ,
  610. UnitOfMeasure_varh ,
  611. UnitOfMeasure_kvarh ,
  612. UnitOfMeasure_W ,
  613. UnitOfMeasure_kW ,
  614. UnitOfMeasure_VA ,
  615. UnitOfMeasure_kVA ,
  616. UnitOfMeasure_var ,
  617. UnitOfMeasure_kvar ,
  618. UnitOfMeasure_A ,
  619. UnitOfMeasure_V ,
  620. UnitOfMeasure_Celsius ,
  621. UnitOfMeasure_Fahrenheit ,
  622. UnitOfMeasure_K ,
  623. UnitOfMeasure_Percent
  624. } UnitOfMeasure;
  625. static char * UnitOfMeasureStr[] = {
  626. MACROSTR(Wh),
  627. MACROSTR(kWh),
  628. MACROSTR(varh),
  629. MACROSTR(kvarh),
  630. MACROSTR(W),
  631. MACROSTR(kW),
  632. MACROSTR(VA),
  633. MACROSTR(kVA),
  634. MACROSTR(var),
  635. MACROSTR(kvar),
  636. MACROSTR(A),
  637. MACROSTR(V),
  638. MACROSTR(Celsius),
  639. MACROSTR(Fahrenheit),
  640. MACROSTR(K),
  641. MACROSTR(Percent)
  642. };
  643. enum LocalAuthListManagementProfile{
  644. LocalAuthListEnabled=0,
  645. LocalAuthListMaxLength,
  646. SendLocalListMaxLength,
  647. _LocalAuthListManagementProfile_CNT
  648. };
  649. enum ReservationProfile{
  650. ReserveConnectorZeroSupported
  651. };
  652. enum SmartChargingProfile{
  653. ChargeProfileMaxStackLevel,
  654. ChargingScheduleAllowedChargingRateUnit,
  655. ChargingScheduleMaxPeriods,
  656. ConnectorSwitch3to1PhaseSupported,
  657. MaxChargingProfilesInstalled
  658. };
  659. enum ChargerSystemStatus{
  660. ChargerSystemStatus_Booting,
  661. ChargerSystemStatus_Idle,
  662. ChargerSystemStatus_Authorizing,
  663. ChargerSystemStatus_Preparing,
  664. ChargerSystemStatus_Charging,
  665. ChargerSystemStatus_Terminating,
  666. ChargerSystemStatus_Alarm,
  667. ChargerSystemStatus_Fault
  668. };
  669. enum GetConfigurationKey {
  670. GetConfiguration_AllowOfflineTxForUnknownId=0,
  671. GetConfiguration_AuthorizationCacheEnabled,
  672. GetConfiguration_AuthorizeRemoteTxRequests,
  673. GetConfiguration_BlinkRepeat,
  674. GetConfiguration_ClockAlignedDataInterval,
  675. GetConfiguration_ConnectionTimeOut,
  676. GetConfiguration_GetConfigurationMaxKeys,
  677. GetConfiguration_HeartbeatInterval,
  678. GetConfiguration_LightIntensity,
  679. GetConfiguration_LocalAuthorizeOffline,
  680. GetConfiguration_LocalPreAuthorize,
  681. GetConfiguration_MaxEnergyOnInvalidId,
  682. GetConfiguration_MeterValuesAlignedData,
  683. GetConfiguration_MeterValuesAlignedDataMaxLength,
  684. GetConfiguration_MeterValuesSampledData,
  685. GetConfiguration_MeterValuesSampledDataMaxLength,
  686. GetConfiguration_MeterValueSampleInterval,
  687. GetConfiguration_MinimumStatusDuration,
  688. GetConfiguration_NumberOfConnectors,
  689. GetConfiguration_ResetRetries,
  690. GetConfiguration_ConnectorPhaseRotation,
  691. GetConfiguration_ConnectorPhaseRotationMaxLength,
  692. GetConfiguration_StopTransactionOnEVSideDisconnect,
  693. GetConfiguration_StopTransactionOnInvalidId,
  694. GetConfiguration_StopTxnAlignedData,
  695. GetConfiguration_StopTxnAlignedDataMaxLength,
  696. GetConfiguration_StopTxnSampledData,
  697. GetConfiguration_StopTxnSampledDataMaxLength,
  698. GetConfiguration_SupportedFeatureProfiles,
  699. GetConfiguration_SupportedFeatureProfilesMaxLength,
  700. GetConfiguration_TransactionMessageAttempts,
  701. GetConfiguration_TransactionMessageRetryInterval,
  702. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  703. GetConfiguration_WebSocketPingInterval,
  704. GetConfiguration_LocalAuthListEnabled,
  705. GetConfiguration_LocalAuthListMaxLength,
  706. GetConfiguration_SendLocalListMaxLength,
  707. GetConfiguration_ReserveConnectorZeroSupported,
  708. GetConfiguration_ChargeProfileMaxStackLevel,
  709. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  710. GetConfiguration_ChargingScheduleMaxPeriods,
  711. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  712. GetConfiguration_MaxChargingProfilesInstalled,
  713. };
  714. //GetConfiguration Array
  715. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  717. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  718. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  719. //==========================================
  720. // GetCompositeSchedule logic related function
  721. //==========================================
  722. int DiffTimebSec(struct timeb ST, struct timeb ET)
  723. {
  724. //return milli-second
  725. unsigned int StartTime,StopTime;
  726. StartTime=(unsigned int)ST.time;
  727. StopTime=(unsigned int)ET.time;
  728. return (StopTime-StartTime);
  729. }
  730. int DiffTimebWithNowSec(struct timeb ST)
  731. {
  732. //return milli-second
  733. struct timeb ET;
  734. unsigned int StartTime,StopTime;
  735. ftime(&ET);
  736. StartTime=(unsigned int)ST.time;
  737. StopTime=(unsigned int)ET.time;
  738. return (StopTime-StartTime);
  739. }
  740. int getStartStop(uint8_t *start, uint8_t *stop)
  741. {
  742. int result = -1;
  743. struct tm tmStart;
  744. struct timeb tbStart;
  745. struct tm tmStop;
  746. struct timeb tbStop;
  747. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  748. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  749. {
  750. tmStart.tm_year -= 1900;
  751. tmStart.tm_mon -= 1;
  752. tbStart.time = mktime(&tmStart);
  753. tbStart.millitm = 0;
  754. tmStop.tm_year -= 1900;
  755. tmStop.tm_mon -= 1;
  756. tbStop.time = mktime(&tmStop);
  757. tbStop.millitm = 0;
  758. result = DiffTimebSec(tbStart, tbStop);
  759. }
  760. else
  761. {
  762. DEBUG_WARN("Start or stop date parsing error.\r\n");
  763. }
  764. return result;
  765. }
  766. int getStartSinceToday(uint8_t *stop)
  767. {
  768. int result = -1;
  769. time_t t;
  770. struct tm *tmStartToday;
  771. struct timeb tbStartToday;
  772. struct tm tmStop;
  773. struct timeb tbStop;
  774. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  775. {
  776. t=time(NULL);
  777. tmStartToday=localtime(&t);
  778. tmStartToday->tm_hour = 0;
  779. tmStartToday->tm_min = 0;
  780. tmStartToday->tm_sec = 0;
  781. tbStartToday.time = mktime(tmStartToday);
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStartToday, tbStop);
  787. }
  788. return result;
  789. }
  790. int getStartSinceWeek(uint8_t *stop)
  791. {
  792. int result = -1;
  793. time_t t;
  794. struct tm *tmStartWeek;
  795. struct timeb tbStartWeek;
  796. struct tm tmStop;
  797. struct timeb tbStop;
  798. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  799. {
  800. t=time(NULL);
  801. tmStartWeek=localtime(&t);
  802. t-=86400*tmStartWeek->tm_wday;
  803. tmStartWeek=localtime(&t);
  804. tmStartWeek->tm_hour = 0;
  805. tmStartWeek->tm_min = 0;
  806. tmStartWeek->tm_sec = 0;
  807. tbStartWeek.time = mktime(tmStartWeek);
  808. tmStop.tm_year -= 1900;
  809. tmStop.tm_mon -= 1;
  810. tbStop.time = mktime(&tmStop);
  811. tbStop.millitm = 0;
  812. result = DiffTimebSec(tbStartWeek, tbStop);
  813. }
  814. return result;
  815. }
  816. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  817. {
  818. FILE *fp;
  819. char profileFileName[128];
  820. char *line = NULL;
  821. size_t len = 0;
  822. time_t CurrentTime;
  823. struct tm *tmComposite;
  824. struct StructChargingProfile maxProfile;
  825. struct StructChargingProfile defaultTxProfile;
  826. struct StructChargingProfile txProfile;
  827. struct StructChargingSchedulePeriod tmpPeriod;
  828. uint8_t limitMax=0;
  829. uint8_t limitDef=0;
  830. uint8_t limitTx=0;
  831. int compositePeriodIdx = 0;
  832. CurrentTime = time(NULL);
  833. tmComposite=localtime(&CurrentTime);
  834. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  835. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  836. compositeProfile->ChargingSchedule.Duration = durationReq;
  837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  838. {
  839. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  840. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  841. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  842. }
  843. compositeProfile->ChargingProfileId = 1;
  844. compositeProfile->StackLevel = 99 ;
  845. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  846. maxProfile.ChargingProfileId = -1;
  847. defaultTxProfile.ChargingProfileId = -1;
  848. txProfile.ChargingProfileId = -1;
  849. system("yes|rm /tmp/*.json");
  850. system("cp /Storage/OCPP/*.json /tmp");
  851. /*
  852. * Search valid charging profile
  853. */
  854. //DEBUG_INFO("====================================\n");
  855. // Search max profile
  856. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  857. if((access(profileFileName, F_OK))!=-1)
  858. {
  859. fp = fopen(profileFileName, "r");
  860. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  861. {
  862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  863. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  864. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  865. }
  866. maxProfile.ChargingProfileId = -1;
  867. maxProfile.StackLevel = -1;
  868. while(getline(&line, &len, fp) != -1)
  869. {
  870. json_object *obj = NULL;
  871. obj = json_tokener_parse(line);
  872. if(is_error(obj))
  873. {
  874. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  875. }
  876. else
  877. {
  878. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  879. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  880. )
  881. {
  882. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  883. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  884. )
  885. {
  886. struct tm tmFrom, tmTo;
  887. struct timeb tbFrom, tbTo;
  888. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  889. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  890. {
  891. tmFrom.tm_year -= 1900;
  892. tmFrom.tm_mon -= 1;
  893. tbFrom.time = mktime(&tmFrom);
  894. tmTo.tm_year -= 1900;
  895. tmTo.tm_mon -= 1;
  896. tbTo.time = mktime(&tmTo);
  897. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  898. {
  899. if(maxProfile.ChargingProfileId == -1)
  900. DEBUG_INFO("MaxProfile found.\n");
  901. else
  902. DEBUG_INFO("MaxProfile updated.\n");
  903. // Required item
  904. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  905. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  906. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  907. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  908. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  909. {
  910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  913. 3:
  914. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  915. }
  916. // Optional item
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  918. {
  919. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  920. }
  921. else
  922. {
  923. sprintf((char*)maxProfile.ValidFrom, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  926. {
  927. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  928. }
  929. else
  930. {
  931. sprintf((char*)maxProfile.ValidTo, " ");
  932. }
  933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  934. {
  935. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  936. }
  937. else
  938. {
  939. sprintf((char*)maxProfile.RecurrencyKind, " ");
  940. }
  941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  942. {
  943. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  944. }
  945. else
  946. {
  947. maxProfile.TransactionId = -1;
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  950. {
  951. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  952. }
  953. else
  954. {
  955. maxProfile.ChargingSchedule.Duration = -1;
  956. }
  957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  958. {
  959. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  960. }
  961. else
  962. {
  963. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  966. {
  967. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  968. }
  969. else
  970. {
  971. maxProfile.ChargingSchedule.MinChargingRate = -1;
  972. }
  973. }
  974. }
  975. }
  976. else
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  987. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  988. {
  989. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  990. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  991. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  992. 3:
  993. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  994. }
  995. // Optional item
  996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  997. {
  998. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  999. }
  1000. else
  1001. {
  1002. sprintf((char*)maxProfile.ValidFrom, " ");
  1003. }
  1004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1005. {
  1006. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1007. }
  1008. else
  1009. {
  1010. sprintf((char*)maxProfile.ValidTo, " ");
  1011. }
  1012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1013. {
  1014. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1015. }
  1016. else
  1017. {
  1018. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1019. }
  1020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1021. {
  1022. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1023. }
  1024. else
  1025. {
  1026. maxProfile.TransactionId = -1;
  1027. }
  1028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1029. {
  1030. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1031. }
  1032. else
  1033. {
  1034. maxProfile.ChargingSchedule.Duration = -1;
  1035. }
  1036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1037. {
  1038. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1039. }
  1040. else
  1041. {
  1042. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1043. }
  1044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1045. {
  1046. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1047. }
  1048. else
  1049. {
  1050. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1051. }
  1052. }
  1053. }
  1054. }
  1055. json_object_put(obj);
  1056. }
  1057. fclose(fp);
  1058. /*
  1059. if(maxProfile.ChargingProfileId !=-1)
  1060. {
  1061. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1062. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1063. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1064. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1065. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1067. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1068. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1069. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1070. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1071. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1073. {
  1074. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1075. {
  1076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1079. }
  1080. }
  1081. }
  1082. else
  1083. DEBUG_INFO("MaxProfile not found.\n");
  1084. DEBUG_INFO("------------------------------------\n");*/
  1085. }
  1086. // Search default tx profile
  1087. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1088. if((access(profileFileName, F_OK))==-1)
  1089. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1090. if((access(profileFileName, F_OK))!=-1)
  1091. {
  1092. fp = fopen(profileFileName, "r");
  1093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1094. {
  1095. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1096. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1097. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1098. }
  1099. defaultTxProfile.ChargingProfileId = -1;
  1100. defaultTxProfile.StackLevel = -1;
  1101. while(getline(&line, &len, fp) != -1)
  1102. {
  1103. json_object *obj = NULL;
  1104. obj = json_tokener_parse(line);
  1105. if(is_error(obj))
  1106. {
  1107. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1108. }
  1109. else
  1110. {
  1111. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1112. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1113. )
  1114. {
  1115. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1116. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1117. )
  1118. {
  1119. struct tm tmFrom, tmTo;
  1120. struct timeb tbFrom, tbTo;
  1121. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1122. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1123. {
  1124. tmFrom.tm_year -= 1900;
  1125. tmFrom.tm_mon -= 1;
  1126. tbFrom.time = mktime(&tmFrom);
  1127. tmTo.tm_year -= 1900;
  1128. tmTo.tm_mon -= 1;
  1129. tbTo.time = mktime(&tmTo);
  1130. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1131. {
  1132. if(defaultTxProfile.ChargingProfileId == -1)
  1133. DEBUG_INFO("TxDefaultProfile found.\n");
  1134. else
  1135. DEBUG_INFO("TxDefaultProfile updated.\n");
  1136. // Required item
  1137. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1138. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1139. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1140. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1141. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1142. {
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1144. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1145. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1146. 3:
  1147. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1148. }
  1149. // Optional item
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1151. {
  1152. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1159. {
  1160. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1161. }
  1162. else
  1163. {
  1164. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1165. }
  1166. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1167. {
  1168. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1173. }
  1174. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1175. {
  1176. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1177. }
  1178. else
  1179. {
  1180. defaultTxProfile.TransactionId = -1;
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1183. {
  1184. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1185. }
  1186. else
  1187. {
  1188. defaultTxProfile.ChargingSchedule.Duration = -1;
  1189. }
  1190. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1191. {
  1192. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1193. }
  1194. else
  1195. {
  1196. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1197. }
  1198. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1199. {
  1200. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1201. }
  1202. else
  1203. {
  1204. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(defaultTxProfile.ChargingProfileId == -1)
  1212. DEBUG_INFO("TxDefaultProfile found.\n");
  1213. else
  1214. DEBUG_INFO("TxDefaultProfile updated.\n");
  1215. // Required item
  1216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1219. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1220. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1221. {
  1222. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1223. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1224. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1225. 3:
  1226. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1227. }
  1228. // Optional item
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1230. {
  1231. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1232. }
  1233. else
  1234. {
  1235. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1236. }
  1237. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1238. {
  1239. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1240. }
  1241. else
  1242. {
  1243. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1244. }
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1246. {
  1247. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1254. {
  1255. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.TransactionId = -1;
  1260. }
  1261. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1262. {
  1263. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1264. }
  1265. else
  1266. {
  1267. defaultTxProfile.ChargingSchedule.Duration = -1;
  1268. }
  1269. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1270. {
  1271. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. json_object_put(obj);
  1289. }
  1290. fclose(fp);
  1291. /*
  1292. if(defaultTxProfile.ChargingProfileId != -1)
  1293. {
  1294. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1295. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1296. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1297. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1298. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1299. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1300. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1301. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1302. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1303. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1304. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1308. {
  1309. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1310. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1311. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1312. }
  1313. }
  1314. }
  1315. else
  1316. DEBUG_INFO("TxDefaultProfile not found.\n");
  1317. DEBUG_INFO("------------------------------------\n");*/
  1318. }
  1319. // Search tx profile
  1320. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1321. if((access(profileFileName, F_OK))!=-1)
  1322. {
  1323. fp = fopen(profileFileName, "r");
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1327. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1329. }
  1330. txProfile.ChargingProfileId = -1;
  1331. txProfile.StackLevel = -1;
  1332. while(getline(&line, &len, fp) != -1)
  1333. {
  1334. json_object *obj = NULL;
  1335. obj = json_tokener_parse(line);
  1336. if(is_error(obj))
  1337. {
  1338. DEBUG_ERROR("Parse txProfile from file error.\n");
  1339. }
  1340. else
  1341. {
  1342. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1343. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1344. )
  1345. {
  1346. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1347. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. )
  1349. {
  1350. struct tm tmFrom, tmTo;
  1351. struct timeb tbFrom, tbTo;
  1352. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1353. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1354. {
  1355. tmFrom.tm_year -= 1900;
  1356. tmFrom.tm_mon -= 1;
  1357. tbFrom.time = mktime(&tmFrom);
  1358. tmTo.tm_year -= 1900;
  1359. tmTo.tm_mon -= 1;
  1360. tbTo.time = mktime(&tmTo);
  1361. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1362. {
  1363. if(txProfile.ChargingProfileId == -1)
  1364. DEBUG_INFO("TxProfile found.\n");
  1365. else
  1366. DEBUG_INFO("TxProfile updated.\n");
  1367. // Required item
  1368. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1369. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1370. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1371. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1372. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1373. {
  1374. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1375. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1376. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1377. 3:
  1378. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1379. }
  1380. // Optional item
  1381. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1382. {
  1383. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1384. }
  1385. else
  1386. {
  1387. sprintf((char*)txProfile.ValidFrom, " ");
  1388. }
  1389. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1390. {
  1391. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1392. }
  1393. else
  1394. {
  1395. sprintf((char*)txProfile.ValidTo, " ");
  1396. }
  1397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1398. {
  1399. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1400. }
  1401. else
  1402. {
  1403. sprintf((char*)txProfile.RecurrencyKind, " ");
  1404. }
  1405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1406. {
  1407. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1408. }
  1409. else
  1410. {
  1411. txProfile.TransactionId = -1;
  1412. }
  1413. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1414. {
  1415. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1416. }
  1417. else
  1418. {
  1419. txProfile.ChargingSchedule.Duration = -1;
  1420. }
  1421. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1422. {
  1423. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1428. }
  1429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1430. {
  1431. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1432. }
  1433. else
  1434. {
  1435. txProfile.ChargingSchedule.MinChargingRate = -1;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if(txProfile.ChargingProfileId == -1)
  1443. DEBUG_INFO("TxProfile found.\n");
  1444. else
  1445. DEBUG_INFO("TxProfile updated.\n");
  1446. // Required item
  1447. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1448. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1449. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1450. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1451. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1452. {
  1453. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1455. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1456. 3:
  1457. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1458. }
  1459. // Optional item
  1460. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1461. {
  1462. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)txProfile.ValidFrom, " ");
  1467. }
  1468. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1469. {
  1470. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1471. }
  1472. else
  1473. {
  1474. sprintf((char*)txProfile.ValidTo, " ");
  1475. }
  1476. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1477. {
  1478. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)txProfile.RecurrencyKind, " ");
  1483. }
  1484. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1485. {
  1486. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1487. }
  1488. else
  1489. {
  1490. txProfile.TransactionId = -1;
  1491. }
  1492. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1493. {
  1494. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1495. }
  1496. else
  1497. {
  1498. txProfile.ChargingSchedule.Duration = -1;
  1499. }
  1500. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1501. {
  1502. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1509. {
  1510. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1511. }
  1512. else
  1513. {
  1514. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. json_object_put(obj);
  1520. }
  1521. fclose(fp);
  1522. /*
  1523. if(defaultTxProfile.ChargingProfileId != -1)
  1524. {
  1525. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1526. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1527. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1528. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1529. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1530. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1531. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1532. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1533. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1534. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1535. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1537. {
  1538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1539. {
  1540. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1541. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1542. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1543. }
  1544. }
  1545. }
  1546. else
  1547. DEBUG_INFO("TxProfile not found.\n");*/
  1548. }
  1549. /*
  1550. * Align found profile start schedule & periods
  1551. */
  1552. //DEBUG_INFO("====================================\n");
  1553. /*
  1554. // For local test usage, force modify found profile start schedule info
  1555. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1556. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1557. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1558. */
  1559. if(maxProfile.ChargingProfileId != -1)
  1560. {
  1561. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1562. {
  1563. if(maxProfile.ChargingSchedule.Duration != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1568. }
  1569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1574. 0:
  1575. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1576. }
  1577. }
  1578. }
  1579. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1600. {
  1601. if(maxProfile.ChargingSchedule.Duration != -1)
  1602. {
  1603. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1604. 0:
  1605. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1606. }
  1607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1608. {
  1609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1610. {
  1611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. }
  1616. }
  1617. else
  1618. {
  1619. if(maxProfile.ChargingSchedule.Duration != -1)
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1622. 0:
  1623. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1624. }
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1628. {
  1629. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1630. 0:
  1631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1632. }
  1633. }
  1634. }
  1635. }
  1636. /*
  1637. DEBUG_INFO("MaxProfile after align.\n");
  1638. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1639. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1640. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1641. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1642. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1643. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1644. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1645. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1646. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1647. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1648. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1650. {
  1651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1652. {
  1653. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1654. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1655. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1656. }
  1657. }
  1658. DEBUG_INFO("------------------------------------\n");*/
  1659. }
  1660. if(defaultTxProfile.ChargingProfileId != -1)
  1661. {
  1662. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1663. {
  1664. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1665. {
  1666. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1667. 0:
  1668. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1669. }
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1673. {
  1674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1675. 0:
  1676. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1677. }
  1678. }
  1679. }
  1680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1681. {
  1682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1683. {
  1684. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1685. 0:
  1686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1687. }
  1688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1689. {
  1690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1691. {
  1692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1693. 0:
  1694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1701. {
  1702. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1703. {
  1704. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1705. 0:
  1706. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1707. }
  1708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1711. {
  1712. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1733. }
  1734. }
  1735. }
  1736. }
  1737. /*
  1738. DEBUG_INFO("defaultTxProfile after align.\n");
  1739. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1740. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1741. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1742. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1743. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1744. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1745. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1746. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1747. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1748. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1749. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1753. {
  1754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1757. }
  1758. }
  1759. DEBUG_INFO("------------------------------------\n");*/
  1760. }
  1761. if(txProfile.ChargingProfileId != -1)
  1762. {
  1763. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1764. {
  1765. if(txProfile.ChargingSchedule.Duration != -1)
  1766. {
  1767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1768. 0:
  1769. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1770. }
  1771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1772. {
  1773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1774. {
  1775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1776. 0:
  1777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1778. }
  1779. }
  1780. }
  1781. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1782. {
  1783. if(txProfile.ChargingSchedule.Duration != -1)
  1784. {
  1785. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1786. 0:
  1787. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1788. }
  1789. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1790. {
  1791. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1794. 0:
  1795. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1796. }
  1797. }
  1798. }
  1799. else
  1800. {
  1801. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1802. {
  1803. if(txProfile.ChargingSchedule.Duration != -1)
  1804. {
  1805. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1808. }
  1809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1814. 0:
  1815. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1834. }
  1835. }
  1836. }
  1837. }
  1838. /*
  1839. DEBUG_INFO("txProfile after align.\n");
  1840. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1841. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1842. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1843. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1844. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1845. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1846. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1847. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1848. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1849. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1850. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1856. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1857. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1858. }
  1859. }*/
  1860. }
  1861. /*
  1862. * Merge to conposite schedule
  1863. */
  1864. //DEBUG_INFO("====================================\n");
  1865. // Find each profile period quantity
  1866. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1867. {
  1868. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1869. limitMax = idx+1;
  1870. }
  1871. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1872. {
  1873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1874. limitDef = idx+1;
  1875. }
  1876. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1877. {
  1878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1879. limitTx = idx+1;
  1880. }
  1881. // TxProfile found, composite schedule based on it
  1882. if(txProfile.ChargingProfileId != -1)
  1883. {
  1884. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1885. {
  1886. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1887. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1888. {
  1889. if(maxProfile.ChargingProfileId != -1)
  1890. {
  1891. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1892. {
  1893. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1894. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1895. {
  1896. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1897. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1898. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1899. }
  1900. if(idxMaxPeriod == (limitMax-1))
  1901. {
  1902. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1903. {
  1904. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1905. {
  1906. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1907. compositePeriodIdx++;
  1908. }
  1909. else
  1910. {
  1911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. compositePeriodIdx++;
  1923. }
  1924. else
  1925. {
  1926. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1927. }
  1928. }
  1929. }
  1930. if(idxTxPeriod == (limitTx-1))
  1931. {
  1932. if(defaultTxProfile.ChargingProfileId != -1)
  1933. {
  1934. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1935. {
  1936. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1937. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1938. {
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1942. {
  1943. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1944. {
  1945. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1946. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1947. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1949. {
  1950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1951. {
  1952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1953. compositePeriodIdx++;
  1954. }
  1955. else
  1956. {
  1957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1958. }
  1959. }
  1960. break;
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1967. {
  1968. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1969. compositePeriodIdx++;
  1970. }
  1971. else
  1972. {
  1973. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1983. else if(defaultTxProfile.ChargingProfileId != -1)
  1984. {
  1985. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1986. {
  1987. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1988. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1989. {
  1990. if(maxProfile.ChargingProfileId != -1)
  1991. {
  1992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1995. {
  1996. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1997. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1998. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1999. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2000. {
  2001. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2002. {
  2003. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2004. compositePeriodIdx++;
  2005. }
  2006. else
  2007. {
  2008. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2009. }
  2010. }
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. else
  2016. {
  2017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2018. {
  2019. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2020. compositePeriodIdx++;
  2021. }
  2022. else
  2023. {
  2024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. // Fill other period by MaxProfile
  2031. if(maxProfile.ChargingProfileId != -1)
  2032. {
  2033. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2034. {
  2035. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2036. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2037. {
  2038. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2039. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2040. {
  2041. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2042. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2043. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2044. }
  2045. if(idxMaxPeriod == (limitMax-1))
  2046. {
  2047. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2048. {
  2049. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2050. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2051. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2052. }
  2053. if(tmpPeriod.Limit != -1)
  2054. {
  2055. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2056. {
  2057. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2058. {
  2059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2060. compositePeriodIdx++;
  2061. }
  2062. else
  2063. {
  2064. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2073. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2074. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2078. {
  2079. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2080. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2081. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2082. }
  2083. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2084. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2085. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2086. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2087. }
  2088. if(line)
  2089. free(line);
  2090. }
  2091. //==========================================
  2092. // Init all share memory
  2093. //==========================================
  2094. int InitShareMemory()
  2095. {
  2096. int result = PASS;
  2097. int MeterSMId;
  2098. //creat ShmSysConfigAndInfo
  2099. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2100. {
  2101. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2102. result = FAIL;
  2103. }
  2104. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2105. {
  2106. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2107. result = FAIL;
  2108. }
  2109. else
  2110. {}
  2111. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2112. {
  2113. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2114. result = FAIL;
  2115. }
  2116. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2117. {
  2118. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2119. result = FAIL;
  2120. }
  2121. else
  2122. {}
  2123. //creat ShmPsuData
  2124. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2125. {
  2126. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2127. result = FAIL;
  2128. }
  2129. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2130. {
  2131. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2132. result = FAIL;
  2133. }
  2134. else
  2135. {}
  2136. //creat ShmOCPP16Data
  2137. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2138. {
  2139. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2140. result = FAIL;
  2141. }
  2142. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2143. {
  2144. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2145. result = FAIL;
  2146. }
  2147. else
  2148. {}
  2149. /****************************** For Initial Settings************************************************/
  2150. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2151. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2152. // allocate Configuration memory address
  2153. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2154. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2155. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2156. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2157. //offline MeterValue Interval
  2158. TempMeterValueInterval = 0;
  2159. return result;
  2160. }
  2161. int ProcessShareMemory()
  2162. {
  2163. if(InitShareMemory() == FAIL)
  2164. {
  2165. DEBUG_ERROR("InitShareMemory NG\n");
  2166. if(ShmStatusCodeData!=NULL)
  2167. {
  2168. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2169. }
  2170. sleep(5);
  2171. return FAIL;
  2172. }
  2173. return PASS;
  2174. }
  2175. //---------------------common routine---------------------------//
  2176. int isOFFline(void)
  2177. {
  2178. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2179. {
  2180. if(TempMeterValueInterval >= 2 )
  2181. {
  2182. TempMeterValueInterval = 0;
  2183. return TRUE;
  2184. }
  2185. else
  2186. {
  2187. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2188. return FALSE;
  2189. }
  2190. }
  2191. else
  2192. {
  2193. return FALSE;
  2194. }
  2195. }
  2196. //---------------------------------------------
  2197. // new:
  2198. // enum SYSTEM_STATUS
  2199. // {
  2200. // SYS_MODE_BOOTING = 0,
  2201. // SYS_MODE_IDLE = 1,
  2202. // SYS_MODE_AUTHORIZING = 2,
  2203. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2204. // SYS_MODE_REASSIGN = 4,
  2205. // SYS_MODE_PREPARING = 5,
  2206. // SYS_MODE_PREPARE_FOR_EV = 6,
  2207. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2208. // SYS_MODE_CHARGING = 8,
  2209. // SYS_MODE_TERMINATING = 9,
  2210. // SYS_MODE_COMPLETE = 10,
  2211. // SYS_MODE_ALARM = 11,
  2212. // SYS_MODE_FAULT = 12,
  2213. // SYS_MODE_RESERVATION = 13,
  2214. // SYS_MODE_BOOKING = 14,
  2215. // SYS_MODE_MAINTAIN = 15,
  2216. // SYS_MODE_DEBUG = 16,
  2217. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2218. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2219. // SYS_MODE_UPDATE = 19
  2220. // };
  2221. //
  2222. //
  2223. //-----------------------------------------
  2224. void CheckSystemValue(void)
  2225. {
  2226. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2227. //int IdleModeCnt = 0;
  2228. char filenmae[100]={0};
  2229. char str[100]={0};
  2230. //===============================
  2231. // send Heartbeat
  2232. //===============================
  2233. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2234. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2235. {
  2236. clientTime.Heartbeat=time((time_t*)NULL);
  2237. if(server_sign == TRUE)
  2238. {
  2239. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2240. }
  2241. else
  2242. {
  2243. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2244. }
  2245. }
  2246. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2247. {
  2248. //parameter for test
  2249. sendHeartbeatRequest(0);
  2250. //==============================================
  2251. // Reset Waiting Time
  2252. //==============================================
  2253. clientTime.Heartbeat=time((time_t*)NULL);
  2254. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2255. }
  2256. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2257. {
  2258. //===============================
  2259. // CSU Trigger Reset Conf
  2260. //===============================
  2261. if((server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2262. {
  2263. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2264. }
  2265. //===============================
  2266. // CSU Trigger Authorize Request
  2267. //===============================
  2268. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2269. {
  2270. sendAuthorizeRequest(0);
  2271. authorizeRetryTimes = authorizeRetryTimes + 1;
  2272. if(authorizeRetryTimes < 3)
  2273. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2274. }
  2275. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  2276. {
  2277. authorizeRetryTimes = 0;
  2278. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2279. server_sign = FALSE;
  2280. }
  2281. 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))
  2282. {
  2283. sendAuthorizeRequest(0);
  2284. }
  2285. //===============================
  2286. // CSU Trigger Smart Charging Profilw
  2287. //===============================
  2288. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2289. {
  2290. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2291. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2292. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2293. }
  2294. //==============================================
  2295. // Charger start transaction
  2296. //==============================================
  2297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2298. {
  2299. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2300. sendStartTransactionRequest(gun_index);
  2301. clientTime.StartTransaction = time((time_t*)NULL);
  2302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2303. }
  2304. //==============================================
  2305. // Charger stop transaction
  2306. //==============================================
  2307. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2308. {
  2309. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2310. sendStopTransactionRequest(gun_index);
  2311. clientTime.StopTransaction = time((time_t*)NULL);
  2312. }
  2313. //==============================================
  2314. // Charger status report
  2315. //==============================================
  2316. //--- Check Mode Change ---//
  2317. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2318. if(gunType[gun_index] == 'J')
  2319. {
  2320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2321. {
  2322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2323. {
  2324. 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]*/ )
  2325. {
  2326. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2327. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2328. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2329. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2330. statusModeChage[gun_index] = TRUE;
  2331. }
  2332. #if 1 // for TempStopTransaction
  2333. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2334. {
  2335. checkTempStopTransaction(gun_index);
  2336. }
  2337. #endif
  2338. }
  2339. }
  2340. }
  2341. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2342. {
  2343. for (int index = 0; index < CCS_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2346. {
  2347. 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]*/ )
  2348. {
  2349. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2350. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2351. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2353. statusModeChage[gun_index] = TRUE;
  2354. }
  2355. #if 1 // for TempStopTransaction
  2356. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2357. {
  2358. checkTempStopTransaction(gun_index);
  2359. }
  2360. #endif
  2361. }
  2362. }
  2363. }
  2364. else if(gunType[gun_index] == 'G')
  2365. {
  2366. for (int index = 0; index < GB_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2369. {
  2370. 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]*/ )
  2371. {
  2372. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2373. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2374. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. #if 1 // for TempStopTransaction
  2379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2380. {
  2381. checkTempStopTransaction(gun_index);
  2382. }
  2383. #endif
  2384. }
  2385. }
  2386. }
  2387. else
  2388. {
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2392. {
  2393. 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]*/ )
  2394. {
  2395. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2396. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2397. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2398. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2399. statusModeChage[gun_index] = TRUE;
  2400. }
  2401. #if 1 // for TempStopTransaction
  2402. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2403. {
  2404. checkTempStopTransaction(gun_index);
  2405. }
  2406. #endif
  2407. }
  2408. }// END
  2409. }
  2410. if(((server_sign == TRUE) && (SystemInitial > 0)) ||
  2411. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2412. {
  2413. if(SystemInitial > 0)
  2414. SystemInitial = SystemInitial -1;
  2415. sendStatusNotificationRequest(gun_index);
  2416. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2417. statusModeChage[gun_index] = FALSE;
  2418. }
  2419. //==============================================
  2420. // Meter report
  2421. //==============================================
  2422. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  2423. {
  2424. //check Transaction active
  2425. if(gunType[gun_index] == 'J')
  2426. {
  2427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2428. {
  2429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2430. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2431. {
  2432. meterValueSend[gun_index] =1;
  2433. }
  2434. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2435. {
  2436. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2437. if((access(filenmae,F_OK))!=-1)
  2438. {
  2439. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2440. sprintf(str,"rm -f %s",filenmae);
  2441. system(str);
  2442. }
  2443. }
  2444. }// End for CHAdeMO
  2445. }
  2446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2447. {
  2448. for (int index = 0; index < CCS_QUANTITY; index++)
  2449. {
  2450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2451. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2452. {
  2453. meterValueSend[gun_index] =1;
  2454. }
  2455. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2456. {
  2457. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2458. if((access(filenmae,F_OK))!=-1)
  2459. {
  2460. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2461. sprintf(str,"rm -f %s",filenmae);
  2462. system(str);
  2463. }
  2464. }
  2465. } // End for CCS
  2466. }
  2467. else if(gunType[gun_index] == 'G')
  2468. {
  2469. for (int index = 0; index < GB_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2473. {
  2474. meterValueSend[gun_index] =1;
  2475. }
  2476. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2477. {
  2478. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2479. if((access(filenmae,F_OK))!=-1)
  2480. {
  2481. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2482. sprintf(str,"rm -f %s",filenmae);
  2483. system(str);
  2484. }
  2485. }
  2486. }// End for GB
  2487. }
  2488. else
  2489. {
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2493. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2494. {
  2495. meterValueSend[gun_index] =1;
  2496. }
  2497. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2498. {
  2499. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2500. if((access(filenmae,F_OK))!=-1)
  2501. {
  2502. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2503. sprintf(str,"rm -f %s",filenmae);
  2504. system(str);
  2505. }
  2506. }
  2507. }//End for AC
  2508. }
  2509. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2510. if(meterValueSend[gun_index] == 1)
  2511. {
  2512. sendMeterValuesRequest(gun_index);
  2513. #if 1 // for TempStopTransaction
  2514. storeTempStopTransaction(gun_index);
  2515. #endif
  2516. }
  2517. }
  2518. //==============================================
  2519. // Check Connector reserved
  2520. //==============================================
  2521. //===============================
  2522. // Check if Reserve is expired
  2523. //===============================
  2524. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2525. {
  2526. double diff_t;
  2527. struct tm tp;
  2528. // current time
  2529. time_t t = time(NULL);
  2530. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2531. tp.tm_isdst = -1;
  2532. time_t utc = mktime(&tp);
  2533. diff_t = difftime(utc, t);
  2534. if(diff_t <= 0)
  2535. {
  2536. DEBUG_INFO("reserve expired.\n");
  2537. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2538. }
  2539. }//END OF Check if Reserve is expired
  2540. //==========================================
  2541. // csu trigger FirmwareStatusNotificationReq
  2542. //==========================================
  2543. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2544. {
  2545. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2546. }
  2547. //==========================================
  2548. // csu trigger CancelReservationConf
  2549. //==========================================
  2550. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2551. {
  2552. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2553. }
  2554. //==========================================
  2555. // csu trigger ChangeAvailabilityConf
  2556. //==========================================
  2557. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2558. {
  2559. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2560. }
  2561. //==========================================
  2562. // csu trigger UnlockConnectorConf
  2563. //==========================================
  2564. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2565. {
  2566. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2567. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2568. }
  2569. //==========================================
  2570. // csu trigger ReserveNowConf
  2571. //==========================================
  2572. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2573. {
  2574. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2575. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2576. }
  2577. //==========================================
  2578. // csu trigger DataTransferReq
  2579. //==========================================
  2580. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2581. {
  2582. sendDataTransferRequest(gun_index);
  2583. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2584. }
  2585. }
  2586. }
  2587. //==========================================
  2588. // send request routine
  2589. //==========================================
  2590. int sendAuthorizeRequest(int gun_index)
  2591. {
  2592. mtrace();
  2593. int result = FAIL;
  2594. char message[100]={0};
  2595. char guid[37];
  2596. char tempdata[65]={0};
  2597. DEBUG_INFO("sendAuthorizeRequest...\n");
  2598. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2599. //Local Authorize
  2600. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2601. {
  2602. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2604. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2605. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2606. result = PASS;
  2607. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2608. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2609. authorizeRetryTimes = 0;
  2610. return result;
  2611. }
  2612. 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))||
  2613. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2614. {
  2615. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2616. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2617. {
  2618. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2619. {
  2620. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2621. }
  2622. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2623. {
  2624. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2625. }
  2626. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2627. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2628. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2629. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2630. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2631. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2632. authorizeRetryTimes = 0;
  2633. return result;
  2634. }
  2635. else
  2636. {
  2637. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2641. result = PASS;
  2642. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2644. authorizeRetryTimes = 0;
  2645. return result;
  2646. }
  2647. }
  2648. //initailize struct Authorize
  2649. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2650. //get data from shared memory
  2651. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2652. random_uuid(guid);
  2653. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2654. LWS_Send(message);
  2655. sprintf(tempdata, "Authorize,%d", gun_index);
  2656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2657. {
  2658. result = PASS;
  2659. DEBUG_INFO("Authorize mapItem pass\n");
  2660. }
  2661. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2662. return result;
  2663. }
  2664. int sendBootNotificationRequest(void)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[500]={0}, payload[700]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. int IsGunCharging = FALSE;
  2672. //check Transaction active
  2673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2676. {
  2677. IsGunCharging = TRUE;
  2678. }
  2679. }
  2680. for (int index = 0; index < CCS_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2683. {
  2684. IsGunCharging = TRUE;
  2685. }
  2686. }
  2687. for (int index = 0; index < GB_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2690. {
  2691. IsGunCharging = TRUE;
  2692. }
  2693. }
  2694. for (int index = 0; index < AC_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2697. {
  2698. IsGunCharging = TRUE;
  2699. }
  2700. }
  2701. if(IsGunCharging == TRUE)
  2702. {
  2703. server_sign = TRUE;
  2704. return result;
  2705. }
  2706. // Fill BootNotification fields
  2707. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2708. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2709. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2710. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2711. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2712. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2713. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2714. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2715. ShmOCPP16Data->ChargeBoxId
  2716. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2717. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2718. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2719. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2720. ,ShmOCPP16Data->BootNotification.CpIccid
  2721. ,ShmOCPP16Data->BootNotification.CpImsi);
  2722. random_uuid(guid);
  2723. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2724. LWS_Send(message);
  2725. sprintf(tempdata, "BootNotification,0");
  2726. if(hashmap_operation(HASH_OP_ADD, 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*/)
  2727. {
  2728. result = PASS;
  2729. }
  2730. memset(queuedata, 0, sizeof(queuedata));
  2731. strcpy(queuedata,message);
  2732. return result;
  2733. }
  2734. int sendDataTransferRequest(int gun_index)
  2735. {
  2736. mtrace();
  2737. char message[1000]={0};
  2738. char guid[37]={0};
  2739. char tempdata[65]={0};
  2740. int result = FAIL;
  2741. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2742. random_uuid(guid);
  2743. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2744. MESSAGE_TYPE_CALL,
  2745. guid,
  2746. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2747. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2748. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2749. LWS_Send(message);
  2750. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2751. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2752. {
  2753. result = PASS;
  2754. DEBUG_INFO("DataTransfer mapItem pass\n");
  2755. }
  2756. return result;
  2757. }
  2758. int sendFirmwareVersionByDataTransfer(void)
  2759. {
  2760. int8_t result = FAIL;
  2761. json_object *FirmwareDataTransfer = json_object_new_object();
  2762. // AC & DC model
  2763. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  2764. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  2765. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  2766. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  2767. // DC model
  2768. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  2769. {
  2770. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  2771. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  2772. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  2773. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  2774. }
  2775. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  2776. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  2777. {
  2778. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  2779. }
  2780. // 4G model
  2781. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  2782. {
  2783. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  2784. }
  2785. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  2786. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  2787. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  2788. if(sendDataTransferRequest(0))
  2789. {
  2790. result = PASS;
  2791. }
  2792. return result;
  2793. }
  2794. int sendDiagnosticsStatusNotificationRequest(char *status)
  2795. {
  2796. mtrace();
  2797. int result = FAIL;
  2798. char message[110]={0};
  2799. char guid[37]={0};
  2800. char tempdata[65]={0};
  2801. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2802. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2803. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2804. random_uuid(guid);
  2805. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2806. LWS_Send(message);
  2807. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2808. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2809. {
  2810. result = PASS;
  2811. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2812. }
  2813. //#ifdef SystemLogMessage
  2814. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2816. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2817. //#endif
  2818. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2819. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2820. //record status
  2821. if(strcmp(status,"Idle")==0)
  2822. {
  2823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2824. }
  2825. else if(strcmp(status,"Uploaded")==0)
  2826. {
  2827. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2828. }
  2829. else if(strcmp(status,"UploadFailed")==0)
  2830. {
  2831. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2832. }
  2833. else if(strcmp(status,"Uploading")==0)
  2834. {
  2835. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2836. }
  2837. return result;
  2838. }
  2839. int sendFirmwareStatusNotificationRequest(char *status)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[110]={0};
  2844. char guid[37]={0};
  2845. char tempdata[65]={0};
  2846. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2847. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2848. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2849. random_uuid(guid);
  2850. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2851. LWS_Send(message);
  2852. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2853. if(hashmap_operation(HASH_OP_ADD, 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*/)
  2854. {
  2855. result = PASS;
  2856. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2857. }
  2858. //#ifdef SystemLogMessage
  2859. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2860. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2861. //#endif
  2862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2864. //record status
  2865. if(strcmp(status,"Downloaded")==0)
  2866. {
  2867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2868. }
  2869. else if(strcmp(status,"DownloadFailed")==0)
  2870. {
  2871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2872. }
  2873. else if(strcmp(status,"Downloading")==0)
  2874. {
  2875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2876. }
  2877. else if(strcmp(status,"Idle")==0)
  2878. {
  2879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2880. }
  2881. else if(strcmp(status,"InstallationFailed")==0)
  2882. {
  2883. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2884. }
  2885. else if(strcmp(status,"Installing")==0)
  2886. {
  2887. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2888. }
  2889. else if(strcmp(status,"Installed")==0)
  2890. {
  2891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2892. }
  2893. return result;
  2894. }
  2895. int sendHeartbeatRequest(int gun_index)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[80]={0};
  2900. char guid[37]={0};
  2901. char tempdata[65]={0};
  2902. random_uuid(guid);
  2903. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2904. , MESSAGE_TYPE_CALL
  2905. , guid );
  2906. LWS_Send(message);
  2907. sprintf(tempdata, "Heartbeat,%d", 0);
  2908. if(hashmap_operation(HASH_OP_ADD, 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*/)
  2909. {
  2910. result = PASS;
  2911. }
  2912. return result;
  2913. }
  2914. int sendStartTransactionRequest(int gun_index)
  2915. {
  2916. mtrace();
  2917. int result = FAIL;
  2918. char message[250]={0};
  2919. char guid[37]={0};
  2920. struct timeval tmnow;
  2921. struct tm *tm;
  2922. char buf[28];//, usec_buf[6];
  2923. char tempdata[65]={0};
  2924. int tempIndex = 0;
  2925. DEBUG_INFO("sendStartTransactionRequest...");
  2926. gettimeofday(&tmnow, NULL);
  2927. time_t t;
  2928. t = time(NULL);
  2929. /*UTC time and date*/
  2930. tm = gmtime(&t);
  2931. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2932. #if 0 // remove temporally
  2933. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2934. strcat(buf,".");
  2935. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2936. strcat(buf,usec_buf);
  2937. #endif
  2938. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2939. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2940. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2941. // clear StartTransaction Response
  2942. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2943. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2944. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2945. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2946. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2947. if(gunType[gun_index] == 'J')
  2948. {
  2949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2950. {
  2951. tempIndex = ((gun_index==2) ? 1: 0);
  2952. }
  2953. else
  2954. {
  2955. tempIndex = gun_index;
  2956. }
  2957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2958. {
  2959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2960. {
  2961. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2962. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2963. }
  2964. }
  2965. }
  2966. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2967. {
  2968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2969. {
  2970. tempIndex = ((gun_index==2) ? 1: 0);
  2971. }
  2972. else
  2973. {
  2974. tempIndex = gun_index;
  2975. }
  2976. for (int index = 0; index < CCS_QUANTITY; index++)
  2977. {
  2978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2979. {
  2980. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2981. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2982. }
  2983. }
  2984. }
  2985. else if(gunType[gun_index] == 'G')
  2986. {
  2987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2988. {
  2989. tempIndex = ((gun_index==2) ? 1: 0);
  2990. }
  2991. else
  2992. {
  2993. tempIndex = gun_index;
  2994. }
  2995. for (int index = 0; index < GB_QUANTITY; index++)
  2996. {
  2997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2998. {
  2999. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3000. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3001. }
  3002. }
  3003. }
  3004. else
  3005. {
  3006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3007. {
  3008. tempIndex = 2;
  3009. }
  3010. else
  3011. {
  3012. tempIndex = gun_index;
  3013. }
  3014. for (int index = 0; index < AC_QUANTITY; index++)
  3015. {
  3016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3017. {
  3018. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3019. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3020. }
  3021. }
  3022. }
  3023. random_uuid(guid);
  3024. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3025. {
  3026. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3027. , gun_index +1
  3028. , MESSAGE_TYPE_CALL
  3029. , guid
  3030. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3031. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3032. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3033. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3034. }
  3035. else
  3036. {
  3037. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3038. , gun_index +1
  3039. , MESSAGE_TYPE_CALL
  3040. , guid
  3041. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3042. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3043. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3044. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3045. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3046. }
  3047. #if 1
  3048. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3049. 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*/)
  3050. {
  3051. result = PASS;
  3052. }
  3053. #endif
  3054. strcpy(queuedata, message);
  3055. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3056. if(GetTransactionQueueNum() == 1)
  3057. {
  3058. LWS_Send(message + 2);
  3059. }
  3060. return result;
  3061. }
  3062. int sendStatusNotificationRequest(int gun_index)
  3063. {
  3064. mtrace();
  3065. int result = FAIL;
  3066. char message[600]={0};
  3067. char guid[37];
  3068. int currentStatus = 0;
  3069. struct timeval tmnow;
  3070. struct tm *tm;
  3071. char buf[28];//, usec_buf[6];
  3072. char tempdata[65]={0};
  3073. int tempIndex = 0;
  3074. gettimeofday(&tmnow, NULL);
  3075. time_t t;
  3076. t = time(NULL);
  3077. /*UTC time and date*/
  3078. tm = gmtime(&t);
  3079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3080. #if 0 // remove temporally
  3081. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3082. strcat(buf,".");
  3083. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3084. strcat(buf,usec_buf);
  3085. #endif
  3086. printf("%s",buf);
  3087. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3088. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3089. // it's option
  3090. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3091. /*
  3092. enum _SYSTEM_STATUS
  3093. {
  3094. S_BOOTING = 0,
  3095. S_IDLE, = 1
  3096. S_AUTHORIZING, =2
  3097. S_REASSIGN_CHECK, =3
  3098. S_REASSIGN, =4
  3099. S_PRECHARGE, =5
  3100. S_PREPARING_FOR_EV, =6
  3101. S_PREPARING_FOR_EVSE, =7
  3102. S_CHARGING, =8
  3103. S_TERMINATING, =9
  3104. S_COMPLETE, =10
  3105. S_ALARM, =11
  3106. S_FAULT =12
  3107. }
  3108. */
  3109. //check Transaction active
  3110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3111. if(gunType[gun_index] == 'J')
  3112. {
  3113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3114. {
  3115. tempIndex = ((gun_index==2) ? 1: 0);
  3116. }
  3117. else
  3118. {
  3119. tempIndex = gun_index;
  3120. }
  3121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3122. {
  3123. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3124. {
  3125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3126. {
  3127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3128. {
  3129. currentStatus = 1; //OCPP Status: Preparing
  3130. }
  3131. else
  3132. {
  3133. currentStatus = 0; //OCPP Status: Available
  3134. }
  3135. }
  3136. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3137. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3138. ) //S_PRECHARGE
  3139. {
  3140. currentStatus = 1; //OCPP Status: Preparing
  3141. }
  3142. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3143. {
  3144. currentStatus = 2; //OCPP Status: Charging
  3145. }
  3146. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3147. {
  3148. currentStatus = 5; //OCPP Status: Finishing
  3149. }
  3150. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3151. {
  3152. currentStatus = 4; //OCPP Status: SuspendedEV
  3153. }
  3154. 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
  3155. {
  3156. currentStatus = 7; //OCPP Status: Unavailable
  3157. }
  3158. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3159. {
  3160. currentStatus = 8; //OCPP Status: Faulted
  3161. }
  3162. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3163. {
  3164. currentStatus = 6; //OCPP Status: Reserved
  3165. }
  3166. } //end of the same index
  3167. }//end of for CHAdeMO_QUANTITY
  3168. }
  3169. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3170. {
  3171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3172. {
  3173. tempIndex = ((gun_index==2) ? 1: 0);
  3174. }
  3175. else
  3176. {
  3177. tempIndex = gun_index;
  3178. }
  3179. for (int index = 0; index < CCS_QUANTITY; index++)
  3180. {
  3181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3182. {
  3183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3184. {
  3185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3186. {
  3187. currentStatus = 1; //OCPP Status: Preparing
  3188. }
  3189. else
  3190. {
  3191. currentStatus = 0; //OCPP Status: Available
  3192. }
  3193. }
  3194. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3195. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3196. ) //S_PRECHARGE
  3197. {
  3198. currentStatus = 1; //OCPP Status: Preparing
  3199. }
  3200. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3201. {
  3202. currentStatus = 2; //OCPP Status: Charging
  3203. }
  3204. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3205. {
  3206. currentStatus = 5; //OCPP Status: Finishing
  3207. }
  3208. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3209. {
  3210. currentStatus = 4; //OCPP Status: SuspendedEV
  3211. }
  3212. 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
  3213. {
  3214. currentStatus = 7; //OCPP Status : Unavailable
  3215. }
  3216. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3217. {
  3218. currentStatus = 8; //OCPP Status: Faulted
  3219. }
  3220. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3221. {
  3222. currentStatus = 6; //OCPP Status: Reserved
  3223. }
  3224. } //end of the same index
  3225. } // end of for CCS_QUANTITY
  3226. }
  3227. else if(gunType[gun_index] == 'G')
  3228. {
  3229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3230. {
  3231. tempIndex = ((gun_index==2) ? 1: 0);
  3232. }
  3233. else
  3234. {
  3235. tempIndex = gun_index;
  3236. }
  3237. for (int index = 0; index < GB_QUANTITY; index++)
  3238. {
  3239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3240. {
  3241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3242. {
  3243. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3244. {
  3245. currentStatus = 1; //OCPP Status: Preparing
  3246. }
  3247. else
  3248. {
  3249. currentStatus = 0; //OCPP Status: Available
  3250. }
  3251. }
  3252. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3253. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3254. ) //S_PRECHARGE
  3255. {
  3256. currentStatus = 1; //OCPP Status: Preparing
  3257. }
  3258. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3259. {
  3260. currentStatus = 2; //OCPP Status: Charging
  3261. }
  3262. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3263. {
  3264. currentStatus = 5; //OCPP Status: Finishing
  3265. }
  3266. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3267. {
  3268. currentStatus = 4; //OCPP Status: SuspendedEV
  3269. }
  3270. 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
  3271. {
  3272. currentStatus = 7; //OCPP Status: Unavailable
  3273. }
  3274. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3275. {
  3276. currentStatus = 8; //OCPP Status: Faulted
  3277. }
  3278. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3279. {
  3280. currentStatus = 6; //OCPP Status: Reserved
  3281. }
  3282. } //end of the same index
  3283. } // end of for GB_QUANTITY
  3284. }
  3285. else
  3286. {
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3288. {
  3289. tempIndex = 2;
  3290. }
  3291. else
  3292. {
  3293. tempIndex = gun_index;
  3294. }
  3295. for (int index = 0; index < AC_QUANTITY; index++)
  3296. {
  3297. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3298. {
  3299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3300. {
  3301. 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))
  3302. {
  3303. currentStatus = 1; //OCPP Status: Preparing
  3304. }
  3305. else
  3306. {
  3307. currentStatus = 0; //OCPP Status: Available
  3308. }
  3309. }
  3310. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3311. {
  3312. currentStatus = 1; //OCPP Status: Preparing
  3313. }
  3314. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3315. {
  3316. currentStatus = 2; //OCPP Status: Charging
  3317. }
  3318. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3319. {
  3320. currentStatus = 5; //OCPP Status: Finishing
  3321. }
  3322. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3323. {
  3324. currentStatus = 4; //OCPP Status: SuspendedEV
  3325. }
  3326. 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
  3327. {
  3328. currentStatus = 7; //OCPP Status: Unavailable
  3329. }
  3330. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3331. {
  3332. currentStatus = 8; //OCPP Status: Faulted
  3333. }
  3334. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3335. {
  3336. currentStatus = 6; //OCPP Status: Reserved
  3337. }
  3338. }//end of the same index
  3339. }//end of for AC_QUANTITY
  3340. }
  3341. //it's option
  3342. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3343. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3344. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3345. random_uuid(guid);
  3346. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3347. , MESSAGE_TYPE_CALL
  3348. , guid
  3349. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3350. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3351. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3352. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3353. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3354. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3355. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3356. LWS_Send(message);
  3357. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3358. 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*/)
  3359. {
  3360. //DEBUG_ERROR("statusNotification mapitem pass");
  3361. result = PASS;
  3362. }
  3363. return result;
  3364. }
  3365. int sendStopTransactionRequest(int gun_index)
  3366. {
  3367. mtrace();
  3368. int result = FAIL;
  3369. //char message[1500]={0};
  3370. char guid[37]={0};
  3371. char tempdata[65]={0};
  3372. int tempIndex = 0;
  3373. //int idx_sample=0;
  3374. DEBUG_ERROR("sendStopTransactionRequest \n");
  3375. memset(queuedata, 0, sizeof(queuedata));
  3376. //ENERGY_ACTIVE_IMPORT_REGISTER
  3377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3378. if(gunType[gun_index] == 'J')
  3379. {
  3380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3381. {
  3382. tempIndex = ((gun_index==2) ? 1: 0);
  3383. }
  3384. else
  3385. {
  3386. tempIndex = gun_index;
  3387. }
  3388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3391. {
  3392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3393. }
  3394. }// END OF CHAdeMO_QUANTITY
  3395. }
  3396. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3397. {
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3399. {
  3400. tempIndex = ((gun_index==2) ? 1: 0);
  3401. }
  3402. else
  3403. {
  3404. tempIndex = gun_index;
  3405. }
  3406. for (int index = 0; index < CCS_QUANTITY; index++)
  3407. {
  3408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3409. {
  3410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3411. }
  3412. }// END OF CCS_QUANTITY
  3413. }
  3414. else if(gunType[gun_index] == 'G')
  3415. {
  3416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3417. {
  3418. tempIndex = ((gun_index==2) ? 1: 0);
  3419. }
  3420. else
  3421. {
  3422. tempIndex = gun_index;
  3423. }
  3424. for (int index = 0; index < GB_QUANTITY; index++)
  3425. {
  3426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3427. {
  3428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3429. }
  3430. }// END OF GB_QUANTITY
  3431. }
  3432. else
  3433. {
  3434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3435. {
  3436. tempIndex = 2;
  3437. }
  3438. else
  3439. {
  3440. tempIndex = gun_index;
  3441. }
  3442. for (int index = 0; index < AC_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3445. {
  3446. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3447. }
  3448. }// END OF AC_QUANTITY
  3449. }
  3450. //Stop Transaction Time
  3451. struct timeval tmnow;
  3452. struct tm *tm;
  3453. char buf[28];//, usec_buf[6];
  3454. gettimeofday(&tmnow, NULL);
  3455. time_t t;
  3456. t = time(NULL);
  3457. /*UTC time and date*/
  3458. tm = gmtime(&t);
  3459. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3461. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3462. random_uuid(guid);
  3463. /***********************************transactionData******************************************************/
  3464. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3466. //=================================
  3467. // Transaction_Begin
  3468. //=================================
  3469. // Energy.Active.Export.Interval
  3470. //idx_sample=0;
  3471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3474. 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*/]);
  3475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3476. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3477. {
  3478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3479. }
  3480. else
  3481. {
  3482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3483. }
  3484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3486. //=================================
  3487. // Transaction_End
  3488. //=================================
  3489. //Current.Export
  3490. //idx_sample=1;
  3491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3492. if(gunType[gun_index] == 'J')
  3493. {
  3494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3495. {
  3496. tempIndex = ((gun_index==2) ? 1: 0);
  3497. }
  3498. else
  3499. {
  3500. tempIndex = gun_index;
  3501. }
  3502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3503. {
  3504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3505. {
  3506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3507. }
  3508. }// End of for CHAdeMO_QUANTITY
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3510. }
  3511. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3514. {
  3515. tempIndex = ((gun_index==2) ? 1: 0);
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < CCS_QUANTITY; index++)
  3522. {
  3523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3524. {
  3525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3526. }
  3527. }// End of for CCS_QUANTITY
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3529. }
  3530. else if(gunType[gun_index] == 'G')
  3531. {
  3532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3533. {
  3534. tempIndex = ((gun_index==2) ? 1: 0);
  3535. }
  3536. else
  3537. {
  3538. tempIndex = gun_index;
  3539. }
  3540. for (int index = 0; index < GB_QUANTITY; index++)
  3541. {
  3542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3543. {
  3544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3545. }
  3546. }// End of for GB_QUANTITY
  3547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3548. }
  3549. else
  3550. {
  3551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3552. {
  3553. tempIndex = 2;
  3554. }
  3555. else
  3556. {
  3557. tempIndex = gun_index;
  3558. }
  3559. for (int index = 0; index < AC_QUANTITY; index++)
  3560. {
  3561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3562. {
  3563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3564. }
  3565. }// End of for AC_QUANTITY
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3567. }
  3568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3571. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3574. //Energy.Active.Export.Interval
  3575. //idx_sample=2;
  3576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3577. if(gunType[gun_index] == 'J')
  3578. {
  3579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3580. {
  3581. tempIndex = ((gun_index==2) ? 1: 0);
  3582. }
  3583. else
  3584. {
  3585. tempIndex = gun_index;
  3586. }
  3587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3588. {
  3589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3590. {
  3591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3592. }
  3593. }// END OF CHAdeMO_QUANTITY
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3595. }
  3596. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3597. {
  3598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3599. {
  3600. tempIndex = ((gun_index==2) ? 1: 0);
  3601. }
  3602. else
  3603. {
  3604. tempIndex = gun_index;
  3605. }
  3606. for (int index = 0; index < CCS_QUANTITY; index++)
  3607. {
  3608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3609. {
  3610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3611. }
  3612. }// END OF CCS_QUANTITY
  3613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3614. }
  3615. else if(gunType[gun_index] == 'G')
  3616. {
  3617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3618. {
  3619. tempIndex = ((gun_index==2) ? 1: 0);
  3620. }
  3621. else
  3622. {
  3623. tempIndex = gun_index;
  3624. }
  3625. for (int index = 0; index < GB_QUANTITY; index++)
  3626. {
  3627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3628. {
  3629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3630. }
  3631. }// END OF GB_QUANTITY
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3633. }
  3634. else
  3635. {
  3636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3637. {
  3638. tempIndex = 2;
  3639. }
  3640. else
  3641. {
  3642. tempIndex = gun_index;
  3643. }
  3644. for (int index = 0; index < AC_QUANTITY; index++)
  3645. {
  3646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3647. {
  3648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3649. }
  3650. }// END OF AC_QUANTITY
  3651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3652. }
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3656. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3659. //Power.Active.Export
  3660. //idx_sample=3;
  3661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3662. if(gunType[gun_index] == 'J')
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3675. {
  3676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3677. }
  3678. } // End for CHAdeMO_QUANTITY
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3680. }
  3681. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CCS_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3696. }
  3697. } // END for CCS_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3699. }
  3700. else if(gunType[gun_index] == 'G')
  3701. {
  3702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3703. {
  3704. tempIndex = ((gun_index==2) ? 1: 0);
  3705. }
  3706. else
  3707. {
  3708. tempIndex = gun_index;
  3709. }
  3710. for (int index = 0; index < GB_QUANTITY; index++)
  3711. {
  3712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3713. {
  3714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3715. }
  3716. }// END for GB_QUANTITY
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3718. }
  3719. else
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3722. {
  3723. tempIndex = 2;
  3724. }
  3725. else
  3726. {
  3727. tempIndex = gun_index;
  3728. }
  3729. for (int index = 0; index < AC_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3732. {
  3733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3734. }
  3735. } // END for AC_QUANTITY
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3737. }
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3741. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3744. //Voltage
  3745. //idx_sample=4;
  3746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3747. if(gunType[gun_index] == 'J')
  3748. {
  3749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3750. {
  3751. tempIndex = ((gun_index==2) ? 1: 0);
  3752. }
  3753. else
  3754. {
  3755. tempIndex = gun_index;
  3756. }
  3757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3760. {
  3761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3762. }
  3763. } // END OF FOR CHAdeMO_QUANTITY
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3765. }
  3766. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3767. {
  3768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3769. {
  3770. tempIndex = ((gun_index==2) ? 1: 0);
  3771. }
  3772. else
  3773. {
  3774. tempIndex = gun_index;
  3775. }
  3776. for (int index = 0; index < CCS_QUANTITY; index++)
  3777. {
  3778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3779. {
  3780. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3781. }
  3782. } // END OF FOR CCS_QUANTITY
  3783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3784. }
  3785. else if(gunType[gun_index] == 'G')
  3786. {
  3787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3788. {
  3789. tempIndex = ((gun_index==2) ? 1: 0);
  3790. }
  3791. else
  3792. {
  3793. tempIndex = gun_index;
  3794. }
  3795. for (int index = 0; index < GB_QUANTITY; index++)
  3796. {
  3797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3798. {
  3799. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3800. }
  3801. } // END OF FOR GB_QUANTITY
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3803. }
  3804. else
  3805. {
  3806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3807. {
  3808. tempIndex = 2;
  3809. }
  3810. else
  3811. {
  3812. tempIndex = gun_index;
  3813. }
  3814. for (int index = 0; index < AC_QUANTITY; index++)
  3815. {
  3816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3817. {
  3818. 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
  3819. }
  3820. } // END OF FOR AC_QUANTITY
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3822. }
  3823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3826. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3829. //SoC
  3830. //idx_sample=5;
  3831. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3832. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3835. {
  3836. tempIndex = ((gun_index==2) ? 1: 0);
  3837. }
  3838. else
  3839. {
  3840. tempIndex = gun_index;
  3841. }
  3842. if(gunType[gun_index] == 'J')
  3843. {
  3844. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3845. {
  3846. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3847. {
  3848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3849. }
  3850. }
  3851. }
  3852. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3853. {
  3854. for (int index = 0; index < CCS_QUANTITY; index++)
  3855. {
  3856. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3857. {
  3858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3859. }
  3860. }
  3861. }
  3862. else if(gunType[gun_index] == 'G')
  3863. {
  3864. for (int index = 0; index < GB_QUANTITY; index++)
  3865. {
  3866. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3867. {
  3868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3869. }
  3870. }
  3871. }
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3878. } // END FOR DC CASE
  3879. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3880. {
  3881. sprintf(queuedata,"%d,[%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\"}]}]}]"
  3882. ,gun_index+1
  3883. ,MESSAGE_TYPE_CALL
  3884. ,guid
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3890. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3933. );
  3934. }
  3935. else
  3936. {
  3937. sprintf(queuedata,"%d,[%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\"}]}]}]"
  3938. ,gun_index+1
  3939. ,MESSAGE_TYPE_CALL
  3940. ,guid
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3946. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3982. );
  3983. }
  3984. #if 1 // for TempStopTransaction
  3985. //Delete TempStopTransaction
  3986. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3987. {
  3988. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3989. }
  3990. #endif
  3991. #if 1
  3992. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3993. if(hashmap_operation(0, guid, tempdata) == 1)
  3994. {
  3995. result = PASS;
  3996. DEBUG_INFO("StopTransaction mapitem pass\n");
  3997. }
  3998. #endif
  3999. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4000. if(GetTransactionQueueNum() == 1)
  4001. {
  4002. LWS_Send(queuedata+2);
  4003. }
  4004. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4005. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4006. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4007. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4008. {
  4009. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4010. }
  4011. //for test
  4012. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4013. return result;
  4014. }
  4015. int sendMeterValuesRequest(int gun_index)
  4016. {
  4017. mtrace();
  4018. int result = FAIL;
  4019. // char message[1500]={0};
  4020. char guid[37]={0};
  4021. //int idx_sample=0;
  4022. //int length = 0;
  4023. char tempdata[65]={0};
  4024. int tempIndex = 0;
  4025. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4026. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4027. /*
  4028. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4029. {
  4030. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4031. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4032. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4033. return result;
  4034. }
  4035. */
  4036. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4037. {
  4038. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4039. }
  4040. memset(queuedata, 0, sizeof(queuedata));
  4041. //set value
  4042. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4043. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4044. random_uuid(guid);
  4045. //UTC Date time
  4046. struct timeval tmnow;
  4047. struct tm *tm;
  4048. char buf[28];//, usec_buf[6];
  4049. gettimeofday(&tmnow, NULL);
  4050. time_t t;
  4051. t = time(NULL);
  4052. /*UTC time and date*/
  4053. tm = gmtime(&t);
  4054. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4055. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4056. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4057. //idx_sample=0;
  4058. //********************************(1)Current.Export************************************************/
  4059. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4060. if(gunType[gun_index] == 'J')
  4061. {
  4062. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4063. {
  4064. tempIndex = ((gun_index==2) ? 1: 0);
  4065. }
  4066. else
  4067. {
  4068. tempIndex = gun_index;
  4069. }
  4070. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4071. {
  4072. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4073. {
  4074. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4075. }
  4076. }
  4077. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4078. }
  4079. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4080. {
  4081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4082. {
  4083. tempIndex = ((gun_index==2) ? 1: 0);
  4084. }
  4085. else
  4086. {
  4087. tempIndex = gun_index;
  4088. }
  4089. for (int index = 0; index < CCS_QUANTITY; index++)
  4090. {
  4091. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4092. {
  4093. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4094. }
  4095. }
  4096. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4097. }
  4098. else if(gunType[gun_index] == 'G')
  4099. {
  4100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4101. {
  4102. tempIndex = ((gun_index==2) ? 1: 0);
  4103. }
  4104. else
  4105. {
  4106. tempIndex = gun_index;
  4107. }
  4108. for (int index = 0; index < GB_QUANTITY; index++)
  4109. {
  4110. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4111. {
  4112. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4113. }
  4114. }
  4115. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4116. }
  4117. else
  4118. {
  4119. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4120. {
  4121. tempIndex = 2;
  4122. }
  4123. else
  4124. {
  4125. tempIndex = gun_index;
  4126. }
  4127. for (int index = 0; index < AC_QUANTITY; index++)
  4128. {
  4129. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4130. {
  4131. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4132. }
  4133. }
  4134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4135. }
  4136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4137. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4139. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4141. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4142. //idx_sample=1;
  4143. //********************************(2)Energy.Active.Import.Register ************************************************/
  4144. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4145. if(gunType[gun_index] == 'J')
  4146. {
  4147. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4148. {
  4149. tempIndex = ((gun_index==2) ? 1: 0);
  4150. }
  4151. else
  4152. {
  4153. tempIndex = gun_index;
  4154. }
  4155. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4156. {
  4157. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4158. {
  4159. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4160. }
  4161. }
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4163. }
  4164. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4165. {
  4166. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4167. {
  4168. tempIndex = ((gun_index==2) ? 1: 0);
  4169. }
  4170. else
  4171. {
  4172. tempIndex = gun_index;
  4173. }
  4174. for (int index = 0; index < CCS_QUANTITY; index++)
  4175. {
  4176. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4177. {
  4178. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4179. }
  4180. }
  4181. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4182. }
  4183. else if(gunType[gun_index] == 'G')
  4184. {
  4185. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4186. {
  4187. tempIndex = ((gun_index==2) ? 1: 0);
  4188. }
  4189. else
  4190. {
  4191. tempIndex = gun_index;
  4192. }
  4193. for (int index = 0; index < GB_QUANTITY; index++)
  4194. {
  4195. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4196. {
  4197. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4198. }
  4199. }
  4200. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4201. }
  4202. else
  4203. {
  4204. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4205. {
  4206. tempIndex = 2;
  4207. }
  4208. else
  4209. {
  4210. tempIndex = gun_index;
  4211. }
  4212. for (int index = 0; index < AC_QUANTITY; index++)
  4213. {
  4214. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4215. {
  4216. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4217. }
  4218. }
  4219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4220. }
  4221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4222. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4224. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4226. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4227. //idx_sample=2;
  4228. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4229. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4230. if(gunType[gun_index] == 'J')
  4231. {
  4232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4233. {
  4234. tempIndex = ((gun_index==2) ? 1: 0);
  4235. }
  4236. else
  4237. {
  4238. tempIndex = gun_index;
  4239. }
  4240. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4241. {
  4242. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4243. {
  4244. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4245. }
  4246. } // END OF FOR CHAdeMO_QUANTITY
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4248. }
  4249. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4250. {
  4251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4252. {
  4253. tempIndex = ((gun_index==2) ? 1: 0);
  4254. }
  4255. else
  4256. {
  4257. tempIndex = gun_index;
  4258. }
  4259. for (int index = 0; index < CCS_QUANTITY; index++)
  4260. {
  4261. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4262. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4263. {
  4264. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4265. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4266. }
  4267. } // END OF CCS_QUANTITY
  4268. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4269. }
  4270. else if(gunType[gun_index] == 'G')
  4271. {
  4272. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4273. {
  4274. tempIndex = ((gun_index==2) ? 1: 0);
  4275. }
  4276. else
  4277. {
  4278. tempIndex = gun_index;
  4279. }
  4280. for (int index = 0; index < GB_QUANTITY; index++)
  4281. {
  4282. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4283. {
  4284. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4285. }
  4286. } // END OF GB_QUANTITY
  4287. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4288. }
  4289. else
  4290. {
  4291. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4292. {
  4293. tempIndex = 2;
  4294. }
  4295. else
  4296. {
  4297. tempIndex = gun_index;
  4298. }
  4299. for (int index = 0; index < AC_QUANTITY; index++)
  4300. {
  4301. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4302. {
  4303. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4304. }
  4305. }
  4306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4307. }
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4309. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4311. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4313. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4314. //idx_sample=3;
  4315. //********************************(4)Power.Active.Export************************************************/
  4316. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4317. if(gunType[gun_index] == 'J')
  4318. {
  4319. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4320. {
  4321. tempIndex = ((gun_index==2) ? 1: 0);
  4322. }
  4323. else
  4324. {
  4325. tempIndex = gun_index;
  4326. }
  4327. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4328. {
  4329. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4330. {
  4331. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4332. }
  4333. } // END OF FOR
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4335. }
  4336. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4337. {
  4338. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4339. {
  4340. tempIndex = ((gun_index==2) ? 1: 0);
  4341. }
  4342. else
  4343. {
  4344. tempIndex = gun_index;
  4345. }
  4346. for (int index = 0; index < CCS_QUANTITY; index++)
  4347. {
  4348. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4349. {
  4350. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4351. }
  4352. }
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4354. }
  4355. else if(gunType[gun_index] == 'G')
  4356. {
  4357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4358. {
  4359. tempIndex = ((gun_index==2) ? 1: 0);
  4360. }
  4361. else
  4362. {
  4363. tempIndex = gun_index;
  4364. }
  4365. for (int index = 0; index < GB_QUANTITY; index++)
  4366. {
  4367. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4368. {
  4369. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4370. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4371. }
  4372. }
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4374. }
  4375. else
  4376. {
  4377. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4378. {
  4379. tempIndex = 2;
  4380. }
  4381. else
  4382. {
  4383. tempIndex = gun_index;
  4384. }
  4385. for (int index = 0; index < AC_QUANTITY; index++)
  4386. {
  4387. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4388. {
  4389. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4390. }
  4391. }
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4393. }
  4394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4395. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4397. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4399. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4400. //idx_sample=4;
  4401. //***********************************************(5)VOLTAGE******************************************************/
  4402. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4403. if(gunType[gun_index] == 'J')
  4404. {
  4405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4406. {
  4407. tempIndex = ((gun_index==2) ? 1: 0);
  4408. }
  4409. else
  4410. {
  4411. tempIndex = gun_index;
  4412. }
  4413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4414. {
  4415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4416. {
  4417. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4418. }
  4419. }
  4420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4421. }
  4422. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4423. {
  4424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4425. {
  4426. tempIndex = ((gun_index==2) ? 1: 0);
  4427. }
  4428. else
  4429. {
  4430. tempIndex = gun_index;
  4431. }
  4432. for (int index = 0; index < CCS_QUANTITY; index++)
  4433. {
  4434. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4435. {
  4436. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4437. }
  4438. }
  4439. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4440. }
  4441. else if(gunType[gun_index] == 'G')
  4442. {
  4443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4444. {
  4445. tempIndex = ((gun_index==2) ? 1: 0);
  4446. }
  4447. else
  4448. {
  4449. tempIndex = gun_index;
  4450. }
  4451. for (int index = 0; index < GB_QUANTITY; index++)
  4452. {
  4453. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4454. {
  4455. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4456. }
  4457. }
  4458. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4459. }
  4460. else
  4461. {
  4462. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4463. {
  4464. tempIndex = 2;
  4465. }
  4466. else
  4467. {
  4468. tempIndex = gun_index;
  4469. }
  4470. for (int index = 0; index < AC_QUANTITY; index++)
  4471. {
  4472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4473. {
  4474. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4475. }
  4476. }
  4477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4478. }
  4479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4480. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4482. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4484. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4485. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4486. {
  4487. //idx_sample=5;
  4488. //sampledValue = NULL;
  4489. //***********************************************(6)SOC******************************************************/
  4490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4491. {
  4492. tempIndex = ((gun_index==2) ? 1: 0);
  4493. }
  4494. else
  4495. {
  4496. tempIndex = gun_index;
  4497. }
  4498. if(gunType[gun_index] == 'J')
  4499. {
  4500. //tempIndex = ((gun_index==2) ? 1: 0);
  4501. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4504. {
  4505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4506. }
  4507. }
  4508. }
  4509. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4510. {
  4511. //tempIndex = ((gun_index==2) ? 1: 0);
  4512. for (int index = 0; index < CCS_QUANTITY; index++)
  4513. {
  4514. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4515. {
  4516. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4517. }
  4518. }
  4519. }
  4520. else if(gunType[gun_index] == 'G')
  4521. {
  4522. //tempIndex = ((gun_index==2) ? 1: 0);
  4523. for (int index = 0; index < GB_QUANTITY; index++)
  4524. {
  4525. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4526. {
  4527. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4528. }
  4529. }
  4530. }
  4531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4535. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4536. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4537. }
  4538. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4539. {
  4540. sprintf(queuedata,"%d,[%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\"}]}]}]"
  4541. ,gun_index + 1
  4542. ,MESSAGE_TYPE_CALL
  4543. ,guid
  4544. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4545. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4546. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4547. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4548. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4549. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4550. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4551. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4552. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4553. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4554. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4555. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4556. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4557. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4558. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4559. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4560. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4561. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4562. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4563. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4589. );
  4590. }
  4591. else
  4592. {
  4593. sprintf(queuedata,"%d,[%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\"}]}]}]"
  4594. ,gun_index + 1
  4595. ,MESSAGE_TYPE_CALL
  4596. ,guid
  4597. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4598. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4599. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4635. );
  4636. }
  4637. // Put request guid to hash map
  4638. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4639. 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*/)
  4640. {
  4641. result = PASS;
  4642. DEBUG_INFO("MeterValues mapitem pass\n");
  4643. }
  4644. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4645. if(GetTransactionQueueNum() == 1)
  4646. {
  4647. LWS_Send(queuedata +2);
  4648. }
  4649. return result;
  4650. }
  4651. //==========================================
  4652. // send confirm routine
  4653. //==========================================
  4654. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4655. {
  4656. mtrace();
  4657. int result = FAIL;
  4658. char message[100]={0};
  4659. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4660. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4661. LWS_Send(message);
  4662. result = TRUE;
  4663. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4664. return result;
  4665. }
  4666. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4667. {
  4668. mtrace();
  4669. int result = FAIL;
  4670. char message[100]={0};
  4671. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4672. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4673. LWS_Send(message);
  4674. result = TRUE;
  4675. return result;
  4676. }
  4677. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4678. {
  4679. mtrace();
  4680. int result = FAIL;
  4681. char message[100]={0};
  4682. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4683. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4684. LWS_Send(message);
  4685. result = TRUE;
  4686. return result;
  4687. }
  4688. int sendClearCacheConfirmation(char *uuid,char *payload)
  4689. {
  4690. mtrace();
  4691. int result = FAIL;
  4692. char message[500]={0};
  4693. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4694. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4695. LWS_Send(message);
  4696. return result;
  4697. }
  4698. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4699. {
  4700. mtrace();
  4701. int result = FAIL;
  4702. char message[500]={0};
  4703. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4704. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4705. LWS_Send(message);
  4706. return result;
  4707. }
  4708. int sendDataTransferConfirmation(char *uuid,char *payload)
  4709. {
  4710. mtrace();
  4711. char statusStr[20]={0};
  4712. char dataStr[10]={0};
  4713. char sstr[20]={0};
  4714. int c = 0;
  4715. char *loc;
  4716. int result = FAIL;
  4717. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4718. /**********************status**************************/
  4719. loc = strstr(payload, "status");
  4720. memset(sstr ,0, sizeof(sstr) );
  4721. c = 0;
  4722. while (loc[3+strlen("status")+c] != '\"')
  4723. {
  4724. sstr[c] = loc[3+strlen("status")+c];
  4725. c++;
  4726. }
  4727. sstr[c] = '\0';
  4728. strcpy(statusStr, sstr);
  4729. /**********************data**************************/
  4730. loc = strstr(payload, "data");
  4731. memset(sstr ,0, sizeof(sstr) );
  4732. c = 0;
  4733. while (loc[3+strlen("data")+c] != '\"')
  4734. {
  4735. sstr[c] = loc[3+strlen("data")+c];
  4736. c++;
  4737. }
  4738. sstr[c] = '\0';
  4739. strcpy(dataStr, sstr);
  4740. return result;
  4741. }
  4742. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4743. {
  4744. mtrace();
  4745. int result = FAIL;
  4746. char message[1000]={0};
  4747. int CompositeScheduleIndex = 0;
  4748. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4749. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4750. if(nPeriod == 0)
  4751. {
  4752. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4753. {
  4754. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4755. ,MESSAGE_TYPE_CALLRESULT
  4756. ,uuid
  4757. ,payload
  4758. ,connectorIdInt);
  4759. }
  4760. else
  4761. {
  4762. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":0,\"numberPhases\":3}]}}]"
  4763. ,MESSAGE_TYPE_CALLRESULT
  4764. ,uuid
  4765. ,payload
  4766. ,connectorIdInt
  4767. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4768. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4769. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4770. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4771. }
  4772. }
  4773. else
  4774. {
  4775. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4776. ,MESSAGE_TYPE_CALLRESULT
  4777. ,uuid
  4778. ,payload
  4779. ,connectorIdInt
  4780. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4781. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4782. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4783. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4784. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4785. {
  4786. if (idx_sample == 0)
  4787. {
  4788. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4789. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4790. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4791. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4792. }
  4793. else
  4794. {
  4795. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4796. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4797. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4798. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4799. }
  4800. }
  4801. sprintf(message + strlen(message), "]}}]");
  4802. }
  4803. LWS_Send(message);
  4804. result = TRUE;
  4805. return result;
  4806. }
  4807. int sendGetConfigurationConfirmation(char *uuid)
  4808. {
  4809. mtrace();
  4810. int result = FAIL;
  4811. int MaxKeySupported = 0;
  4812. int sentConfigurationNumber= 0;
  4813. int sentunConfigurationNumber= 0;
  4814. char message[4000]={0};
  4815. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4816. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4817. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4818. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4819. ,MESSAGE_TYPE_CALLRESULT
  4820. ,uuid );
  4821. //configuration key
  4822. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4823. {
  4824. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4825. {
  4826. if (sentConfigurationNumber == 0)
  4827. {
  4828. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4829. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4830. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4831. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4832. }
  4833. else
  4834. {
  4835. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4836. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4837. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4838. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4839. }
  4840. sentConfigurationNumber = sentConfigurationNumber + 1;
  4841. }
  4842. }
  4843. sprintf(message + strlen(message), "]");
  4844. if(UnknownKeynum != 0)
  4845. {
  4846. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4847. //unkown key
  4848. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4849. {
  4850. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4851. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4852. if(sentunConfigurationNumber == 0)
  4853. {
  4854. sprintf(message + strlen(message), "\"%s\""
  4855. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4856. }
  4857. else
  4858. {
  4859. sprintf(message + strlen(message), ",\"%s\""
  4860. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4861. }
  4862. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4863. }
  4864. sprintf(message + strlen(message), "]");
  4865. }
  4866. sprintf(message + strlen(message), "}]");
  4867. LWS_Send(message);
  4868. return result;
  4869. }
  4870. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4871. {
  4872. mtrace();
  4873. int result = FAIL;
  4874. char message[400]={0};
  4875. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4876. if(strcmp(payload,"")==0)
  4877. {
  4878. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4879. }
  4880. else
  4881. {
  4882. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4883. }
  4884. LWS_Send(message);
  4885. result = TRUE;
  4886. return result;
  4887. }
  4888. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4889. {
  4890. mtrace();
  4891. int result = FAIL;
  4892. char message[80]={0};
  4893. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4894. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4895. LWS_Send(message);
  4896. result = TRUE;
  4897. return result;
  4898. }
  4899. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4900. {
  4901. mtrace();
  4902. int result = FAIL;
  4903. char message[80]={0};
  4904. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4906. LWS_Send(message);
  4907. result = TRUE;
  4908. return result;
  4909. }
  4910. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4911. {
  4912. mtrace();
  4913. int result = FAIL;
  4914. char message[80]={0};
  4915. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4916. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4917. LWS_Send(message);
  4918. result = TRUE;
  4919. return result;
  4920. }
  4921. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4922. {
  4923. mtrace();
  4924. int result = FAIL;
  4925. char message[80]={0};
  4926. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4927. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4928. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4929. LWS_Send(message);
  4930. result = TRUE;
  4931. return result;
  4932. }
  4933. int sendResetConfirmation(char *uuid,char *payload)
  4934. {
  4935. mtrace();
  4936. int result = FAIL;
  4937. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4938. char message[80]={0};
  4939. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4940. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4941. LWS_Send(message);
  4942. result = TRUE;
  4943. return result;
  4944. }
  4945. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4946. {
  4947. mtrace();
  4948. int result = FAIL;
  4949. char message[500]={0};
  4950. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4951. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4952. LWS_Send(message);
  4953. result = TRUE;
  4954. return result;
  4955. }
  4956. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4957. {
  4958. mtrace();
  4959. int result = FAIL;
  4960. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4961. char message[80]={0};
  4962. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4964. LWS_Send(message);
  4965. result = TRUE;
  4966. return result;
  4967. }
  4968. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4969. {
  4970. mtrace();
  4971. int result = FAIL;
  4972. char message[80]={0};
  4973. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  4974. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4975. LWS_Send(message);
  4976. result = TRUE;
  4977. return result;
  4978. }
  4979. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  4980. {
  4981. mtrace();
  4982. int result = FAIL;
  4983. char message[80]={0};
  4984. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4985. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  4986. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4987. LWS_Send(message);
  4988. result = TRUE;
  4989. return result;
  4990. }
  4991. int sendUpdateFirmwareConfirmation(char *uuid)
  4992. {
  4993. mtrace();
  4994. int result = FAIL;
  4995. char message[60]={0};
  4996. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4997. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  4998. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4999. LWS_Send(message);
  5000. result = TRUE;
  5001. return result;
  5002. }
  5003. //==========================================
  5004. // send CallError routine
  5005. //==========================================
  5006. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5007. {
  5008. mtrace();
  5009. char message[220]={0};
  5010. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5011. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5012. LWS_Send(message);
  5013. }
  5014. //==========================================
  5015. // Handle server request routine Start
  5016. //==========================================
  5017. int handleCancelReservationRequest(char *uuid, char *payload)
  5018. {
  5019. mtrace();
  5020. int result = FAIL;
  5021. int gunNO = 0;
  5022. int reservationIdInt =0;
  5023. char comfirmstr[20];
  5024. DEBUG_INFO("handleCancelReservationRequest...\n");
  5025. json_object *CancelReservation;
  5026. CancelReservation = json_tokener_parse(payload);
  5027. if(!is_error(CancelReservation))
  5028. {
  5029. // Required data
  5030. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5031. }
  5032. json_object_put(CancelReservation);
  5033. memset(comfirmstr, 0, sizeof comfirmstr);
  5034. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5035. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5036. //check Transaction active
  5037. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5038. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5039. {
  5040. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5041. {
  5042. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5043. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5044. if(gunType[2] == 'J')
  5045. {
  5046. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5047. }
  5048. else
  5049. {
  5050. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5051. }
  5052. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5053. goto end;
  5054. }
  5055. }
  5056. for (int index = 0; index < CCS_QUANTITY; index++)
  5057. {
  5058. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5059. {
  5060. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5061. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5062. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5063. {
  5064. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5065. }
  5066. else
  5067. {
  5068. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5069. }
  5070. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5071. goto end;
  5072. }
  5073. }
  5074. for (int index = 0; index < GB_QUANTITY; index++)
  5075. {
  5076. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5077. {
  5078. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5079. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5080. if(gunType[2] == 'G')
  5081. {
  5082. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5083. }
  5084. else
  5085. {
  5086. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5087. }
  5088. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5089. goto end;
  5090. }
  5091. }
  5092. for (int index = 0; index < AC_QUANTITY; index++)
  5093. {
  5094. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5095. {
  5096. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5097. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5099. {
  5100. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5101. }
  5102. else
  5103. {
  5104. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5105. }
  5106. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5107. goto end;
  5108. }
  5109. }
  5110. //The reservationId does NOT match the reservationId
  5111. sendCancelReservationConfirmation(uuid, comfirmstr);
  5112. end:
  5113. // Fill in ocpp packet uuid
  5114. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5115. return result;
  5116. }
  5117. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5118. {
  5119. mtrace();
  5120. int result = FAIL;
  5121. int gunIndex = 0;
  5122. char typeStr[16]={0};
  5123. char comfirmstr[20];
  5124. int specificId = FALSE;
  5125. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5126. json_object *ChangeAvailability;
  5127. ChangeAvailability = json_tokener_parse(payload);
  5128. if(!is_error(ChangeAvailability))
  5129. {
  5130. // Required data
  5131. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5132. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5133. }
  5134. json_object_put(ChangeAvailability);
  5135. if(gunIndex != 0)
  5136. {
  5137. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5138. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5139. }
  5140. else
  5141. {
  5142. for(int i=0; i < gunTotalNumber; i++)
  5143. {
  5144. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5145. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5146. }
  5147. }
  5148. memset(comfirmstr, 0, sizeof comfirmstr);
  5149. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5150. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5151. {
  5152. specificId = TRUE;
  5153. }
  5154. if(specificId == FALSE)
  5155. goto end;
  5156. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5157. {
  5158. //----------------------gunIndex is 0 ------------------------------------------------//
  5159. if(gunIndex == 0)
  5160. {
  5161. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5162. {
  5163. for(int i=0; i < gunTotalNumber; i++)
  5164. {
  5165. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5166. {
  5167. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5168. {
  5169. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5170. {
  5171. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5172. goto end;
  5173. }
  5174. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5175. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5176. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5177. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5178. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5179. {
  5180. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5181. goto end;
  5182. }
  5183. }
  5184. }//END FOR CHAdeMO_QUANTITY
  5185. for (int index = 0; index < CCS_QUANTITY; index++)
  5186. {
  5187. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5188. {
  5189. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5190. {
  5191. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5192. goto end;
  5193. }
  5194. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5195. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5196. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5197. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5198. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5199. {
  5200. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5201. goto end;
  5202. }
  5203. }
  5204. }//END FOR CCS_QUANTITY
  5205. for (int index = 0; index < GB_QUANTITY; index++)
  5206. {
  5207. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5208. {
  5209. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5210. {
  5211. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5212. goto end;
  5213. }
  5214. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5215. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5216. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5217. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5218. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5219. {
  5220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5221. goto end;
  5222. }
  5223. }
  5224. }// END FOR GB_QUANTITY
  5225. for (int index = 0; index < AC_QUANTITY; index++)
  5226. {
  5227. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5228. {
  5229. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5230. {
  5231. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5232. goto end;
  5233. }
  5234. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5235. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5236. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5237. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5238. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5239. {
  5240. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5241. goto end;
  5242. }
  5243. }
  5244. }//END FOR AC_QUANTITY
  5245. }// END FOR gunTotalNumber
  5246. }
  5247. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5248. {
  5249. for(int i=0; i < gunTotalNumber; i++)
  5250. {
  5251. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5252. {
  5253. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5254. goto end;
  5255. }
  5256. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5259. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5260. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5261. {
  5262. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5263. goto end;
  5264. }
  5265. }
  5266. }
  5267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5268. goto end;
  5269. }
  5270. //----------------------gunIndex is not 0 ------------------------------------------------//
  5271. //check Transaction active
  5272. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5273. {
  5274. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5275. {
  5276. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5277. {
  5278. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5279. goto end;
  5280. }
  5281. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5285. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5286. {
  5287. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5288. goto end;
  5289. }
  5290. else
  5291. {
  5292. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5293. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5294. goto end;
  5295. }
  5296. }
  5297. }//END FOR CHAdeMO_QUANTITY
  5298. for (int index = 0; index < CCS_QUANTITY; index++)
  5299. {
  5300. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5301. {
  5302. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5303. {
  5304. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5305. goto end;
  5306. }
  5307. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5308. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5312. {
  5313. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5314. goto end;
  5315. }
  5316. else
  5317. {
  5318. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5319. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5320. goto end;
  5321. }
  5322. }
  5323. }//END FOR CCS_QUANTITY
  5324. for (int index = 0; index < GB_QUANTITY; index++)
  5325. {
  5326. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5327. {
  5328. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5329. {
  5330. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5331. goto end;
  5332. }
  5333. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5336. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5337. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5338. {
  5339. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5340. goto end;
  5341. }
  5342. else
  5343. {
  5344. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5345. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5346. goto end;
  5347. }
  5348. }
  5349. }// END FOR GB_QUANTITY
  5350. for (int index = 0; index < AC_QUANTITY; index++)
  5351. {
  5352. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5353. {
  5354. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5355. {
  5356. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5357. goto end;
  5358. }
  5359. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5360. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5362. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5363. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5364. {
  5365. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5366. goto end;
  5367. }
  5368. else
  5369. {
  5370. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5371. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5372. goto end;
  5373. }
  5374. }
  5375. }//END FOR AC_QUANTITY
  5376. }//END FOR AvailabilityTypeStr[Inoperative]
  5377. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5378. {
  5379. //----------------------gunIndex is 0 ------------------------------------------------//
  5380. if(gunIndex == 0)
  5381. {
  5382. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5383. {
  5384. for(int i=0; i < gunTotalNumber; i++)
  5385. {
  5386. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5387. {
  5388. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5389. {
  5390. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5391. goto end;
  5392. }
  5393. }//END FOR CHAdeMO_QUANTITY
  5394. for (int index = 0; index < CCS_QUANTITY; index++)
  5395. {
  5396. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5397. {
  5398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5399. goto end;
  5400. }
  5401. }//END FOR CCS_QUANTITY
  5402. for (int index = 0; index < GB_QUANTITY; index++)
  5403. {
  5404. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5405. {
  5406. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5407. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5408. goto end;
  5409. }
  5410. }// END FOR GB_QUANTITY
  5411. for (int index = 0; index < AC_QUANTITY; index++)
  5412. {
  5413. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5414. {
  5415. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5416. goto end;
  5417. }
  5418. }//END FOR CHAdeMO_QUANTITY
  5419. }// END FOR gunTotalNumber
  5420. }
  5421. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5422. {
  5423. for(int i=0; i < gunTotalNumber; i++)
  5424. {
  5425. for (int index = 0; index < AC_QUANTITY; index++)
  5426. {
  5427. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5428. {
  5429. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5430. goto end;
  5431. }
  5432. }//END FOR CHAdeMO_QUANTITY
  5433. } // END FOR gunTotalNumber
  5434. }
  5435. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5436. goto end;
  5437. }
  5438. //----------------------gunIndex is not 0 ------------------------------------------------//
  5439. //check Transaction active
  5440. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5441. {
  5442. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5443. {
  5444. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5445. goto end;
  5446. }
  5447. }//END FOR CHAdeMO_QUANTITY
  5448. for (int index = 0; index < CCS_QUANTITY; index++)
  5449. {
  5450. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5451. {
  5452. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5453. goto end;
  5454. }
  5455. }//END FOR CCS_QUANTITY
  5456. for (int index = 0; index < GB_QUANTITY; index++)
  5457. {
  5458. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5459. {
  5460. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5461. goto end;
  5462. }
  5463. }// END FOR GB_QUANTITY
  5464. for (int index = 0; index < AC_QUANTITY; index++)
  5465. {
  5466. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5467. {
  5468. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5469. goto end;
  5470. }
  5471. }//END FOR AC_QUANTITY
  5472. }//END FOR AvailabilityTypeStr[Operative]
  5473. end:
  5474. if(gunIndex != 0)
  5475. {
  5476. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5477. }
  5478. else
  5479. {
  5480. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5481. }
  5482. if(gunIndex != 0)
  5483. {
  5484. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5485. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5486. }
  5487. else
  5488. {
  5489. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5490. {
  5491. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5492. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5493. }
  5494. }
  5495. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5496. return result;
  5497. }
  5498. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5499. {
  5500. mtrace();
  5501. int result = FAIL;
  5502. char keystr[40]={0};
  5503. char valuestr[100]={0};
  5504. char comfirmstr[20]={0};
  5505. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5506. json_object *ChangeConfiguration;
  5507. ChangeConfiguration = json_tokener_parse(payload);
  5508. if(!is_error(ChangeConfiguration))
  5509. {
  5510. // Required data
  5511. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5512. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5513. }
  5514. json_object_put(ChangeConfiguration);
  5515. if((uuid==NULL) || (payload ==NULL) )
  5516. {
  5517. DEBUG_ERROR("Payload is null\n");
  5518. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5519. }
  5520. else
  5521. {
  5522. int status = setKeyValue(keystr, valuestr);
  5523. switch(status)
  5524. {
  5525. case ConfigurationStatus_Accepted:
  5526. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5527. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5528. StoreConfigurationTable();
  5529. break;
  5530. case ConfigurationStatus_Rejected:
  5531. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5532. break;
  5533. case RebootRequired:
  5534. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5535. StoreConfigurationTable();
  5536. break;
  5537. case NotSupported:
  5538. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5539. break;
  5540. default:
  5541. break;
  5542. }
  5543. }
  5544. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5545. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5546. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5547. {
  5548. ChageWebSocketPingInterval(atoi(valuestr));
  5549. }
  5550. return result;
  5551. }
  5552. int handleClearCacheRequest(char *uuid, char *payload)
  5553. {
  5554. mtrace();
  5555. int result = FAIL;
  5556. char comfirmstr[20];
  5557. int fd;
  5558. char rmFileCmd[100]={0};
  5559. struct stat stats;
  5560. DEBUG_INFO("handleClearCacheRequest...\n");
  5561. stat("/Storage/OCPP", &stats);
  5562. // Check for directory existence
  5563. if (S_ISDIR(stats.st_mode) == 1)
  5564. {}
  5565. else
  5566. {
  5567. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5568. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5569. system(rmFileCmd);
  5570. }
  5571. memset(rmFileCmd, 0, sizeof rmFileCmd);
  5572. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5573. {
  5574. DEBUG_INFO("AuthorizationCache file exist.\n");
  5575. }
  5576. else
  5577. {
  5578. DEBUG_INFO("AuthorizationCache file not exist\n");
  5579. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5580. if(log == NULL)
  5581. {
  5582. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5583. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5584. goto end;
  5585. }
  5586. else
  5587. {
  5588. fclose(log);
  5589. }
  5590. }
  5591. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5592. {
  5593. DEBUG_INFO("open AuthorizationCache file failed\n");
  5594. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5595. }
  5596. else
  5597. {
  5598. DEBUG_INFO("open AuthorizationCache file successful\n");
  5599. ftruncate(fd,0);
  5600. lseek(fd,0,SEEK_SET);
  5601. close(fd);
  5602. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5603. }
  5604. end:
  5605. sendClearCacheConfirmation(uuid, comfirmstr);
  5606. return result;
  5607. }
  5608. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5609. {
  5610. mtrace();
  5611. int result = FAIL;
  5612. int resultRename;
  5613. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5614. char chargingProfilePurposeStr[26]={0};
  5615. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5616. char tempchargingProfilePurposeStr[26]={0};
  5617. char sstr[160]={0};
  5618. char str[100]={0};
  5619. int c = 0;
  5620. char *loc;
  5621. char fname[200]={0};
  5622. char comfirmstr[20]={0};
  5623. char word[1600]={0};
  5624. int clearflag = FALSE;
  5625. int chargingProfileIdIsNULL = FALSE;
  5626. int connectorIsNULL = FALSE;
  5627. int chargingProfilePurposeIsNULL = FALSE;
  5628. int stackLevelIsNULL = FALSE;
  5629. //int GotoEnd = FALSE;
  5630. FILE *fptr1, *fptr2;
  5631. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5632. int n_chargingProfile=0;
  5633. int isEmptyFile = FALSE;
  5634. char sLineWord[1600]={0};
  5635. char chargingProfiles[10][100]={0};
  5636. int ChargeProfileCount = 0;
  5637. char ch;
  5638. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5639. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5640. json_object *ClearChargingProfile;
  5641. ClearChargingProfile = json_tokener_parse(payload);
  5642. if(!is_error(ClearChargingProfile))
  5643. {
  5644. // Optional data
  5645. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5646. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5647. else
  5648. chargingProfileIdIsNULL = TRUE;
  5649. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5650. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5651. else
  5652. connectorIsNULL = TRUE;
  5653. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5654. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5655. else
  5656. chargingProfilePurposeIsNULL = TRUE;
  5657. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5658. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5659. else
  5660. stackLevelIsNULL = TRUE;
  5661. }
  5662. json_object_put(ClearChargingProfile);
  5663. if(connectorIsNULL == FALSE)
  5664. {
  5665. switch(connectorIdInt)
  5666. {
  5667. case 0:
  5668. if(chargingProfilePurposeIsNULL == TRUE)
  5669. {
  5670. int l = 0;
  5671. strcpy(fname, ChargePointMaxProfile_JSON);
  5672. if((access(fname,F_OK))!=-1)
  5673. {
  5674. strcpy(chargingProfiles[l], fname);
  5675. l = l + 1;
  5676. }
  5677. strcpy(fname, TxDefaultProfile_0_JSON);
  5678. if((access(fname,F_OK))!=-1)
  5679. {
  5680. strcpy(chargingProfiles[l], fname);
  5681. l = l + 1;
  5682. }
  5683. ChargeProfileCount = l;
  5684. }
  5685. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5686. {
  5687. strcpy(fname, ChargePointMaxProfile_JSON);
  5688. if((access(fname,F_OK))!=-1)
  5689. {
  5690. strcpy(chargingProfiles[0], fname);
  5691. ChargeProfileCount = 1;
  5692. }
  5693. }
  5694. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5695. {
  5696. strcpy(fname, TxDefaultProfile_0_JSON);
  5697. if((access(fname,F_OK))!=-1)
  5698. {
  5699. strcpy(chargingProfiles[0], fname);
  5700. ChargeProfileCount = 1;
  5701. }
  5702. }
  5703. break;
  5704. default:
  5705. if(chargingProfilePurposeIsNULL == TRUE)
  5706. {
  5707. int m = 0;
  5708. memset(fname, 0, sizeof fname);
  5709. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5710. if((access(fname,F_OK))!=-1)
  5711. {
  5712. strcpy(chargingProfiles[m], fname);
  5713. m = m + 1;
  5714. }
  5715. memset(fname, 0, sizeof fname);
  5716. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5717. if((access(fname,F_OK))!=-1)
  5718. {
  5719. strcpy(chargingProfiles[m], fname);
  5720. m = m + 1;
  5721. }
  5722. ChargeProfileCount = m;
  5723. }
  5724. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5725. {
  5726. //strcpy(fname, TxDefaultProfile_1_JSON);
  5727. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5728. if((access(fname,F_OK))!=-1)
  5729. {
  5730. strcpy(chargingProfiles[0], fname);
  5731. ChargeProfileCount = 1;
  5732. }
  5733. }
  5734. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5735. {
  5736. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5737. if((access(fname,F_OK))!=-1)
  5738. {
  5739. strcpy(chargingProfiles[0], fname);
  5740. ChargeProfileCount = 1;
  5741. }
  5742. //strcpy(fname, TxProfile_1_JSON);
  5743. }
  5744. //strcpy(fname, ChargePointMaxProfile_JSON );
  5745. break;
  5746. }
  5747. }
  5748. else // Check all Charging Profiles
  5749. {
  5750. int i = 0;
  5751. char fnametemp[200]={0};
  5752. ChargeProfileCount = 0;
  5753. //Check ChargePointMaxProfile.json exit
  5754. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5755. {
  5756. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5757. i = i + 1;
  5758. }
  5759. //Check TxDefaultProfile_0.json exit
  5760. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5761. {
  5762. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5763. i = i + 1;
  5764. }
  5765. //Check TxDefaultProfile_%d.json
  5766. for(int j=1; j <= gunTotalNumber; j++)
  5767. {
  5768. memset(fnametemp, 0, sizeof fnametemp);
  5769. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5770. if((access(fnametemp,F_OK))!=-1)
  5771. {
  5772. strcpy(chargingProfiles[i], fnametemp);
  5773. i = i + 1;
  5774. }
  5775. }
  5776. //Check TxProfile_%d.json
  5777. for(int j=1; j <= gunTotalNumber; j++)
  5778. {
  5779. memset(fnametemp, 0, sizeof fnametemp);
  5780. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5781. if((access(fnametemp,F_OK))!=-1)
  5782. {
  5783. strcpy(chargingProfiles[i], fnametemp);
  5784. i = i + 1;
  5785. }
  5786. }
  5787. ChargeProfileCount = i;
  5788. }// End connectorIsNULL is TRUE
  5789. if(ChargeProfileCount == 0)
  5790. {
  5791. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5792. goto end;
  5793. }
  5794. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5795. {
  5796. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5797. goto end;
  5798. }
  5799. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5800. {
  5801. memset(str, 0, sizeof str);
  5802. // clear temp file
  5803. sprintf(str,"rm -f %s",temp);
  5804. system(str);
  5805. for(int k=0; k < ChargeProfileCount; k++)
  5806. {
  5807. memset(str, 0, sizeof str);
  5808. //clear file in C
  5809. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5810. system(str);
  5811. }
  5812. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5813. goto end;
  5814. }
  5815. else if(connectorIsNULL == TRUE)
  5816. {
  5817. for(int k=0; k < ChargeProfileCount; k++)
  5818. {
  5819. fptr1 = fopen(chargingProfiles[k], "r");
  5820. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5821. //Check Charging Profile Count
  5822. while(fscanf(fptr1, "%s", word) != EOF)
  5823. {
  5824. //DEBUG_INFO("word=%s\n",word);
  5825. if(strstr(word, "chargingProfileId")!= NULL)
  5826. {
  5827. //DEBUG_INFO("test chargingProfileId \n");
  5828. n_chargingProfile = n_chargingProfile + 1;
  5829. //DEBUG_INFO("chargingProfileId Found\n");
  5830. }
  5831. }
  5832. rewind(fptr1);
  5833. //search Charging Profile Element
  5834. //int i= 0;
  5835. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5836. {
  5837. //------------------------tempconnectorIdInt------------------------//
  5838. loc = strstr(sLineWord, "connectorId");
  5839. c = 0;
  5840. memset(sstr ,0, sizeof(sstr) );
  5841. while (loc[strlen("connectorId")+2+c] != ',')
  5842. {
  5843. sstr[c] = loc[strlen("connectorId")+2+c];
  5844. c++;
  5845. }
  5846. sstr[c] = '\0';
  5847. tempconnectorIdInt = atoi(sstr);
  5848. printf("file's gun number is %d\n", tempconnectorIdInt);
  5849. //--------------------------chargingProfileId--------------------//
  5850. c = 0;
  5851. loc = strstr(sLineWord, "chargingProfileId");
  5852. memset(sstr ,0, sizeof(sstr) );
  5853. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5854. {
  5855. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5856. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5857. c++;
  5858. }
  5859. sstr[c] = '\0';
  5860. tempchargingProfileIdInt = atoi(sstr);
  5861. //stackLevel
  5862. c = 0;
  5863. loc = strstr(sLineWord, "stackLevel");
  5864. memset(sstr ,0, sizeof(sstr) );
  5865. while (loc[strlen("stackLevel")+2+c] != ',')
  5866. {
  5867. sstr[c] = loc[strlen("stackLevel")+2+c];
  5868. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5869. c++;
  5870. }
  5871. sstr[c] = '\0';
  5872. tempstackLevelInt = atoi(sstr);
  5873. c = 0;
  5874. loc = strstr(sLineWord, "chargingProfilePurpose");
  5875. memset(sstr ,0, sizeof(sstr) );
  5876. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5877. {
  5878. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5879. c++;
  5880. }
  5881. sstr[c] = '\0';
  5882. strcpy(tempchargingProfilePurposeStr, sstr);
  5883. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5884. {
  5885. //------- not write to fptr2-------//
  5886. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5887. //clearflag = TRUE;
  5888. }
  5889. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5890. {
  5891. //------- not write to fptr2-------//
  5892. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5893. }
  5894. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5895. {
  5896. //------- not write to fptr2-------//
  5897. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5898. }
  5899. else
  5900. {
  5901. fprintf(fptr2, sLineWord);//writing data into file
  5902. }
  5903. memset(sLineWord, 0, sizeof sLineWord);
  5904. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5905. if(clearflag == TRUE)
  5906. {
  5907. fclose(fptr1);
  5908. fclose(fptr2);
  5909. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5910. system(str);
  5911. // clear temp file
  5912. sprintf(str,"rm -f %s",temp);
  5913. system(str);
  5914. }
  5915. else
  5916. {
  5917. fclose(fptr1);
  5918. fclose(fptr2);
  5919. memset(str, 0, sizeof str);
  5920. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5921. system(str);
  5922. resultRename = rename(temp, chargingProfiles[k]);
  5923. if(resultRename == 0)
  5924. {
  5925. DEBUG_INFO("File ChargingProfile renamed successfully");
  5926. }
  5927. else
  5928. {
  5929. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5930. }
  5931. if(comfirmstr[0]== 0)
  5932. {
  5933. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5934. }
  5935. //Check chargingProfile is empty file
  5936. /*------ Read the file ----------------*/
  5937. fptr1=fopen(chargingProfiles[k],"r");
  5938. ch=fgetc(fptr1);
  5939. rewind(fptr1);
  5940. memset(sLineWord, 0, sizeof sLineWord);
  5941. if(ch!=EOF)
  5942. {
  5943. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5944. {
  5945. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5946. if(sLineWord[0]=='\0')
  5947. {
  5948. isEmptyFile = TRUE;
  5949. break;
  5950. }
  5951. else
  5952. {
  5953. isEmptyFile = FALSE;
  5954. break;
  5955. }
  5956. }
  5957. }
  5958. fclose(fptr1);
  5959. if(isEmptyFile == TRUE)
  5960. {
  5961. memset(str, 0, sizeof str);
  5962. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5963. system(str);
  5964. }
  5965. }
  5966. }// End of while(int k=0; k < ChargePointCount; k++)
  5967. }
  5968. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5969. {
  5970. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5971. for(int k=0; k < ChargeProfileCount; k++)
  5972. {
  5973. fptr1 = fopen(chargingProfiles[k], "r");
  5974. fptr2 = fopen(temp, "w+");
  5975. //Check Charging Profile Count
  5976. while(fscanf(fptr1, "%s", word) != EOF)
  5977. {
  5978. //DEBUG_INFO("word=%s\n",word);
  5979. if(strstr(word, "chargingProfileId")!= NULL)
  5980. {
  5981. n_chargingProfile = n_chargingProfile + 1;
  5982. }
  5983. }
  5984. rewind(fptr1);
  5985. //search Charging Profile Element
  5986. //int i= 0;
  5987. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5988. {
  5989. //*************************tempconnectorIdInt*********************************/
  5990. loc = strstr(sLineWord, "connectorId");
  5991. c = 0;
  5992. memset(sstr ,0, sizeof(sstr) );
  5993. while (loc[strlen("connectorId")+2+c] != ',')
  5994. {
  5995. sstr[c] = loc[strlen("connectorId")+2+c];
  5996. c++;
  5997. }
  5998. sstr[c] = '\0';
  5999. tempconnectorIdInt = atoi(sstr);
  6000. //chargingProfileId
  6001. c = 0;
  6002. loc = strstr(sLineWord, "chargingProfileId");
  6003. memset(sstr ,0, sizeof(sstr) );
  6004. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6005. {
  6006. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6007. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6008. c++;
  6009. }
  6010. sstr[c] = '\0';
  6011. tempchargingProfileIdInt = atoi(sstr);
  6012. //stackLevel
  6013. c = 0;
  6014. loc = strstr(sLineWord, "stackLevel");
  6015. memset(sstr ,0, sizeof(sstr) );
  6016. while (loc[strlen("stackLevel")+2+c] != ',')
  6017. {
  6018. sstr[c] = loc[strlen("stackLevel")+2+c];
  6019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6020. c++;
  6021. }
  6022. sstr[c] = '\0';
  6023. tempstackLevelInt = atoi(sstr);
  6024. c = 0;
  6025. loc = strstr(sLineWord, "chargingProfilePurpose");
  6026. memset(sstr ,0, sizeof(sstr) );
  6027. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6028. {
  6029. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6030. c++;
  6031. }
  6032. sstr[c] = '\0';
  6033. strcpy(tempchargingProfilePurposeStr, sstr);
  6034. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6035. {
  6036. //------- not write to fptr2-------//
  6037. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6038. //clearflag = TRUE;
  6039. }
  6040. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6041. {
  6042. //------- not write to fptr2-------//
  6043. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6044. }
  6045. else if(stackLevelIsNULL == TRUE)
  6046. {
  6047. //Clear Whole File
  6048. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6049. clearflag = TRUE;
  6050. break;
  6051. }
  6052. else
  6053. {
  6054. fprintf(fptr2, sLineWord);//writing data into file
  6055. }
  6056. memset(sLineWord, 0, sizeof sLineWord);
  6057. }
  6058. if(clearflag == TRUE)
  6059. {
  6060. fclose(fptr1);
  6061. fclose(fptr2);
  6062. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6063. system(str);
  6064. // clear temp file
  6065. sprintf(str,"rm -f %s",temp);
  6066. system(str);
  6067. }
  6068. else
  6069. {
  6070. fclose(fptr1);
  6071. fclose(fptr2);
  6072. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6073. system(str);
  6074. resultRename = rename(temp, chargingProfiles[k]);
  6075. if(resultRename == 0)
  6076. {
  6077. DEBUG_INFO("File ChargingProfile renamed successfully");
  6078. }
  6079. else
  6080. {
  6081. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6082. }
  6083. if(comfirmstr[0]== 0)
  6084. {
  6085. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6086. }
  6087. //Check chargingProfile is empty file
  6088. /*------ Read the file ----------------*/
  6089. fptr1=fopen(chargingProfiles[k],"r");
  6090. ch=fgetc(fptr1);
  6091. rewind(fptr1);
  6092. memset(sLineWord, 0, sizeof sLineWord);
  6093. if(ch!=EOF)
  6094. {
  6095. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6096. {
  6097. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6098. if(sLineWord[0]=='\0')
  6099. {
  6100. isEmptyFile = TRUE;
  6101. break;
  6102. }
  6103. else
  6104. {
  6105. isEmptyFile = FALSE;
  6106. break;
  6107. }
  6108. }
  6109. }
  6110. fclose(fptr1);
  6111. if(isEmptyFile == TRUE)
  6112. {
  6113. memset(str, 0, sizeof str);
  6114. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6115. system(str);
  6116. }
  6117. /*------- End of reading ---------------*/
  6118. }
  6119. } // while(int k=0; k < ChargeProfileCount; k++)
  6120. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6121. end:
  6122. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6123. return result;
  6124. }
  6125. int handleDataTransferRequest(char *uuid, char *payload)
  6126. {
  6127. mtrace();
  6128. int result = FAIL;
  6129. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  6130. char tempvendorId[255]={0};
  6131. char tempmessageId[50]={0};
  6132. char tempdata[50]={0};
  6133. char message[80]={0};
  6134. DEBUG_INFO("handleDataTransferRequest...\n");
  6135. if((uuid != NULL) && (payload != NULL))
  6136. {
  6137. json_object *DataTransfer;
  6138. DataTransfer = json_tokener_parse(payload);
  6139. if(!is_error(DataTransfer))
  6140. {
  6141. // Required data
  6142. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6143. // Optional data
  6144. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6145. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6146. if(json_object_object_get(DataTransfer, "data") != NULL)
  6147. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6148. result = PASS;
  6149. }
  6150. json_object_put(DataTransfer);
  6151. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  6152. }
  6153. else
  6154. {
  6155. char guid[37]={0};
  6156. random_uuid(guid);
  6157. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  6158. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  6159. }
  6160. LWS_Send(message);
  6161. return result;
  6162. }
  6163. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6164. {
  6165. mtrace();
  6166. int result = FAIL;
  6167. int connectorIdInt, durationInt;
  6168. char chargingRateUnitStr[4]={0};
  6169. char comfirmstr[20];
  6170. int confirmPeriods = 0;
  6171. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6172. json_object *GetCompositeSchedule;
  6173. GetCompositeSchedule = json_tokener_parse(payload);
  6174. if(!is_error(GetCompositeSchedule))
  6175. {
  6176. // Required data
  6177. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6178. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6179. // Optional data
  6180. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6181. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6182. }
  6183. json_object_put(GetCompositeSchedule);
  6184. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6185. if((connectorIdInt == 0) ||
  6186. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6187. {
  6188. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6189. struct StructChargingProfile tmpProfile[1];
  6190. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6191. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6192. {
  6193. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6194. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6195. }
  6196. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6197. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6198. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6199. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6200. {
  6201. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6202. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6203. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6204. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6205. {
  6206. confirmPeriods = idx;
  6207. break;
  6208. }
  6209. }
  6210. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6211. }
  6212. else
  6213. {
  6214. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6215. }
  6216. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6217. return result;
  6218. }
  6219. int handleGetConfigurationRequest(char *uuid, char *payload)
  6220. {
  6221. mtrace();
  6222. int result = FAIL;
  6223. int MaxKeySupported = 0;
  6224. int n_keys = 0;
  6225. char requestKey[43][50]={0};
  6226. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6227. json_object *GetConfiguration;
  6228. GetConfiguration = json_tokener_parse(payload);
  6229. if(!is_error(GetConfiguration))
  6230. {
  6231. // Optional data
  6232. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6233. {
  6234. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6235. {
  6236. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6237. n_keys = idx + 1;
  6238. }
  6239. }
  6240. }
  6241. json_object_put(GetConfiguration);
  6242. UnknownKeynum = 0;
  6243. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6244. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6245. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6246. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6247. if(n_keys != 0)
  6248. {
  6249. for(int i=0;i<n_keys;i++)
  6250. {
  6251. getKeyValue(requestKey[i]);
  6252. }
  6253. }
  6254. else
  6255. {
  6256. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6257. getKeyValue("");
  6258. }
  6259. processUnkownKey();
  6260. sendGetConfigurationConfirmation(uuid);
  6261. return result;
  6262. }
  6263. static char fnamePlusPath[100]={0};
  6264. static char fnamePWithNoPath[60]={0};
  6265. void checkUploadLog(void)
  6266. {
  6267. FILE *fp;
  6268. /* Open the command for reading. */
  6269. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6270. if (fp == NULL) {
  6271. printf("Failed to run command\n" );
  6272. exit(1);
  6273. }
  6274. int ftppathlen = 0;
  6275. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6276. int i = 0;
  6277. /* Read the output a line at a time - output it. */
  6278. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6279. if(i==0)
  6280. {
  6281. ftppathlen = strlen(fnamePlusPath);
  6282. printf("%s\n", fnamePlusPath);
  6283. fnamePlusPath[ftppathlen]='\0';
  6284. break;
  6285. }
  6286. i= i+1;
  6287. }
  6288. /* close */
  6289. pclose(fp);
  6290. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6291. {
  6292. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6293. {
  6294. fnamePlusPath[k]='\0';
  6295. }
  6296. }
  6297. i=1;
  6298. //char fname[60]={0};
  6299. while(i < ftppathlen)
  6300. {
  6301. int len=ftppathlen-i;
  6302. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6303. {
  6304. printf("compare '/' all right\n");
  6305. break;
  6306. }
  6307. i=i+1;
  6308. }
  6309. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6310. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6311. fnamePWithNoPath[i+1] = '\0';
  6312. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6313. {
  6314. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6315. {
  6316. fnamePWithNoPath[j]='\0';
  6317. }
  6318. }
  6319. FILE* fp1 = fopen(fnamePlusPath, "r");
  6320. if (fp1)
  6321. {
  6322. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6323. // file exists
  6324. fclose(fp1);
  6325. }
  6326. else
  6327. {
  6328. // file doesn't exist
  6329. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6330. }
  6331. }
  6332. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6333. {
  6334. mtrace();
  6335. int result = FAIL;
  6336. char cmdBuf[512];
  6337. char fName[258];
  6338. time_t CurrentTime;
  6339. struct tm *tm;
  6340. pthread_t th_Status;
  6341. CurrentTime = time(NULL);
  6342. tm = localtime(&CurrentTime);
  6343. sprintf(fName ,"%s-%s-%04d%02d%02d%02d%02d%02d.zip", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber, (tm->tm_year+1900), (tm->tm_mon+1),tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
  6344. sendGetDiagnosticsConfirmation(uuid, fName);
  6345. system("exec /root/logPackTools 'log' 6");
  6346. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6347. system(cmdBuf);
  6348. checkUploadLog();
  6349. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6350. return result;
  6351. }
  6352. void* GetDiagnosticsProcess(void* data)
  6353. {
  6354. pthread_detach(pthread_self());
  6355. mtrace();
  6356. int retriesInt=0, retryIntervalInt=0;
  6357. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6358. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6359. 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};
  6360. int port=0;
  6361. char sstr[260]={ 0 };
  6362. int c = 0;
  6363. char *loc;
  6364. int isSuccess = FALSE;
  6365. char ftpbuf[200]={0};
  6366. char * pch;
  6367. char str[300]={ 0 };
  6368. strcpy(str,(const char*)data);
  6369. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6370. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6371. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6372. //****************location*******************/
  6373. c = 0;
  6374. memset(sstr ,0, sizeof(sstr) );
  6375. loc = strstr(str, "location");
  6376. while (loc[3+strlen("location")+c] != '\"')
  6377. {
  6378. sstr[c] = loc[3+strlen("location")+c];
  6379. c++;
  6380. }
  6381. sstr[c] = '\0';
  6382. strcpy(locationstr,sstr);
  6383. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6384. if(strcmp(locationstr,"")==0)
  6385. {
  6386. DEBUG_INFO("location is <Empty>!\n");
  6387. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6388. goto end;
  6389. }
  6390. //****************retries*******************/
  6391. c = 0;
  6392. loc = strstr(str, "retries");
  6393. if(loc == NULL)
  6394. {
  6395. retriesIsNULL = TRUE;
  6396. }
  6397. else
  6398. {
  6399. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6400. {
  6401. sstr[c] = loc[strlen("retries")+2+c];
  6402. c++;
  6403. }
  6404. sstr[c] = '\0';
  6405. retriesInt = atoi(sstr);
  6406. }
  6407. if(retriesIsNULL == TRUE)
  6408. {
  6409. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6410. }
  6411. //****************retryInterval*******************/
  6412. c = 0;
  6413. loc = strstr(str, "retryInterval");
  6414. if(loc == NULL)
  6415. {
  6416. retryIntervalIsNULL = TRUE;
  6417. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6418. }
  6419. else
  6420. {
  6421. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6422. {
  6423. sstr[c] = loc[strlen("retryInterval")+2+c];
  6424. c++;
  6425. }
  6426. sstr[c] = '\0';
  6427. retryIntervalInt = atoi(sstr);
  6428. }
  6429. //****************startTime*******************/
  6430. c = 0;
  6431. memset(sstr ,0, sizeof(sstr) );
  6432. loc = strstr(str, "startTime");
  6433. if(loc == NULL)
  6434. {
  6435. startTimeIsNULL = TRUE;
  6436. }
  6437. else
  6438. {
  6439. while (loc[3+strlen("startTime")+c] != '\"')
  6440. {
  6441. sstr[c] = loc[3+strlen("startTime")+c];
  6442. c++;
  6443. }
  6444. sstr[c] = '\0';
  6445. strcpy(startTimestr,sstr);
  6446. }
  6447. //****************stopTime*******************/
  6448. c = 0;
  6449. memset(sstr ,0, sizeof(sstr) );
  6450. loc = strstr(str, "stopTime");
  6451. if(loc == NULL)
  6452. {
  6453. stopTimeIsNULL = TRUE;
  6454. }
  6455. else
  6456. {
  6457. while (loc[3+strlen("stopTime")+c] != '\"')
  6458. {
  6459. sstr[c] = loc[3+strlen("stopTime")+c];
  6460. c++;
  6461. }
  6462. sstr[c] = '\0';
  6463. strcpy(stopTimestr,sstr);
  6464. }
  6465. memset(protocol, 0, sizeof(protocol));
  6466. memset(user, 0, sizeof(user) );
  6467. memset(password, 0, sizeof(password));
  6468. memset(host, 0, sizeof(host));
  6469. memset(path, 0, sizeof(path));
  6470. memset(ftppath, 0, sizeof(ftppath));
  6471. memset(host1, 0, sizeof(host1));
  6472. memset(path1, 0, sizeof(path1));
  6473. /*location: ftp://user:password@host:port/path*/
  6474. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6475. if((access(fnamePlusPath,F_OK))!=-1)
  6476. {
  6477. DEBUG_INFO("fnamePlusPath exist.\n");
  6478. }
  6479. else
  6480. {
  6481. DEBUG_INFO("fnamePlusPath not exist!\n");
  6482. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6483. goto end;
  6484. }
  6485. pch=strchr(locationstr,'@');
  6486. if(pch==NULL)
  6487. {
  6488. sscanf(locationstr,
  6489. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6490. protocol, host, &port, path);
  6491. strcpy(user,"anonymous");
  6492. strcpy(password,"");
  6493. }
  6494. else
  6495. {
  6496. //DEBUG_INFO("pch=%s\n", pch);
  6497. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6498. protocol, user, password, host, &port, path);
  6499. }
  6500. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6501. {
  6502. DEBUG_INFO("protocol is not ftp/http ! \n");
  6503. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6504. goto end;
  6505. }
  6506. if(strncmp(locationstr,"http", 4) == 0)
  6507. {
  6508. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6509. sprintf(ftppath,"/%s", path);
  6510. do{
  6511. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6512. sleep(retryIntervalInt);
  6513. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6514. if(!isSuccess)
  6515. {
  6516. DEBUG_INFO("Diagnostics fail.\n");
  6517. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6518. }
  6519. else
  6520. {
  6521. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6522. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6523. }
  6524. }
  6525. else
  6526. {
  6527. sscanf(host,"%[^/]%s",host1, path1);
  6528. sprintf(ftppath,"%s", path1);
  6529. int ftppathlen=strlen(ftppath);
  6530. int i=1;
  6531. char filenametemp[50];
  6532. while(i < ftppathlen)
  6533. {
  6534. int len=ftppathlen-i;
  6535. if(ftppath[len]== 47) // '/' ascll code: 47
  6536. {
  6537. DEBUG_INFO("find '/' all right\n");
  6538. break;
  6539. }
  6540. i=i+1;
  6541. }
  6542. memset(filenametemp, 0, sizeof(filenametemp));
  6543. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6544. filenametemp[i+1] = 0;
  6545. memset(ftpbuf, 0, sizeof(ftpbuf));
  6546. if(port == 0)
  6547. port = 21;
  6548. do{
  6549. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6550. sleep(retryIntervalInt);
  6551. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6552. if(!isSuccess)
  6553. {
  6554. DEBUG_INFO("Diagnostics fail.\n");
  6555. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6556. }
  6557. else
  6558. {
  6559. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6560. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6561. }
  6562. }
  6563. end:
  6564. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6565. pthread_exit(NULL);
  6566. }
  6567. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6568. {
  6569. mtrace();
  6570. int result = FAIL;
  6571. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6572. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6573. {
  6574. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6575. localversion = -1;
  6576. }
  6577. else
  6578. {
  6579. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6580. OCPP_getListVerion();
  6581. }
  6582. //from db.OCPP_getListVerion
  6583. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6584. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6585. sendGetLocalListVersionConfirmation(uuid,"");
  6586. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6587. return result;
  6588. }
  6589. int handleRemoteStartRequest(char *uuid, char *payload)
  6590. {
  6591. mtrace();
  6592. int result = FAIL;
  6593. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6594. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6595. int tempIndex = 0;
  6596. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6597. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6598. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6599. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6600. int chargingSchedulePeriodCount = 0;
  6601. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6602. int c = 0;
  6603. char *loc;
  6604. char comfirmstr[20]={0};
  6605. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6606. if(server_pending == TRUE)
  6607. {
  6608. return 0;
  6609. }
  6610. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6611. strcpy(sstrtemp, stringtrimspace(payload));
  6612. //**********connectorId****************/
  6613. c = 0;
  6614. memset(sstr ,0, sizeof(sstr) );
  6615. loc = strstr(sstrtemp, "connectorId");
  6616. if(loc == NULL)
  6617. {
  6618. connectorIdIsNULL = TRUE;
  6619. }
  6620. else
  6621. {
  6622. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6623. {
  6624. sstr[c] = loc[strlen("connectorId")+2+c];
  6625. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6626. c++;
  6627. }
  6628. sstr[c] = '\0';
  6629. connectorIdInt = atoi(sstr);
  6630. }
  6631. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6632. {
  6633. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6634. goto end;
  6635. }
  6636. //****************idTag*******************/
  6637. c = 0;
  6638. memset(sstr ,0, sizeof(sstr) );
  6639. loc = strstr(sstrtemp, "idTag");
  6640. while (loc[3+strlen("idTag")+c] != '\"')
  6641. {
  6642. sstr[c] = loc[3+strlen("idTag")+c];
  6643. c++;
  6644. }
  6645. sstr[c] = '\0';
  6646. strcpy(idTagstr,sstr);
  6647. //****************chargingProfile*******************/
  6648. c = 0;
  6649. memset(sstr ,0, sizeof(sstr) );
  6650. loc = strstr(sstrtemp, "chargingProfile");
  6651. if(loc == NULL)
  6652. {
  6653. chargingProfileIsNULL = TRUE;
  6654. }
  6655. else
  6656. {
  6657. //****************chargingProfileId*******************/
  6658. c=0;
  6659. loc = strstr(sstrtemp, "chargingProfileId");
  6660. memset(sstr ,0, sizeof(sstr) );
  6661. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6662. {
  6663. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6664. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6665. c++;
  6666. }
  6667. sstr[c] = '\0';
  6668. chargingProfileIdInt = atoi(sstr);
  6669. //****************transactionId*******************/
  6670. loc = strstr(sstrtemp, "transactionId");
  6671. if(loc == NULL)
  6672. {
  6673. transactionIdIsNULL = TRUE;
  6674. }
  6675. else
  6676. {
  6677. c=0;
  6678. memset(sstr ,0, sizeof(sstr) );
  6679. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6680. {
  6681. sstr[c] = loc[strlen("transactionId")+2+c];
  6682. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6683. c++;
  6684. }
  6685. sstr[c] = '\0';
  6686. transactionIdInt = atoi(sstr);
  6687. }
  6688. //****************stackLevel*******************/
  6689. c=0;
  6690. loc = strstr(sstrtemp, "stackLevel");
  6691. memset(sstr ,0, sizeof(sstr) );
  6692. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6693. {
  6694. sstr[c] = loc[strlen("stackLevel")+2+c];
  6695. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6696. c++;
  6697. }
  6698. sstr[c] = '\0';
  6699. stackLevelInt = atoi(sstr);
  6700. //****************chargingProfilePurpose*******************/
  6701. c = 0;
  6702. memset(sstr ,0, sizeof(sstr) );
  6703. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6704. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6705. {
  6706. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6707. c++;
  6708. }
  6709. sstr[c] = '\0';
  6710. strcpy(chargingProfilePurposestr,sstr);
  6711. //****************chargingProfileKind*******************/
  6712. c = 0;
  6713. memset(sstr ,0, sizeof(sstr) );
  6714. loc = strstr(sstrtemp, "chargingProfileKind");
  6715. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6716. {
  6717. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6718. c++;
  6719. }
  6720. sstr[c] = '\0';
  6721. strcpy(chargingProfileKindstr,sstr);
  6722. //****************recurrencyKind*******************/
  6723. loc = strstr(sstrtemp, "recurrencyKind");
  6724. if(loc == NULL)
  6725. {
  6726. recurrencyKindIsNULL = TRUE;
  6727. }
  6728. else
  6729. {
  6730. c = 0;
  6731. memset(sstr ,0, sizeof(sstr) );
  6732. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6733. {
  6734. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6735. c++;
  6736. }
  6737. sstr[c] = '\0';
  6738. strcpy(recurrencyKindstr,sstr);
  6739. }
  6740. //****************validFrom*******************/
  6741. loc = strstr(sstrtemp, "validFrom");
  6742. if(loc == NULL)
  6743. {
  6744. validFromIsNULL = TRUE;
  6745. }
  6746. else
  6747. {
  6748. c = 0;
  6749. memset(sstr ,0, sizeof(sstr) );
  6750. while (loc[3+strlen("validFrom")+c] != '\"')
  6751. {
  6752. sstr[c] = loc[3+strlen("validFrom")+c];
  6753. c++;
  6754. }
  6755. sstr[c] = '\0';
  6756. strcpy(validFromstr,sstr);
  6757. }
  6758. //****************validTo*******************/
  6759. loc = strstr(sstrtemp, "validTo");
  6760. if(loc == NULL)
  6761. {
  6762. validToIsNULL = TRUE;
  6763. }
  6764. else
  6765. {
  6766. c = 0;
  6767. memset(sstr ,0, sizeof(sstr) );
  6768. while (loc[3+strlen("validTo")+c] != '\"')
  6769. {
  6770. sstr[c] = loc[3+strlen("validTo")+c];
  6771. c++;
  6772. }
  6773. sstr[c] = '\0';
  6774. strcpy(validTostr,sstr);
  6775. }
  6776. //****************chargingSchedule*******************/
  6777. loc = strstr(sstrtemp, "chargingSchedule");
  6778. if(loc != NULL)
  6779. {
  6780. //****************duration*******************/
  6781. loc = strstr(sstrtemp, "duration");
  6782. if(loc == NULL)
  6783. {
  6784. durationIsNULL = TRUE;
  6785. }
  6786. else
  6787. {
  6788. c=0;
  6789. memset(sstr ,0, sizeof(sstr) );
  6790. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6791. {
  6792. sstr[c] = loc[strlen("duration")+2+c];
  6793. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6794. c++;
  6795. }
  6796. sstr[c] = '\0';
  6797. durationInt = atoi(sstr);
  6798. }
  6799. //****************startSchedule******************/
  6800. loc = strstr(sstrtemp, "startSchedule");
  6801. if(loc == NULL)
  6802. {
  6803. startScheduleIsNULL = TRUE;
  6804. }
  6805. else
  6806. {
  6807. c = 0;
  6808. memset(sstr ,0, sizeof(sstr) );
  6809. while (loc[3+strlen("startSchedule")+c] != '\"')
  6810. {
  6811. sstr[c] = loc[3+strlen("startSchedule")+c];
  6812. c++;
  6813. }
  6814. sstr[c] = '\0';
  6815. strcpy(startSchedulestr,sstr);
  6816. }
  6817. //****************chargingRateUnit*******************/
  6818. c = 0;
  6819. memset(sstr ,0, sizeof(sstr) );
  6820. loc = strstr(sstrtemp, "chargingRateUnit");
  6821. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6822. {
  6823. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6824. c++;
  6825. }
  6826. sstr[c] = '\0';
  6827. strcpy(chargingRateUnitstr,sstr);
  6828. //****************minChargingRate*******************/
  6829. loc = strstr(sstrtemp, "minChargingRate");
  6830. if(loc == NULL)
  6831. {
  6832. minChargingRateIsNULL = TRUE;
  6833. }
  6834. else
  6835. {
  6836. c=0;
  6837. memset(sstr ,0, sizeof(sstr) );
  6838. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6839. {
  6840. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6841. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6842. c++;
  6843. }
  6844. sstr[c] = '\0';
  6845. minChargingRateflaot = atof(sstr);
  6846. }
  6847. //****************chargingSchedulePeriod count*******************/
  6848. int what_len = strlen("startPeriod");
  6849. char *where = sstrtemp;
  6850. while ((where = strstr(where, "startPeriod"))) {
  6851. where += what_len;
  6852. chargingSchedulePeriodCount++;
  6853. }
  6854. where = sstrtemp;
  6855. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6856. {
  6857. //****************startPeriod*******************/
  6858. c=0;
  6859. loc = strstr(where, "startPeriod");
  6860. memset(sstr ,0, sizeof(sstr) );
  6861. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6862. {
  6863. sstr[c] = loc[strlen("startPeriod")+2+c];
  6864. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6865. c++;
  6866. }
  6867. sstr[c] = '\0';
  6868. startPeriodInt[periodNums] = atoi(sstr);
  6869. //****************limit*******************/
  6870. c=0;
  6871. loc = strstr(where, "limit");
  6872. memset(sstr ,0, sizeof(sstr) );
  6873. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6874. {
  6875. sstr[c] = loc[strlen("limit")+2+c];
  6876. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6877. c++;
  6878. }
  6879. sstr[c] = '\0';
  6880. limitflaot[periodNums] = atof(sstr);
  6881. //****************numberPhases*******************/
  6882. loc = strstr(where, "numberPhases");
  6883. if(loc == NULL)
  6884. {
  6885. numberPhasesIsNULL = TRUE;
  6886. }
  6887. else
  6888. {
  6889. c=0;
  6890. memset(sstr ,0, sizeof(sstr) );
  6891. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6892. {
  6893. sstr[c] = loc[strlen("numberPhases")+2+c];
  6894. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6895. c++;
  6896. }
  6897. sstr[c] = '\0';
  6898. numberPhasesInt[periodNums] = atoi(sstr);
  6899. }
  6900. where = loc;
  6901. } // END FOR chargingSchedulePeriodCount
  6902. }// END IF chargingSchedule
  6903. } // END chargingProfile
  6904. /*
  6905. enum _SYSTEM_STATUS
  6906. {
  6907. S_BOOTING = 0,
  6908. S_IDLE, = 1
  6909. S_AUTHORIZING, =2
  6910. S_REASSIGN_CHECK, =3
  6911. S_REASSIGN, =4
  6912. S_PRECHARGE, =5
  6913. S_PREPARING_FOR_EV, =6
  6914. S_PREPARING_FOR_EVSE, =7
  6915. S_CHARGING, =8
  6916. S_TERMINATING, =9
  6917. S_COMPLETE, =10
  6918. S_ALARM, =11
  6919. S_FAULT =12
  6920. }
  6921. */
  6922. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6923. {
  6924. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6925. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6926. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6927. //check Transaction active
  6928. if(gunType[connectorIdInt -1] == 'J')
  6929. {
  6930. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6931. {
  6932. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6933. }
  6934. else
  6935. {
  6936. tempIndex = connectorIdInt -1;
  6937. }
  6938. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6939. {
  6940. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6941. {
  6942. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6943. {
  6944. //Reserved
  6945. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6946. }
  6947. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6948. {
  6949. //Reserved
  6950. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6951. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6952. goto end;
  6953. }
  6954. else
  6955. {
  6956. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6957. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6958. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6959. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6960. {
  6961. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6962. goto end;
  6963. }
  6964. }//END FOR ELSE
  6965. }
  6966. }// END FOR CHAdeMO_QUANTITY
  6967. }
  6968. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6969. {
  6970. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6971. {
  6972. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6973. }
  6974. else
  6975. {
  6976. tempIndex = connectorIdInt -1;
  6977. }
  6978. for (int index = 0; index < CCS_QUANTITY; index++)
  6979. {
  6980. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6981. {
  6982. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6983. {
  6984. //Reserved
  6985. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6986. }
  6987. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6988. {
  6989. //Reserved
  6990. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6991. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6992. goto end;
  6993. }
  6994. else
  6995. {
  6996. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6997. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6998. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6999. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7000. {
  7001. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7002. goto end;
  7003. }
  7004. }// END FOR ELSE
  7005. }
  7006. }// END FOR CCS_QUANTITY
  7007. }
  7008. else if(gunType[connectorIdInt -1] == 'G')
  7009. {
  7010. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7011. {
  7012. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7013. }
  7014. else
  7015. {
  7016. tempIndex = connectorIdInt -1;
  7017. }
  7018. for (int index = 0; index < GB_QUANTITY; index++)
  7019. {
  7020. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7021. {
  7022. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7023. {
  7024. //Reserved
  7025. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7026. }
  7027. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7028. {
  7029. //Reserved
  7030. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7031. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7032. goto end;
  7033. }
  7034. else
  7035. {
  7036. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7037. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7038. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7039. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7040. {
  7041. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7042. goto end;
  7043. }
  7044. }// END FOR ELSE
  7045. }
  7046. } // END FOR GB_QUANTITY
  7047. }
  7048. else
  7049. {
  7050. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7051. {
  7052. tempIndex = 2;
  7053. }
  7054. else
  7055. {
  7056. tempIndex = connectorIdInt -1;
  7057. }
  7058. for (int index = 0; index < AC_QUANTITY; index++)
  7059. {
  7060. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7061. {
  7062. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7063. {
  7064. //Reserved
  7065. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7066. }
  7067. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7068. {
  7069. //Reserved
  7070. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7072. goto end;
  7073. }
  7074. else
  7075. {
  7076. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7077. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7078. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7079. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7080. {
  7081. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7082. goto end;
  7083. }
  7084. }//END FOR ELSE
  7085. }
  7086. }// END FOR AC_QUANTITY
  7087. }
  7088. if(chargingProfileIsNULL == FALSE)
  7089. {
  7090. //ChargingProfile
  7091. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7092. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7093. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7094. if(recurrencyKindIsNULL == FALSE) //OPTION
  7095. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7096. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7097. if(transactionIdIsNULL == FALSE) // OPTION
  7098. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7099. if(validFromIsNULL == FALSE) // OPTION
  7100. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7101. if(validToIsNULL == FALSE) //OPTION
  7102. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7103. //ChargingSchedule
  7104. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7105. if(durationIsNULL == FALSE) //OPTION
  7106. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7107. if(minChargingRateIsNULL == FALSE) //OPTION
  7108. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7109. if(startScheduleIsNULL == FALSE) //OPTION
  7110. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7111. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7112. {
  7113. //ChargingSchedulePeriod
  7114. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7115. if(numberPhasesIsNULL == FALSE)
  7116. {
  7117. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7118. }
  7119. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7120. }
  7121. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7122. {
  7123. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7124. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7125. //memset idTag
  7126. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7127. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7128. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7129. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7130. }
  7131. else
  7132. {
  7133. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7134. }
  7135. }
  7136. else
  7137. {
  7138. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7139. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7140. //memset idTag
  7141. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7142. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7143. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7144. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7145. }
  7146. }
  7147. else
  7148. {
  7149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7150. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7151. }
  7152. end:
  7153. if(connectorIdIsNULL == FALSE)
  7154. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7155. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7156. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7157. //OCPP send RemoteStartConfirmation by first.
  7158. sendRemoteStartConfirmation(uuid, comfirmstr);
  7159. return result;
  7160. }
  7161. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7162. {
  7163. mtrace();
  7164. int result = FAIL;
  7165. int match = FALSE;
  7166. int GunNO = 0;
  7167. int tempIndex = 0;
  7168. int transactionIdInt=0;
  7169. int transactionIdIsNULL= FALSE;
  7170. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7171. int c = 0;
  7172. char *loc;
  7173. char comfirmstr[20];
  7174. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7175. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7176. if(server_pending == TRUE)
  7177. {
  7178. return 0;
  7179. }
  7180. strcpy(sstrtemp, stringtrimspace(payload));
  7181. c=0;
  7182. loc = strstr(sstrtemp, "transactionId");
  7183. if(loc == NULL)
  7184. {
  7185. transactionIdIsNULL= TRUE;
  7186. }
  7187. else
  7188. {
  7189. memset(sstr ,0, sizeof(sstr) );
  7190. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7191. {
  7192. sstr[c] = loc[strlen("transactionId")+2+c];
  7193. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7194. c++;
  7195. }
  7196. sstr[c] = '\0';
  7197. transactionIdInt = atoi(sstr);
  7198. }
  7199. if(transactionIdIsNULL == FALSE)
  7200. {
  7201. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7202. {
  7203. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7204. {
  7205. //check Transaction active
  7206. if(gunType[gun_index] == 'J')
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((gun_index==2) ? 1: 0);
  7211. }
  7212. else
  7213. {
  7214. tempIndex = gun_index;
  7215. }
  7216. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7219. {
  7220. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7221. {
  7222. match = TRUE;
  7223. GunNO = gun_index;
  7224. }
  7225. }
  7226. }// END FOR CHAdeMO_QUANTITY
  7227. }
  7228. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7229. {
  7230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7231. {
  7232. tempIndex = ((gun_index==2) ? 1: 0);
  7233. }
  7234. else
  7235. {
  7236. tempIndex = gun_index;
  7237. }
  7238. for (int index = 0; index < CCS_QUANTITY; index++)
  7239. {
  7240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7241. {
  7242. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7243. {
  7244. match = TRUE;
  7245. GunNO = gun_index;
  7246. }
  7247. }
  7248. }// END FOR CCS_QUANTITY
  7249. }
  7250. else if(gunType[gun_index] == 'G')
  7251. {
  7252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7253. {
  7254. tempIndex = ((gun_index==2) ? 1: 0);
  7255. }
  7256. else
  7257. {
  7258. tempIndex = gun_index;
  7259. }
  7260. for (int index = 0; index < GB_QUANTITY; index++)
  7261. {
  7262. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7263. {
  7264. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7265. {
  7266. match = TRUE;
  7267. GunNO = gun_index;
  7268. }
  7269. }
  7270. }// END FOR GB_QUANTITY
  7271. }
  7272. else
  7273. {
  7274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7275. {
  7276. tempIndex = 2;
  7277. }
  7278. else
  7279. {
  7280. tempIndex = gun_index;
  7281. }
  7282. for (int index = 0; index < AC_QUANTITY; index++)
  7283. {
  7284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7285. {
  7286. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7287. {
  7288. match = TRUE;
  7289. GunNO = gun_index;
  7290. }
  7291. }
  7292. }// END FOR CHAdeMO_QUANTITY
  7293. } // END FOR AC ELSE
  7294. }// CHECK IF ResponseTransactionId == transactionIdInt
  7295. }//END FOR
  7296. if( match == TRUE)
  7297. {
  7298. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7299. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7300. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7301. }
  7302. else
  7303. {
  7304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7305. }
  7306. }
  7307. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7308. return result;
  7309. }
  7310. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7311. {
  7312. mtrace();
  7313. int result = FAIL;
  7314. int connectorIdInt=0, reservationIdInt=0;
  7315. int tempIndex = 0;
  7316. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7317. char comfirmstr[20]={0};
  7318. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7319. int c = 0;
  7320. char *loc;
  7321. //char *ptr;
  7322. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7323. strcpy(sstrtemp, stringtrimspace(payload));
  7324. //***(1)connectorId ****/
  7325. c=0;
  7326. loc = strstr(sstrtemp, "connectorId");
  7327. memset(sstr ,0, sizeof(sstr) );
  7328. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7329. {
  7330. sstr[c] = loc[strlen("connectorId")+2+c];
  7331. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. connectorIdInt = atoi(sstr);
  7336. //***(2)expiryDate ****/
  7337. loc = strstr(sstrtemp, "expiryDate");
  7338. memset(sstr ,0, sizeof(sstr) );
  7339. c = 0;
  7340. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7341. {
  7342. sstr[c] = loc[3+strlen("expiryDate")+c];
  7343. c++;
  7344. }
  7345. sstr[c] = '\0';
  7346. strcpy(expiryDatestr, sstr);
  7347. //***(3)idTag ****/
  7348. loc = strstr(sstrtemp, "idTag");
  7349. memset(sstr ,0, sizeof(sstr) );
  7350. c = 0;
  7351. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7352. {
  7353. sstr[c] = loc[3+strlen("idTag")+c];
  7354. c++;
  7355. }
  7356. sstr[c] = '\0';
  7357. strcpy(idTagstr, sstr);
  7358. //***(4)parentIdTag ****/
  7359. loc = strstr(sstrtemp, "parentIdTag");
  7360. memset(sstr ,0, sizeof(sstr) );
  7361. c = 0;
  7362. if(loc == NULL)
  7363. {
  7364. strcpy(parentIdTagstr, "");
  7365. }
  7366. else
  7367. {
  7368. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7369. {
  7370. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7371. c++;
  7372. }
  7373. sstr[c] = '\0';
  7374. strcpy(parentIdTagstr, sstr);
  7375. }
  7376. //***(5)reservationId ****/
  7377. c=0;
  7378. loc = strstr(sstrtemp, "reservationId");
  7379. memset(sstr ,0, sizeof(sstr) );
  7380. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7381. {
  7382. sstr[c] = loc[strlen("reservationId")+2+c];
  7383. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7384. c++;
  7385. }
  7386. sstr[c] = '\0';
  7387. reservationIdInt = atoi(sstr);
  7388. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7389. /*
  7390. enum SYSTEM_STATUS
  7391. {
  7392. SYS_MODE_BOOTING = 0,
  7393. SYS_MODE_IDLE = 1,
  7394. SYS_MODE_AUTHORIZING = 2,
  7395. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7396. SYS_MODE_REASSIGN = 4,
  7397. SYS_MODE_PREPARING = 5,
  7398. SYS_MODE_PREPARE_FOR_EV = 6,
  7399. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7400. SYS_MODE_CHARGING = 8,
  7401. SYS_MODE_TERMINATING = 9,
  7402. SYS_MODE_COMPLETE = 10,
  7403. SYS_MODE_ALARM = 11,
  7404. SYS_MODE_FAULT = 12,
  7405. SYS_MODE_RESERVATION = 13,
  7406. SYS_MODE_BOOKING = 14,
  7407. SYS_MODE_MAINTAIN = 15,
  7408. SYS_MODE_DEBUG = 16,
  7409. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7410. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7411. SYS_MODE_UPDATE = 19
  7412. };
  7413. */
  7414. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7415. {
  7416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7417. goto end;
  7418. }
  7419. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7420. {
  7421. //check Transaction active
  7422. if(gunType[connectorIdInt -1] == 'J')
  7423. {
  7424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7425. {
  7426. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7427. }
  7428. else
  7429. {
  7430. tempIndex = connectorIdInt -1;
  7431. }
  7432. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7433. {
  7434. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7435. {
  7436. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7437. {
  7438. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7439. {
  7440. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7441. {
  7442. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7443. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7444. }
  7445. 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'))
  7446. {
  7447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7448. }
  7449. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7450. {
  7451. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7452. }
  7453. else
  7454. {
  7455. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7456. }
  7457. }
  7458. 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
  7459. {
  7460. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7461. }
  7462. }
  7463. else
  7464. {
  7465. //replace reservation
  7466. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7467. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7468. }
  7469. }
  7470. } // END FOR CHAdeMO_QUANTITY
  7471. }
  7472. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7473. {
  7474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7475. {
  7476. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7477. }
  7478. else
  7479. {
  7480. tempIndex = connectorIdInt -1;
  7481. }
  7482. for (int index = 0; index < CCS_QUANTITY; index++)
  7483. {
  7484. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7485. {
  7486. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7487. {
  7488. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7489. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7490. {
  7491. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7492. {
  7493. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7495. }
  7496. 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'))
  7497. {
  7498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7499. }
  7500. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7501. {
  7502. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7503. }
  7504. else
  7505. {
  7506. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7507. }
  7508. }
  7509. 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
  7510. {
  7511. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7512. }
  7513. }
  7514. else
  7515. {
  7516. //replace reservation
  7517. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7518. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7519. }
  7520. }
  7521. } // END FOR CCS_QUANTITY
  7522. }
  7523. else if(gunType[connectorIdInt -1] == 'G')
  7524. {
  7525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7526. {
  7527. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7528. }
  7529. else
  7530. {
  7531. tempIndex = connectorIdInt -1;
  7532. }
  7533. for (int index = 0; index < GB_QUANTITY; index++)
  7534. {
  7535. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7536. {
  7537. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7538. {
  7539. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7540. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7541. {
  7542. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7543. {
  7544. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7545. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7546. }
  7547. 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'))
  7548. {
  7549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7550. }
  7551. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7552. {
  7553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7554. }
  7555. else
  7556. {
  7557. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7558. }
  7559. }
  7560. 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
  7561. {
  7562. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7563. }
  7564. }
  7565. else
  7566. {
  7567. //replace reservation
  7568. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7569. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7570. }
  7571. }
  7572. }// END FOR GB_QUANTITY
  7573. }
  7574. else
  7575. {
  7576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7577. {
  7578. tempIndex = 2;
  7579. }
  7580. else
  7581. {
  7582. tempIndex = (connectorIdInt -1);
  7583. }
  7584. for (int index = 0; index < AC_QUANTITY; index++)
  7585. {
  7586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7587. {
  7588. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7589. {
  7590. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7591. {
  7592. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7593. {
  7594. 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))
  7595. {
  7596. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7597. }
  7598. else
  7599. {
  7600. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7601. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7602. }
  7603. }
  7604. 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'))
  7605. {
  7606. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7607. }
  7608. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7609. {
  7610. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7611. }
  7612. else
  7613. {
  7614. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7615. }
  7616. }
  7617. 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
  7618. {
  7619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7620. }
  7621. }
  7622. else
  7623. {
  7624. //replace reservation
  7625. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7626. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7627. }
  7628. }
  7629. } // END FOR AC_QUANTITY
  7630. }
  7631. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7632. }
  7633. else if(connectorIdInt == 0)
  7634. {
  7635. //check Transaction active
  7636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7637. {
  7638. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7639. {
  7640. 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'))
  7641. {
  7642. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7643. goto end;
  7644. }
  7645. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7646. {
  7647. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7648. goto end;
  7649. }
  7650. 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
  7651. {
  7652. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7653. goto end;
  7654. }
  7655. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7656. {
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7658. goto end;
  7659. }
  7660. }
  7661. }// END FOR CHAdeMO_QUANTITY
  7662. for (int index = 0; index < CCS_QUANTITY; index++)
  7663. {
  7664. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7665. {
  7666. 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'))
  7667. {
  7668. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7669. goto end;
  7670. }
  7671. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7674. goto end;
  7675. }
  7676. 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
  7677. {
  7678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7679. goto end;
  7680. }
  7681. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7682. {
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7684. goto end;
  7685. }
  7686. }
  7687. } // END FOR CCS_QUANTITY
  7688. for (int index = 0; index < GB_QUANTITY; index++)
  7689. {
  7690. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7691. {
  7692. 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'))
  7693. {
  7694. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7695. goto end;
  7696. }
  7697. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7698. {
  7699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7700. goto end;
  7701. }
  7702. 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
  7703. {
  7704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7705. goto end;
  7706. }
  7707. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7708. {
  7709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7710. goto end;
  7711. }
  7712. }
  7713. } // END FOR GB_QUANTITY
  7714. for (int index = 0; index < AC_QUANTITY; index++)
  7715. {
  7716. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7717. {
  7718. 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'))
  7719. {
  7720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7721. goto end;
  7722. }
  7723. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7724. {
  7725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7726. goto end;
  7727. }
  7728. 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
  7729. {
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7731. goto end;
  7732. }
  7733. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7734. {
  7735. 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))
  7736. {
  7737. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7738. goto end;
  7739. }
  7740. }
  7741. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7744. goto end;
  7745. }
  7746. }
  7747. }// END FOR AC_QUANTITY
  7748. //The connectorId is 0
  7749. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7750. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7751. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7752. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7753. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7754. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7755. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7756. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7757. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7758. result = TRUE;
  7759. return result;
  7760. }
  7761. else
  7762. {
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7764. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7765. }
  7766. if(strcmp(comfirmstr,"Accepted") == 0)
  7767. {
  7768. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7770. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7771. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7772. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7773. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7774. result = TRUE;
  7775. return result;
  7776. }
  7777. end:
  7778. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7779. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7780. return result;
  7781. }
  7782. int handleResetRequest(char *uuid, char *payload)
  7783. {
  7784. mtrace();
  7785. int result = FAIL;
  7786. char sstr[10]={0},sstrtemp[30]={ 0 };
  7787. char typestr[10]={0};
  7788. char comfirmstr[20]={0};
  7789. int c = 0;
  7790. char *loc;
  7791. DEBUG_INFO("handleResetRequest...\n");
  7792. strcpy(sstrtemp, stringtrimspace(payload));
  7793. loc = strstr(sstrtemp, "type");
  7794. memset(sstr ,0, sizeof(sstr) );
  7795. c = 0;
  7796. while (loc[3+strlen("type")+c] != '\"')
  7797. {
  7798. sstr[c] = loc[3+strlen("type")+c];
  7799. c++;
  7800. }
  7801. sstr[c] = '\0';
  7802. strcpy(typestr,sstr);
  7803. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7804. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7805. {
  7806. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7807. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7808. result = TRUE;
  7809. return result;
  7810. }
  7811. else
  7812. {
  7813. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7814. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7815. goto errorend;
  7816. }
  7817. errorend:
  7818. sendResetConfirmation(uuid, comfirmstr);
  7819. return result;
  7820. }
  7821. int handleSendLocalListRequest(char *uuid, char *payload)
  7822. {
  7823. mtrace();
  7824. int result = FAIL;
  7825. int listVersionInt;
  7826. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7827. char listsearch[]="listVersion";
  7828. char updateTypesearch[]="updateType";
  7829. char localAuthorizationListsearch[]="localAuthorizationList";
  7830. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7831. char CardList[500][160]={0};
  7832. char updateTypestr[15]={0};
  7833. char idTagstr[20]={0};
  7834. char parentIdTag[20]={0};
  7835. char expiryDate[30]={0};
  7836. char idTagstatus[16]={0};
  7837. int c = 0;
  7838. int i = 0;
  7839. char *delim1 = "}";
  7840. char * pch;
  7841. char *loc;
  7842. //char *ptr;
  7843. char comfirmstr[20];
  7844. //int n_localAuthorizations = 0;
  7845. int checkState_Faulted = FALSE;
  7846. DEBUG_INFO("handleSendLocalListRequest...\n");
  7847. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7848. {
  7849. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7850. goto end;
  7851. }
  7852. //check Charge Point state
  7853. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7854. {
  7855. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7856. {
  7857. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7858. }
  7859. }
  7860. for (int index = 0; index < CCS_QUANTITY; index++)
  7861. {
  7862. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7863. {
  7864. checkState_Faulted = TRUE; //OCPP Status
  7865. }
  7866. }
  7867. for (int index = 0; index < GB_QUANTITY; index++)
  7868. {
  7869. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7870. {
  7871. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7872. }
  7873. }
  7874. //check Charge Point state
  7875. for (int index = 0; index < AC_QUANTITY; index++)
  7876. {
  7877. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7878. {
  7879. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7880. }
  7881. }
  7882. if(checkState_Faulted == TRUE)
  7883. {
  7884. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7885. goto end;
  7886. }
  7887. //Filter payload space
  7888. strcpy(sstrtemp, stringtrimspace(payload));
  7889. //listVersion
  7890. c = 0;
  7891. loc = strstr(sstrtemp, listsearch);
  7892. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7893. {
  7894. sstr[c] = loc[strlen("listVersion")+2+c];
  7895. c++;
  7896. }
  7897. sstr[c] = '\0';
  7898. listVersionInt = atoi(sstr);
  7899. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7900. //updateType
  7901. loc = strstr(sstrtemp, updateTypesearch);
  7902. c = 0;
  7903. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7904. {
  7905. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7906. c++;
  7907. }
  7908. sstr[c] = '\0';
  7909. strcpy(updateTypestr, sstr);
  7910. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7911. //localAuthorizationList
  7912. memset(sstr ,0, sizeof(sstr) );
  7913. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7914. if(loc != NULL) // localAuthorizationList is not NULL
  7915. {
  7916. //Check UpdateType
  7917. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7918. {
  7919. //Local list full update
  7920. printf("Local list full update.\n");
  7921. OCPP_getListVerion();
  7922. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7923. {
  7924. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7925. goto end;
  7926. }
  7927. OCPP_cleanLocalList();
  7928. }
  7929. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7930. {
  7931. //Local list different update
  7932. printf("Local list different update.\n");
  7933. OCPP_getListVerion();
  7934. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7935. {
  7936. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7937. goto end;
  7938. }
  7939. }
  7940. else
  7941. {
  7942. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7943. goto end;
  7944. }
  7945. c = 0;
  7946. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7947. {
  7948. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7949. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7950. c++;
  7951. }
  7952. sstr[c] = '\0';
  7953. //DEBUG_INFO("sstr=%s\n", sstr);
  7954. //parsing strings to words
  7955. i = 0;
  7956. pch = strtok(sstr,delim1);
  7957. while (pch != NULL)
  7958. {
  7959. strcpy(CardList[i], pch);
  7960. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7961. pch = strtok (NULL, delim1);
  7962. i = i + 1;
  7963. }
  7964. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7965. //local Authorizations List Numbers
  7966. //n_localAuthorizations = i;
  7967. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7968. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7969. c= 0;
  7970. while(c < i) // i is CardList Number
  7971. {
  7972. //Search "IdToken"
  7973. memset(sstr ,0, sizeof(sstr) );
  7974. loc = strstr(CardList[c], "idTag");
  7975. int j = 0;
  7976. while (loc[3+strlen("idTag")+j] != '\"')
  7977. {
  7978. sstr[j] = loc[3+strlen("idTag")+j];
  7979. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7980. j++;
  7981. }
  7982. sstr[j] = '\0';
  7983. strcpy(idTagstr, sstr);
  7984. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7985. //Search "expiryDate"
  7986. memset(sstr ,0, sizeof(sstr) );
  7987. loc = strstr(CardList[c], "expiryDate");
  7988. j = 0;
  7989. if(loc != NULL)
  7990. {
  7991. while (loc[3+strlen("expiryDate")+j] != '\"')
  7992. {
  7993. sstr[j] = loc[3+strlen("expiryDate")+j];
  7994. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7995. j++;
  7996. }
  7997. sstr[j] = '\0';
  7998. strcpy(expiryDate, sstr);
  7999. }
  8000. else
  8001. {
  8002. strcpy(expiryDate, "");
  8003. }
  8004. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8005. //Search "parentIdTag"
  8006. memset(sstr ,0, sizeof(sstr) );
  8007. loc = strstr(CardList[c], "parentIdTag");
  8008. j = 0;
  8009. if(loc != NULL)
  8010. {
  8011. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8012. {
  8013. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8014. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8015. j++;
  8016. }
  8017. sstr[j] = '\0';
  8018. strcpy(parentIdTag, sstr);
  8019. }
  8020. else
  8021. {
  8022. strcpy(parentIdTag, "");
  8023. }
  8024. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8025. //Search "status"
  8026. memset(sstr ,0, sizeof(sstr) );
  8027. loc = strstr(CardList[c], "status");
  8028. j = 0;
  8029. while (loc[3+strlen("status")+j] != '\"')
  8030. {
  8031. sstr[j] = loc[3+strlen("status")+j];
  8032. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8033. j++;
  8034. }
  8035. sstr[j] = '\0';
  8036. strcpy(idTagstatus, sstr);
  8037. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8038. OCPP_getIdTag(idTagstr);
  8039. //OCPP_getIdTag("test"); For Test
  8040. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8041. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8042. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8043. {
  8044. //Local list full update
  8045. DEBUG_INFO("Local list full update.\n");
  8046. // update list
  8047. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8048. //DEBUG_INFO("Local list full update. 1\n");
  8049. //OCPP_get_TableAuthlocalAllData();
  8050. //DEBUG_INFO("Local list full update. 2\n");
  8051. }
  8052. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8053. {
  8054. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8055. }
  8056. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8057. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8058. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8059. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8060. c++;
  8061. }
  8062. }
  8063. else
  8064. {
  8065. //Check UpdateType
  8066. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8067. {
  8068. //Local list full update
  8069. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8070. OCPP_cleanLocalList();
  8071. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8072. goto end;
  8073. }
  8074. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8075. {
  8076. //Local list different update
  8077. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8078. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8079. goto end;
  8080. }
  8081. }
  8082. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8083. end:
  8084. sendSendLocalListConfirmation(uuid, comfirmstr);
  8085. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8086. return result;
  8087. }
  8088. #define MAX 200
  8089. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8090. {
  8091. mtrace();
  8092. int result = FAIL;
  8093. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8094. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8095. char chargingProfilePurposeStr[30]={0};
  8096. char chargingProfileKindStr[16]={0};
  8097. char recurrencyKindStr[10]={0};
  8098. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8099. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8100. int chargingSchedulePeriodCount = 0;
  8101. //int updateflag = FALSE;
  8102. char comfirmstr[20]={0};
  8103. int meet= FALSE;
  8104. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8105. int c = 0;
  8106. char *loc;
  8107. FILE *fptr1;//, *fptr2;
  8108. //int lno=0;//, linectr = 0;
  8109. //int modifyflag = FALSE;
  8110. char filename[MAX]={0};
  8111. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8112. //int resultRename=0;
  8113. char rmFileCmd[50]={0};
  8114. char tempchargingProfilePurposeStr[30]={0};
  8115. char word[1600]={0};
  8116. int n_chargingProfile = 0;
  8117. //[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}}}]
  8118. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8119. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8120. //Filter string space
  8121. strcpy(sstrtemp, stringtrimspace(payload));
  8122. //*********************connectorId***************************/
  8123. loc = strstr(sstrtemp, "connectorId");
  8124. c = 0;
  8125. memset(sstr ,0, sizeof(sstr) );
  8126. while (loc[strlen("connectorId")+2+c] != ',')
  8127. {
  8128. sstr[c] = loc[strlen("connectorId")+2+c];
  8129. c++;
  8130. }
  8131. sstr[c] = '\0';
  8132. connectorIdInt = atoi(sstr);
  8133. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8134. {
  8135. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8136. }
  8137. else
  8138. {
  8139. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8140. }
  8141. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8142. //*********************chargingProfileId***************************/
  8143. loc = strstr(sstrtemp, "chargingProfileId");
  8144. c = 0;
  8145. memset(sstr ,0, sizeof(sstr) );
  8146. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8147. {
  8148. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8149. c++;
  8150. }
  8151. sstr[c] = '\0';
  8152. chargingProfileIdInt = atoi(sstr);
  8153. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8154. {
  8155. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8156. }
  8157. else
  8158. {
  8159. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8160. }
  8161. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8162. //*********************transactionId***************************/
  8163. loc = strstr(sstrtemp, "transactionId");
  8164. if(loc != NULL)
  8165. {
  8166. c = 0;
  8167. memset(sstr ,0, sizeof(sstr) );
  8168. while (loc[strlen("transactionId")+2+c] != ',')
  8169. {
  8170. sstr[c] = loc[strlen("transactionId")+2+c];
  8171. c++;
  8172. }
  8173. sstr[c] = '\0';
  8174. transactionIdInt = atoi(sstr);
  8175. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8176. {
  8177. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8178. }
  8179. else
  8180. {
  8181. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8182. }
  8183. }
  8184. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8185. //*********************stackLevel***************************/
  8186. loc = strstr(sstrtemp, "stackLevel");
  8187. c = 0;
  8188. memset(sstr ,0, sizeof(sstr) );
  8189. while (loc[strlen("stackLevel")+2+c] != ',')
  8190. {
  8191. sstr[c] = loc[strlen("stackLevel")+2+c];
  8192. c++;
  8193. }
  8194. sstr[c] = '\0';
  8195. stackLevelInt = atoi(sstr);
  8196. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8197. {
  8198. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8199. }
  8200. else
  8201. {
  8202. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8203. }
  8204. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8205. //*********************chargingProfilePurpose***************************/
  8206. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8207. c = 0;
  8208. memset(sstr ,0, sizeof(sstr) );
  8209. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8210. {
  8211. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8212. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8213. c++;
  8214. }
  8215. sstr[c] = '\0';
  8216. strcpy(chargingProfilePurposeStr,sstr);
  8217. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8218. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8219. {
  8220. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8221. }
  8222. else
  8223. {
  8224. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8225. }
  8226. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8227. //*********************chargingProfileKind***************************/
  8228. loc = strstr(sstrtemp, "chargingProfileKind");
  8229. c = 0;
  8230. memset(sstr ,0, sizeof(sstr) );
  8231. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8232. {
  8233. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8234. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8235. c++;
  8236. }
  8237. sstr[c] = '\0';
  8238. strcpy(chargingProfileKindStr,sstr);
  8239. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8240. {
  8241. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8242. }
  8243. else
  8244. {
  8245. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8246. }
  8247. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8248. //*********************recurrencyKind***************************/
  8249. loc = strstr(sstrtemp, "recurrencyKind");
  8250. if(loc != NULL)
  8251. {
  8252. c = 0;
  8253. memset(sstr ,0, sizeof(sstr) );
  8254. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8255. {
  8256. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8257. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8258. c++;
  8259. }
  8260. sstr[c] = '\0';
  8261. strcpy(recurrencyKindStr,sstr);
  8262. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8263. {
  8264. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8265. }
  8266. else
  8267. {
  8268. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8269. }
  8270. }
  8271. else
  8272. {
  8273. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8274. {
  8275. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8276. }
  8277. else
  8278. {
  8279. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8280. }
  8281. }
  8282. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8283. //*********************validFrom***************************/
  8284. loc = strstr(sstrtemp, "validFrom");
  8285. if(loc != NULL)
  8286. {
  8287. c = 0;
  8288. memset(sstr ,0, sizeof(sstr) );
  8289. while (loc[3+strlen("validFrom")+c] != '\"')
  8290. {
  8291. sstr[c] = loc[3+strlen("validFrom")+c];
  8292. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8293. c++;
  8294. }
  8295. sstr[c] = '\0';
  8296. strcpy(validFromStr,sstr);
  8297. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8298. {
  8299. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8300. }
  8301. else
  8302. {
  8303. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8304. }
  8305. }
  8306. else
  8307. {
  8308. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8309. {
  8310. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8311. }
  8312. else
  8313. {
  8314. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8315. }
  8316. }
  8317. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8318. //*********************validTo***************************/
  8319. loc = strstr(sstrtemp, "validTo");
  8320. if(loc != NULL)
  8321. {
  8322. c = 0;
  8323. memset(sstr ,0, sizeof(sstr) );
  8324. while (loc[3+strlen("validTo")+c] != '\"')
  8325. {
  8326. sstr[c] = loc[3+strlen("validTo")+c];
  8327. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8328. c++;
  8329. }
  8330. sstr[c] = '\0';
  8331. strcpy(validToStr,sstr);
  8332. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8333. {
  8334. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8335. }
  8336. else
  8337. {
  8338. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8339. }
  8340. }
  8341. else
  8342. {
  8343. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8344. {
  8345. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8346. }
  8347. else
  8348. {
  8349. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8350. }
  8351. }
  8352. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8353. //*********************duration***************************/
  8354. loc = strstr(sstrtemp, "duration");
  8355. if(loc != NULL)
  8356. {
  8357. c = 0;
  8358. memset(sstr ,0, sizeof(sstr) );
  8359. while (loc[strlen("duration")+2+c] != ',')
  8360. {
  8361. sstr[c] = loc[strlen("duration")+2+c];
  8362. c++;
  8363. }
  8364. sstr[c] = '\0';
  8365. durationInt = atoi(sstr);
  8366. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8367. {
  8368. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8369. }
  8370. else
  8371. {
  8372. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8373. }
  8374. }
  8375. else
  8376. {
  8377. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8378. {
  8379. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8380. }
  8381. else
  8382. {
  8383. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8384. }
  8385. }
  8386. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8387. //*********************startSchedule***************************/
  8388. loc = strstr(sstrtemp, "startSchedule");
  8389. if(loc != NULL)
  8390. {
  8391. c = 0;
  8392. memset(sstr ,0, sizeof(sstr) );
  8393. while (loc[3+strlen("startSchedule")+c] != '\"')
  8394. {
  8395. sstr[c] = loc[3+strlen("startSchedule")+c];
  8396. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8397. c++;
  8398. }
  8399. sstr[c] = '\0';
  8400. strcpy(startScheduleStr,sstr);
  8401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8402. {
  8403. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8404. }
  8405. else
  8406. {
  8407. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8408. }
  8409. }
  8410. else
  8411. {
  8412. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8413. {
  8414. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8415. }
  8416. else
  8417. {
  8418. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8419. }
  8420. }
  8421. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8422. //*********************chargingRateUnit***************************/
  8423. loc = strstr(sstrtemp, "chargingRateUnit");
  8424. if(loc != NULL)
  8425. {
  8426. c = 0;
  8427. memset(sstr ,0, sizeof(sstr) );
  8428. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8429. {
  8430. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8431. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8432. c++;
  8433. }
  8434. sstr[c] = '\0';
  8435. strcpy(chargingRateUnitStr,sstr);
  8436. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8437. {
  8438. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8439. }
  8440. else
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8443. }
  8444. }
  8445. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8446. //****************chargingSchedulePeriod count start*******************/
  8447. int what_len = strlen("startPeriod");
  8448. char tempChargingProfile[1600]={0};
  8449. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8450. char *where = tempChargingProfile;
  8451. if (what_len)
  8452. {
  8453. while ((where = strstr(where, "startPeriod"))) {
  8454. where += what_len;
  8455. chargingSchedulePeriodCount++;
  8456. }
  8457. }
  8458. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8459. {
  8460. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8461. goto end;
  8462. }
  8463. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8464. //where = payload;
  8465. int templength = 0;
  8466. //int searchstart = 0;
  8467. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8468. {
  8469. //****************startPeriod*******************/
  8470. c=0;
  8471. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8472. memset(sstr ,0, sizeof(sstr) );
  8473. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8474. {
  8475. sstr[c] = loc[strlen("startPeriod")+2+c];
  8476. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8477. c++;
  8478. }
  8479. sstr[c] = '\0';
  8480. startPeriodInt[periodNums] = atoi(sstr);
  8481. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8482. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8484. {
  8485. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8486. }
  8487. else
  8488. {
  8489. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8490. }
  8491. templength = strlen("startPeriod")+2+c;
  8492. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8493. //****************limit*******************/
  8494. c=0;
  8495. loc = strstr(tempChargingProfile + templength, "limit");
  8496. memset(sstr ,0, sizeof(sstr) );
  8497. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8498. {
  8499. sstr[c] = loc[strlen("limit")+2+c];
  8500. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8501. c++;
  8502. }
  8503. sstr[c] = '\0';
  8504. limitflaot[periodNums] = atof(sstr);
  8505. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8506. {
  8507. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8508. }
  8509. else
  8510. {
  8511. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8512. }
  8513. templength = templength + strlen("limit")+2+c;
  8514. //****************numberPhases*******************/
  8515. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8516. if(loc != NULL)
  8517. {
  8518. c=0;
  8519. memset(sstr ,0, sizeof(sstr) );
  8520. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8521. {
  8522. sstr[c] = loc[strlen("numberPhases")+2+c];
  8523. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8524. c++;
  8525. }
  8526. sstr[c] = '\0';
  8527. numberPhasesInt[periodNums] = atoi(sstr);
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8531. }
  8532. else
  8533. {
  8534. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8535. }
  8536. templength = templength + strlen("numberPhases")+2+c;
  8537. }
  8538. //where = loc;
  8539. }
  8540. //****************chargingSchedulePeriod count end*******************/
  8541. //*********************minChargingRate***************************/
  8542. loc = strstr(sstrtemp, "minChargingRate");
  8543. if(loc != NULL)
  8544. {
  8545. c = 0;
  8546. memset(sstr ,0, sizeof(sstr) );
  8547. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8548. {
  8549. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8550. c++;
  8551. }
  8552. sstr[c] = '\0';
  8553. minChargingRateFloat = atof(sstr);
  8554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8555. {
  8556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8557. }
  8558. else
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8561. }
  8562. }
  8563. else
  8564. {
  8565. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8566. {
  8567. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8568. }
  8569. else
  8570. {
  8571. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8572. }
  8573. }
  8574. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8575. {
  8576. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8577. if(connectorIdInt != 0)
  8578. {
  8579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8580. goto end;
  8581. }
  8582. strcpy(filename, ChargePointMaxProfile_JSON );
  8583. fptr1 = fopen(filename, "r");
  8584. if (!fptr1)
  8585. {
  8586. //file not exist
  8587. DEBUG_INFO("Unable to open the input file!!\n");
  8588. fptr1 = fopen(filename, "w+");
  8589. }
  8590. else
  8591. {
  8592. //Check Charging Profile Count
  8593. while(fscanf(fptr1, "%s", word) != EOF)
  8594. {
  8595. //DEBUG_INFO("word=%s\n",word);
  8596. if(strstr(word, "chargingProfileId")!= NULL)
  8597. {
  8598. //DEBUG_INFO("test chargingProfileId \n");
  8599. n_chargingProfile = n_chargingProfile + 1;
  8600. //DEBUG_INFO("chargingProfileId Found\n");
  8601. }
  8602. }
  8603. }
  8604. fclose(fptr1);
  8605. }
  8606. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8607. {
  8608. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8609. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8610. {
  8611. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8612. goto end;
  8613. }
  8614. memset(filename, 0, sizeof filename);
  8615. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8616. fptr1 = fopen(filename, "r");
  8617. if (!fptr1)
  8618. {
  8619. //file not exist
  8620. //DEBUG_INFO("Unable to open the input file!!\n");
  8621. fptr1 = fopen(filename, "w+");
  8622. }
  8623. else
  8624. {
  8625. //Check Charging Profile Count
  8626. while(fscanf(fptr1, "%s", word) != EOF)
  8627. {
  8628. //DEBUG_INFO("word=%s\n",word);
  8629. if(strstr(word, "chargingProfileId")!= NULL)
  8630. {
  8631. //DEBUG_INFO("test chargingProfileId \n");
  8632. n_chargingProfile = n_chargingProfile + 1;
  8633. //DEBUG_INFO("chargingProfileId Found\n");
  8634. }
  8635. }
  8636. }
  8637. fclose(fptr1);
  8638. }
  8639. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8640. {
  8641. //printf("set chargingProfile 1-4\n");
  8642. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8643. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8644. if(connectorIdInt == 0)
  8645. {
  8646. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8647. goto end;
  8648. }
  8649. int tempIndex = 0;
  8650. //check Transaction active
  8651. if(gunType[connectorIdInt -1] == 'J')
  8652. {
  8653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8654. {
  8655. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8656. }
  8657. else
  8658. {
  8659. tempIndex = connectorIdInt -1;
  8660. }
  8661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8662. {
  8663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8664. {
  8665. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8666. {
  8667. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8668. {
  8669. meet = TRUE;
  8670. break;
  8671. }
  8672. }
  8673. }
  8674. }
  8675. }
  8676. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8677. {
  8678. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8679. {
  8680. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8681. }
  8682. else
  8683. {
  8684. tempIndex = connectorIdInt -1;
  8685. }
  8686. for (int index = 0; index < CCS_QUANTITY; index++)
  8687. {
  8688. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8689. {
  8690. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8691. {
  8692. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8693. {
  8694. meet = TRUE;
  8695. break;
  8696. }
  8697. }
  8698. }
  8699. }
  8700. }
  8701. else if(gunType[connectorIdInt -1] == 'G')
  8702. {
  8703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8704. {
  8705. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8706. }
  8707. else
  8708. {
  8709. tempIndex = connectorIdInt -1;
  8710. }
  8711. for (int index = 0; index < GB_QUANTITY; index++)
  8712. {
  8713. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8714. {
  8715. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8716. {
  8717. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8718. {
  8719. meet = TRUE;
  8720. break;
  8721. }
  8722. }
  8723. }
  8724. }
  8725. }
  8726. else
  8727. {
  8728. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8729. {
  8730. tempIndex = 2;
  8731. }
  8732. else
  8733. {
  8734. tempIndex = (connectorIdInt -1);
  8735. }
  8736. for (int index = 0; index < AC_QUANTITY; index++)
  8737. {
  8738. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8739. {
  8740. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8741. {
  8742. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8743. {
  8744. meet = TRUE;
  8745. break;
  8746. }
  8747. }
  8748. }
  8749. }
  8750. }
  8751. //check Transaction active
  8752. if(meet == FALSE)
  8753. {
  8754. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8755. goto end;
  8756. }
  8757. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8758. {
  8759. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8760. goto end;
  8761. }
  8762. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8763. fptr1 = fopen(filename, "r");
  8764. if (!fptr1)
  8765. {
  8766. //file not exist
  8767. DEBUG_INFO("Unable to open the input file!!\n");
  8768. fptr1 = fopen(filename, "w+");
  8769. }
  8770. else
  8771. {
  8772. //Check Charging Profile Count
  8773. while(fscanf(fptr1, "%s", word) != EOF)
  8774. {
  8775. //DEBUG_INFO("word=%s\n",word);
  8776. if(strstr(word, "chargingProfileId")!= NULL)
  8777. {
  8778. //DEBUG_INFO("test chargingProfileId \n");
  8779. n_chargingProfile = n_chargingProfile + 1;
  8780. //DEBUG_INFO("chargingProfileId Found\n");
  8781. }
  8782. }
  8783. }
  8784. fclose(fptr1);
  8785. }
  8786. // Check ChargeProfileMaxStackLevel
  8787. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8788. {
  8789. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8790. goto end;
  8791. }
  8792. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8793. {
  8794. int i = 0;
  8795. char fnametemp[200]={0};
  8796. n_chargingProfile = 0;
  8797. //Check ChargePointMaxProfile.json exit
  8798. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8799. {
  8800. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8801. //Check Charging Profile Count
  8802. while(fscanf(fptr1, "%s", word) != EOF)
  8803. {
  8804. //DEBUG_INFO("word=%s\n",word);
  8805. if(strstr(word, "chargingProfileId")!= NULL)
  8806. {
  8807. //DEBUG_INFO("test chargingProfileId \n");
  8808. n_chargingProfile = n_chargingProfile + 1;
  8809. i = i + 1;
  8810. //DEBUG_INFO("chargingProfileId Found\n");
  8811. }
  8812. memset(word, 0, sizeof word);
  8813. }
  8814. fclose(fptr1);
  8815. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8816. }
  8817. //Check TxDefaultProfile_0.json exit
  8818. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8819. {
  8820. i = 0;
  8821. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8822. //Check Charging Profile Count
  8823. while(fscanf(fptr1, "%s", word) != EOF)
  8824. {
  8825. //DEBUG_INFO("word=%s\n",word);
  8826. if(strstr(word, "chargingProfileId")!= NULL)
  8827. {
  8828. //DEBUG_INFO("test chargingProfileId \n");
  8829. n_chargingProfile = n_chargingProfile + 1;
  8830. i = i + 1;
  8831. //DEBUG_INFO("chargingProfileId Found\n");
  8832. }
  8833. memset(word, 0, sizeof word);
  8834. }
  8835. fclose(fptr1);
  8836. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8837. }
  8838. //Check TxDefaultProfile_%d.json
  8839. for(int j=1; j <= gunTotalNumber; j++)
  8840. {
  8841. memset(fnametemp, 0, sizeof fnametemp);
  8842. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8843. if((access(fnametemp,F_OK))!=-1)
  8844. {
  8845. i = 0;
  8846. fptr1 = fopen(fnametemp, "r");
  8847. //Check Charging Profile Count
  8848. while(fscanf(fptr1, "%s", word) != EOF)
  8849. {
  8850. //DEBUG_INFO("word=%s\n",word);
  8851. if(strstr(word, "chargingProfileId")!= NULL)
  8852. {
  8853. //DEBUG_INFO("test chargingProfileId \n");
  8854. n_chargingProfile = n_chargingProfile + 1;
  8855. i = i + 1;
  8856. //DEBUG_INFO("chargingProfileId Found\n");
  8857. }
  8858. memset(word, 0, sizeof word);
  8859. }
  8860. fclose(fptr1);
  8861. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8862. }
  8863. }
  8864. //Check TxProfile_%d.json
  8865. for(int j=1; j <= gunTotalNumber; j++)
  8866. {
  8867. memset(fnametemp, 0, sizeof fnametemp);
  8868. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8869. if((access(fnametemp,F_OK))!=-1)
  8870. {
  8871. i = 0;
  8872. fptr1 = fopen(fnametemp, "r");
  8873. //Check Charging Profile Count
  8874. while(fscanf(fptr1, "%s", word) != EOF)
  8875. {
  8876. //DEBUG_INFO("word=%s\n",word);
  8877. if(strstr(word, "chargingProfileId")!= NULL)
  8878. {
  8879. //DEBUG_INFO("test chargingProfileId \n");
  8880. n_chargingProfile = n_chargingProfile + 1;
  8881. i = i + 1;
  8882. //DEBUG_INFO("chargingProfileId Found\n");
  8883. }
  8884. memset(word, 0, sizeof word);
  8885. }
  8886. fclose(fptr1);
  8887. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8888. }
  8889. }
  8890. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8891. {
  8892. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8893. goto end;
  8894. }
  8895. }
  8896. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8897. //**********************************Write to File********************************************************/
  8898. FILE *infile;
  8899. FILE *outfile;
  8900. // open file for writing
  8901. infile = fopen (filename, "r");
  8902. outfile = fopen (tempfile, "w");
  8903. int d =0;
  8904. d = fgetc(infile);
  8905. //DEBUG_INFO("d:%d\n",d);
  8906. rewind(infile);
  8907. //*璉 瘚 辣蝏     1嚗   0 */
  8908. if(d == EOF)
  8909. {
  8910. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8911. fprintf(outfile,"%s\n",payload);
  8912. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8913. fclose(infile);
  8914. fclose(outfile);
  8915. sprintf(rmFileCmd,"rm -f %s",filename);
  8916. system(rmFileCmd);
  8917. rename(tempfile, filename);
  8918. sleep(1);
  8919. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8920. //system(rmFileCmd);
  8921. }
  8922. else
  8923. {
  8924. char buf[1000]={0};
  8925. int ChargingProfileAdded = FALSE;
  8926. while (fgets(buf, sizeof(buf), infile) != NULL)
  8927. {
  8928. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8929. //*************************tempconnectorIdInt*********************************/
  8930. loc = strstr(buf, "connectorId");
  8931. c = 0;
  8932. memset(sstr ,0, sizeof(sstr) );
  8933. while (loc[strlen("connectorId")+2+c] != ',')
  8934. {
  8935. sstr[c] = loc[strlen("connectorId")+2+c];
  8936. c++;
  8937. }
  8938. sstr[c] = '\0';
  8939. tempconnectorIdInt = atoi(sstr);
  8940. //*************************tempchargingProfileIdInt*********************************/
  8941. loc = strstr(buf, "chargingProfileId");
  8942. c = 0;
  8943. memset(sstr ,0, sizeof(sstr) );
  8944. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8945. {
  8946. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8947. c++;
  8948. }
  8949. sstr[c] = '\0';
  8950. tempchargingProfileIdInt = atoi(sstr);
  8951. //*************************tempstackLevelInt*********************************/
  8952. loc = strstr(buf, "stackLevel");
  8953. c = 0;
  8954. memset(sstr ,0, sizeof(sstr) );
  8955. while (loc[strlen("stackLevel")+2+c] != ',')
  8956. {
  8957. sstr[c] = loc[strlen("stackLevel")+2+c];
  8958. c++;
  8959. }
  8960. sstr[c] = '\0';
  8961. tempstackLevelInt = atoi(sstr);
  8962. //*************************tempchargingProfilePurposeStr*********************************/
  8963. loc = strstr(payload, "chargingProfilePurpose");
  8964. c = 0;
  8965. memset(sstr ,0, sizeof(sstr) );
  8966. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8967. {
  8968. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8969. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8970. c++;
  8971. }
  8972. sstr[c] = '\0';
  8973. strcpy(tempchargingProfilePurposeStr,sstr);
  8974. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8975. {
  8976. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8977. {
  8978. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8979. if(ChargingProfileAdded == FALSE)
  8980. {
  8981. fprintf(outfile,"%s\n",payload);
  8982. ChargingProfileAdded = TRUE;
  8983. }
  8984. }
  8985. else
  8986. {
  8987. if(tempstackLevelInt < stackLevelInt)
  8988. {
  8989. if(ChargingProfileAdded == FALSE)
  8990. {
  8991. fprintf(outfile,"%s\n",payload);
  8992. ChargingProfileAdded = TRUE;
  8993. fprintf(outfile,"%s\n",buf);
  8994. }
  8995. else
  8996. {
  8997. fprintf(outfile,"%s\n",buf);
  8998. }
  8999. }
  9000. else
  9001. {
  9002. if(ChargingProfileAdded == FALSE)
  9003. {
  9004. fprintf(outfile,"%s\n",buf);
  9005. fprintf(outfile,"%s\n",payload);
  9006. ChargingProfileAdded = TRUE;
  9007. }
  9008. else
  9009. {
  9010. fprintf(outfile,"%s\n",buf);
  9011. }
  9012. }
  9013. }
  9014. }
  9015. else
  9016. {
  9017. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9018. {
  9019. if(ChargingProfileAdded == FALSE)
  9020. {
  9021. fprintf(outfile,"%s\n",payload);
  9022. ChargingProfileAdded = TRUE;
  9023. fprintf(outfile,"%s\n",buf);
  9024. }
  9025. else
  9026. {
  9027. fprintf(outfile,"%s\n",buf);
  9028. }
  9029. }
  9030. else if(tempstackLevelInt < stackLevelInt)
  9031. {
  9032. if(ChargingProfileAdded == FALSE)
  9033. {
  9034. fprintf(outfile,"%s\n",payload);
  9035. ChargingProfileAdded = TRUE;
  9036. fprintf(outfile,"%s\n",buf);
  9037. }
  9038. else
  9039. {
  9040. fprintf(outfile,"%s\n",buf);
  9041. }
  9042. }
  9043. else
  9044. {
  9045. if(ChargingProfileAdded == FALSE)
  9046. {
  9047. fprintf(outfile,"%s\n",buf);
  9048. fprintf(outfile,"%s\n",payload);
  9049. ChargingProfileAdded = TRUE;
  9050. }
  9051. else
  9052. {
  9053. fprintf(outfile,"%s\n",buf);
  9054. }
  9055. }
  9056. }
  9057. } // end of while loop
  9058. fclose(infile);
  9059. fclose(outfile);
  9060. sprintf(rmFileCmd,"rm -f %s",filename);
  9061. system(rmFileCmd);
  9062. rename(tempfile, filename);
  9063. sleep(1);
  9064. result = TRUE;
  9065. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9066. }
  9067. end:
  9068. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9069. return result;
  9070. return result;
  9071. }
  9072. int handleTriggerMessageRequest(char *uuid, char *payload)
  9073. {
  9074. mtrace();
  9075. int result = FAIL;
  9076. int connectorIdIsNULL = FALSE;
  9077. int connectorIdInt =0;
  9078. char sstr[40]={0},sstrtemp[100]={ 0 };
  9079. char requestedMessagestr[40]={0};
  9080. char comfirmstr[20]={0};
  9081. int c = 0;
  9082. char *loc;
  9083. DEBUG_INFO("handleTriggerMessageRequest\n");
  9084. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9085. strcpy(sstrtemp, stringtrimspace(payload));
  9086. c = 0;
  9087. loc = strstr(sstrtemp, "requestedMessage");
  9088. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9089. {
  9090. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9091. c++;
  9092. }
  9093. sstr[c] = '\0';
  9094. strcpy(requestedMessagestr, sstr);
  9095. c = 0;
  9096. loc = strstr(sstrtemp, "connectorId");
  9097. if(loc == NULL)
  9098. {
  9099. connectorIdIsNULL = TRUE;
  9100. }
  9101. else
  9102. {
  9103. memset(sstr ,0, sizeof(sstr) );
  9104. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9105. {
  9106. sstr[c] = loc[strlen("connectorId")+2+c];
  9107. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9108. c++;
  9109. }
  9110. sstr[c] = '\0';
  9111. connectorIdInt = atoi(sstr);
  9112. }
  9113. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9114. {
  9115. //connectorIdInt = json_object_get_int(connectorId);
  9116. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9117. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9118. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9119. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9120. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9121. }
  9122. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9123. {
  9124. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9125. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9126. return TRUE;
  9127. }
  9128. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9129. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9130. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9131. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9132. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9133. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9134. {
  9135. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9136. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9137. return TRUE;
  9138. }
  9139. else
  9140. {
  9141. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9142. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9143. }
  9144. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9145. {
  9146. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9147. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9148. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9149. {
  9150. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9151. }
  9152. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9153. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9154. }
  9155. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9156. {
  9157. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9158. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9159. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9160. }
  9161. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9162. {
  9163. sendBootNotificationRequest();
  9164. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9165. }
  9166. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9167. {
  9168. sendHeartbeatRequest(connectorIdInt);
  9169. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9170. }
  9171. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9172. {
  9173. if(connectorIdIsNULL == FALSE)
  9174. {
  9175. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9176. {
  9177. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9178. sendMeterValuesRequest(connectorIdInt -1);
  9179. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9180. }
  9181. }
  9182. else
  9183. {
  9184. for(int idx=0;idx< gunTotalNumber;idx++)
  9185. {
  9186. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9187. sendMeterValuesRequest(idx);
  9188. }
  9189. }
  9190. }
  9191. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9192. {
  9193. if(connectorIdIsNULL == FALSE)
  9194. {
  9195. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9196. {
  9197. sendStatusNotificationRequest(connectorIdInt -1);
  9198. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9199. }
  9200. }
  9201. else
  9202. {
  9203. for(int idx=0;idx< gunTotalNumber;idx++)
  9204. sendStatusNotificationRequest(idx);
  9205. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9206. }
  9207. }
  9208. return result;
  9209. }
  9210. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9211. {
  9212. mtrace();
  9213. int result = FAIL;
  9214. char sstr[6]={0},sstrtemp[50]={ 0 };
  9215. int connectorIdInt =0;
  9216. char comfirmstr[20]={0};
  9217. int c = 0;
  9218. int tempIndex = 0;
  9219. char *loc;
  9220. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9221. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9222. strcpy(sstrtemp, stringtrimspace(payload));
  9223. c = 0;
  9224. loc = strstr(sstrtemp, "connectorId");
  9225. memset(sstr ,0, sizeof(sstr) );
  9226. while (loc[strlen("connectorId")+2+c] != '}')
  9227. {
  9228. sstr[c] = loc[strlen("connectorId")+2+c];
  9229. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9230. c++;
  9231. }
  9232. sstr[c] = '\0';
  9233. connectorIdInt = atoi(sstr);
  9234. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9235. if(gunTotalNumber == 0)
  9236. {
  9237. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9238. goto end;
  9239. }
  9240. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9241. {
  9242. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9243. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9244. goto end;
  9245. }
  9246. else
  9247. {
  9248. //check Transaction active
  9249. if(gunType[connectorIdInt-1] == 'J')
  9250. {
  9251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9252. {
  9253. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9254. }
  9255. else
  9256. {
  9257. tempIndex = connectorIdInt -1;
  9258. }
  9259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9260. {
  9261. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9262. {
  9263. //stop Transaction
  9264. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9265. }
  9266. }
  9267. }
  9268. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9269. {
  9270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9271. {
  9272. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9273. }
  9274. else
  9275. {
  9276. tempIndex = connectorIdInt -1;
  9277. }
  9278. for (int index = 0; index < CCS_QUANTITY; index++)
  9279. {
  9280. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9281. {
  9282. //stop Transaction
  9283. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9284. }
  9285. }
  9286. }
  9287. else if(gunType[connectorIdInt-1] == 'G')
  9288. {
  9289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9290. {
  9291. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9292. }
  9293. else
  9294. {
  9295. tempIndex = connectorIdInt -1;
  9296. }
  9297. for (int index = 0; index < GB_QUANTITY; index++)
  9298. {
  9299. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9300. {
  9301. //stop Transaction
  9302. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9303. }
  9304. }
  9305. }
  9306. else
  9307. {
  9308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9309. {
  9310. tempIndex = 2;
  9311. }
  9312. else
  9313. {
  9314. tempIndex = connectorIdInt-1;
  9315. }
  9316. for (int index = 0; index < AC_QUANTITY; index++)
  9317. {
  9318. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9319. {
  9320. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9321. }
  9322. }
  9323. }
  9324. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9325. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9326. result = TRUE;
  9327. return result;
  9328. }
  9329. end:
  9330. //json_object_put(obj); --- remove temporally
  9331. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9332. return result;
  9333. }
  9334. static char UpdateFirmwarepayloadData[300]={0};
  9335. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9336. {
  9337. mtrace();
  9338. int result = FAIL;
  9339. pthread_t t;
  9340. sendUpdateFirmwareConfirmation(uuid);
  9341. memset(UpdateFirmwarepayloadData, 0, 300);
  9342. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9343. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9344. ////pthread_join(t, NULL); //
  9345. //pthread_detach(t);
  9346. //sendUpdateFirmwareConfirmation(uuid);
  9347. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9348. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9349. return result;
  9350. }
  9351. void *UpdateFirmwareProcess(void *data)
  9352. {
  9353. pthread_detach(pthread_self());
  9354. mtrace();
  9355. int retriesInt =0, retryIntervalInt=0;
  9356. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9357. int port=0;
  9358. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9359. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9360. //char comfirmstr[20];
  9361. int isSuccess = 0;
  9362. char ftpbuf[200];
  9363. char temp[100];
  9364. char * pch;
  9365. int retriesISNULL=FALSE;
  9366. int retryInterval=FALSE;
  9367. int c = 0;
  9368. //int i = 0;
  9369. char *loc;
  9370. char sstr[300]={ 0 };
  9371. char str[300]={ 0 };
  9372. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9373. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9374. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9375. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9376. //***************location **************/
  9377. loc = strstr(str, "location");
  9378. memset(sstr ,0, sizeof(sstr) );
  9379. c = 0;
  9380. while (loc[3+strlen("location")+c] != '\"')
  9381. {
  9382. sstr[c] = loc[3+strlen("location")+c];
  9383. c++;
  9384. }
  9385. sstr[c] = '\0';
  9386. strcpy(locationstr, sstr);
  9387. //***************retries**************/
  9388. c = 0;
  9389. loc = strstr(str, "retries");
  9390. if(loc == NULL)
  9391. {
  9392. retriesISNULL=TRUE;
  9393. }
  9394. else
  9395. {
  9396. memset(sstr ,0, sizeof(sstr) );
  9397. while (loc[strlen("retries")+2+c] != ',')
  9398. {
  9399. sstr[c] = loc[strlen("retries")+2+c];
  9400. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9401. c++;
  9402. }
  9403. sstr[c] = '\0';
  9404. }
  9405. if(retriesISNULL == FALSE)
  9406. {
  9407. retriesInt = atoi(sstr);
  9408. }
  9409. //***************retrieveDate **************/
  9410. loc = strstr(str, "retrieveDate");
  9411. memset(sstr ,0, sizeof(sstr) );
  9412. c = 0;
  9413. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9414. {
  9415. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9416. c++;
  9417. }
  9418. sstr[c] = '\0';
  9419. strcpy(retrieveDatestr, sstr);
  9420. //***************retryInterval **************/
  9421. c = 0;
  9422. loc = strstr(str, "retryInterval");
  9423. memset(sstr ,0, sizeof(sstr) );
  9424. if(loc == NULL)
  9425. {
  9426. retryInterval=TRUE;
  9427. }
  9428. else
  9429. {
  9430. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9431. {
  9432. sstr[c] = loc[strlen("retryInterval")+2+c];
  9433. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9434. c++;
  9435. }
  9436. sstr[c] = '\0';
  9437. }
  9438. if(retryInterval==FALSE)
  9439. {
  9440. retryIntervalInt = atoi(sstr);
  9441. }
  9442. memset(ftppath, 0, sizeof(ftppath));
  9443. memset(path, 0, sizeof(path));
  9444. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9445. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9446. if(strncmp(locationstr,"http", 4) == 0)
  9447. {
  9448. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9449. protocol, host, path);
  9450. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9451. // protocol, user, password, host, path);
  9452. sprintf(ftppath,"/%s", path);
  9453. //DEBUG_INFO("protocol =%s\n",protocol);
  9454. //DEBUG_INFO("host =%s\n",host);
  9455. //DEBUG_INFO("path =%s\n",path);
  9456. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9457. int ftppathlen=strlen(ftppath);
  9458. int i=1;
  9459. char filenametemp[50];
  9460. while(i < ftppathlen)
  9461. {
  9462. int len=ftppathlen-i;
  9463. if(ftppath[len]== 47) // '/' ascll code: 47
  9464. {
  9465. DEBUG_INFO("compare '/' all right\n");
  9466. break;
  9467. }
  9468. i=i+1;
  9469. }
  9470. memset(filenametemp, 0, sizeof(filenametemp));
  9471. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9472. filenametemp[i+1] = 0;
  9473. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9474. do{
  9475. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9476. sleep(retryIntervalInt);
  9477. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9478. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9479. if(!isSuccess)
  9480. {
  9481. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9482. }
  9483. else
  9484. {
  9485. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9486. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9487. //isUpdateRequest = TRUE;
  9488. }
  9489. }
  9490. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9491. {
  9492. memset(ftpbuf, 0, sizeof(ftpbuf));
  9493. memset(temp, 0, sizeof(temp));
  9494. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9495. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9496. int ftppathlen=strlen(ftpbuf);
  9497. int i=1;
  9498. char filenametemp[50];
  9499. while(i < ftppathlen)
  9500. {
  9501. int len=ftppathlen-i;
  9502. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9503. {
  9504. DEBUG_INFO(" compare '/' all right\n");
  9505. break;
  9506. }
  9507. i=i+1;
  9508. }
  9509. memset(filenametemp, 0, sizeof(filenametemp));
  9510. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9511. filenametemp[i+1] = 0;
  9512. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9513. pch=strchr(temp,'@');
  9514. if(pch==NULL)
  9515. {
  9516. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9517. protocol, host, &port, path);
  9518. strcpy(user,"anonymous");
  9519. strcpy(password,"");
  9520. }
  9521. else
  9522. {
  9523. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9524. protocol, user, password, host, &port, path);
  9525. }
  9526. sscanf(host,"%[^/]%s",host1, path1);
  9527. sprintf(ftppath,"%s", path1);
  9528. //DEBUG_INFO("protocol =%s\n",protocol);
  9529. //DEBUG_INFO("user =%s\n",user);
  9530. //DEBUG_INFO("password =%s\n",password);
  9531. //DEBUG_INFO("host1 =%s\n",host1);
  9532. //DEBUG_INFO("port =%d\n",port);
  9533. //DEBUG_INFO("path1 =%s\n",path1);
  9534. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9535. //ftpFile(host, user, password, port, ftppath, fname);
  9536. //download firmware pthred
  9537. if(port == 0)
  9538. {
  9539. port = 21;
  9540. }
  9541. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9542. do{
  9543. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9544. sleep(retryIntervalInt);
  9545. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9546. if(!isSuccess)
  9547. {
  9548. //BulldogUtil.sleepMs(interval*1000);
  9549. DEBUG_INFO("Update firmware request and download file fail.\n");
  9550. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9551. }
  9552. else
  9553. {
  9554. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9555. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9556. //isUpdateRequest = TRUE;
  9557. }
  9558. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9559. }
  9560. else
  9561. {
  9562. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9563. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9564. }
  9565. pthread_exit(NULL);
  9566. }
  9567. //==========================================
  9568. // Handle server response routine
  9569. //==========================================
  9570. void handleAuthorizeResponse(char *payload, int gun_index)
  9571. {
  9572. mtrace();
  9573. char expiryDatestr[30]={0};
  9574. char parentIdTagstr[20]={0};
  9575. char statusstr[20]={0};
  9576. char expiryDatestrtemp[30]={0};
  9577. char parentIdTagstrtemp[20]={0};
  9578. char IdTagstrtemp[20]={0};
  9579. char statusstrtemp[20]={0};
  9580. int expiryDateISNULL=FALSE;
  9581. int parentIdTagISNULL=FALSE;
  9582. char sstr[160]={0};
  9583. char* filename = AuthorizationCache_JSON;
  9584. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9585. char *loc;
  9586. int resultRename=0;
  9587. int responseIdTagInfoAsZero= 0;
  9588. char rmFileCmd[50]={0};
  9589. DEBUG_INFO("handleAuthorizeResponse...\n");
  9590. json_object *Authorize;
  9591. Authorize = json_tokener_parse(payload);
  9592. if(!is_error(Authorize))
  9593. {
  9594. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9595. {
  9596. // Required data
  9597. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9598. // Optional data
  9599. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9600. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9601. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9602. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9603. }
  9604. }
  9605. json_object_put(Authorize);
  9606. if(expiryDateISNULL == FALSE)
  9607. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9608. if(parentIdTagISNULL == FALSE)
  9609. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9610. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9611. //Update idTag information to authorization cache if supproted
  9612. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9613. {
  9614. if((access(filename,F_OK))!=-1)
  9615. {
  9616. printf("AuthorizationCache exist.\n");
  9617. }
  9618. else
  9619. {
  9620. printf("AuthorizationCache not exist\n");
  9621. FILE *log = fopen(filename, "w+");
  9622. if(log == NULL)
  9623. {
  9624. printf("log is NULL\n");
  9625. goto out;
  9626. }
  9627. else
  9628. {
  9629. fclose(log);
  9630. }
  9631. }
  9632. FILE *infile;
  9633. FILE *outfile;
  9634. // open file for writing
  9635. infile = fopen (filename, "r");
  9636. outfile = fopen (tempfile, "w");
  9637. int c;
  9638. c = fgetc(infile);
  9639. //DEBUG_INFO("c:%d\n",c);
  9640. rewind(infile);
  9641. if(c == EOF)
  9642. {
  9643. DEBUG_INFO("Orignal File is NULL\n");
  9644. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9645. {
  9646. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9647. }
  9648. else
  9649. {
  9650. strcpy(expiryDatestrtemp, "");
  9651. }
  9652. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9653. {
  9654. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9655. }
  9656. else
  9657. {
  9658. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9659. }
  9660. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9661. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9662. fclose(infile);
  9663. fclose(outfile);
  9664. sprintf(rmFileCmd,"rm -f %s",filename);
  9665. system(rmFileCmd);
  9666. resultRename = rename(tempfile, filename);
  9667. if(resultRename == 0)
  9668. {
  9669. printf("File renamed successfully");
  9670. }
  9671. else
  9672. {
  9673. printf("Error: unable to rename the file");
  9674. }
  9675. }
  9676. else
  9677. {
  9678. char buf[160]={0};
  9679. while (fgets(buf, sizeof(buf), infile) != NULL)
  9680. {
  9681. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9682. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9683. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9684. memset(statusstr, 0, sizeof(statusstrtemp));
  9685. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9686. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9687. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9688. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9689. //------------------IdTag-----------------------
  9690. loc = strstr(buf, "idTag");
  9691. memset(sstr ,0, sizeof(sstr) );
  9692. c = 0;
  9693. while (loc[3+strlen("idTag")+c] != '\"')
  9694. {
  9695. sstr[c] = loc[3+strlen("idTag")+c];
  9696. c++;
  9697. }
  9698. sstr[c] = '\0';
  9699. strcpy(IdTagstrtemp,sstr);
  9700. //*********************expiryDate***************/
  9701. loc = strstr(buf, "expiryDate");
  9702. memset(sstr ,0, sizeof(sstr) );
  9703. c = 0;
  9704. while (loc[3+strlen("expiryDate")+c] != '\"')
  9705. {
  9706. sstr[c] = loc[3+strlen("expiryDate")+c];
  9707. c++;
  9708. }
  9709. sstr[c] = '\0';
  9710. strcpy(expiryDatestr,sstr);
  9711. //*********************parentIdTag***************/
  9712. loc = strstr(buf, "parentIdTag");
  9713. memset(sstr ,0, sizeof(sstr) );
  9714. c = 0;
  9715. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9716. {
  9717. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9718. c++;
  9719. }
  9720. sstr[c] = '\0';
  9721. strcpy(parentIdTagstr,sstr);
  9722. //*********************status***************/
  9723. loc = strstr(buf, "status");
  9724. memset(sstr ,0, sizeof(sstr) );
  9725. c = 0;
  9726. while (loc[3+strlen("status")+c] != '\"')
  9727. {
  9728. sstr[c] = loc[3+strlen("status")+c];
  9729. c++;
  9730. }
  9731. sstr[c] = '\0';
  9732. strcpy(statusstr,sstr);
  9733. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9734. {
  9735. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9736. responseIdTagInfoAsZero = 1;
  9737. }
  9738. else
  9739. {
  9740. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9741. }
  9742. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9743. {
  9744. //modify item
  9745. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9746. {
  9747. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9748. }
  9749. else
  9750. {
  9751. strcpy(expiryDatestrtemp, "");
  9752. }
  9753. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9754. {
  9755. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9756. }
  9757. else
  9758. {
  9759. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9760. }
  9761. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9762. }
  9763. else
  9764. {
  9765. //wrie original item
  9766. strcpy(expiryDatestrtemp, expiryDatestr);
  9767. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9768. strcpy(statusstrtemp, statusstr);
  9769. }
  9770. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9771. }
  9772. fclose(infile);
  9773. fclose(outfile);
  9774. sprintf(rmFileCmd,"rm -f %s",filename);
  9775. system(rmFileCmd);
  9776. resultRename = rename(tempfile, filename);
  9777. if(resultRename == 0)
  9778. {
  9779. DEBUG_INFO("File renamed successfully");
  9780. }
  9781. else
  9782. {
  9783. DEBUG_INFO("Error: unable to rename the file");
  9784. }
  9785. }
  9786. }
  9787. out:
  9788. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9789. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9790. authorizeRetryTimes = 0;
  9791. }
  9792. char * strtrimc( char * s )
  9793. {
  9794. char * p1 = s;
  9795. char * p2 = s;
  9796. while(*p1 != '\0')
  9797. {
  9798. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9799. {
  9800. if(*p1 != ',')
  9801. {
  9802. p1 ++;
  9803. }
  9804. else
  9805. {
  9806. break;
  9807. }
  9808. }
  9809. if(*p1 != ',')
  9810. {
  9811. * p2 ++ = *p1 ++;
  9812. //printf("p2=%s\n",p2);
  9813. }
  9814. else
  9815. {
  9816. break;
  9817. }
  9818. }
  9819. *p2 = '\0';
  9820. return (s);
  9821. }
  9822. void handleBootNotificationResponse(char *payload, int gun_index)
  9823. {
  9824. mtrace();
  9825. char statusStr[12]={0};
  9826. char currentTimeStr[30]={0};
  9827. int intervalInt = 0;
  9828. struct tm tp;
  9829. char buf[28]={0};
  9830. char timebuf[50]={0};
  9831. DEBUG_INFO("handleBootNotificationResponse...\n");
  9832. json_object *BootNotification;
  9833. BootNotification = json_tokener_parse(payload);
  9834. if(!is_error(BootNotification))
  9835. {
  9836. // Required data
  9837. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9838. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9839. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9840. }
  9841. json_object_put(BootNotification);
  9842. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9843. BootNotificationInterval = intervalInt;
  9844. HeartBeatWaitTime = intervalInt;
  9845. //write back to ShmOCPP16Data->BootNotification
  9846. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9847. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9848. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9849. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9850. {
  9851. server_sign = TRUE;
  9852. server_pending =FALSE;
  9853. }
  9854. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9855. {
  9856. server_pending = TRUE;
  9857. }
  9858. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9859. tp.tm_isdst = -1;
  9860. //time_t utc = mktime(&tp);
  9861. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9862. memset(timebuf, 0, sizeof timebuf);
  9863. sprintf(timebuf,"date -s '%s'",buf);
  9864. system(timebuf);
  9865. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-5);
  9866. //==============================================
  9867. // RTC sync
  9868. //==============================================
  9869. system("/sbin/hwclock -w --systohc");
  9870. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9871. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9872. sendFirmwareVersionByDataTransfer();
  9873. }
  9874. void handleDataTransferResponse(char *payload, int gun_index)
  9875. {
  9876. char sstr[160]={0};//sstr[200]={ 0 };
  9877. int c = 0;
  9878. char *loc;
  9879. DEBUG_INFO("handleDataTransferResponse ...\n");
  9880. loc = strstr(payload, "status");
  9881. printf("loc=%s\n",loc);
  9882. c = 0;
  9883. while (loc[3+strlen("status")+c] != '\"')
  9884. {
  9885. sstr[c] = loc[3+strlen("status")+c];
  9886. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9887. c++;
  9888. }
  9889. sstr[c] = '\0';
  9890. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9891. }
  9892. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9893. {
  9894. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9895. //struct json_object *obj;
  9896. // obj = json_tokener_parse(payload);
  9897. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9898. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9899. //No fields are defined.
  9900. }
  9901. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9902. {
  9903. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9904. //struct json_object *obj;
  9905. // obj = json_tokener_parse(payload);
  9906. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9907. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9908. //No fields are defined.
  9909. }
  9910. void handleHeartbeatResponse(char *payload, int gun_index)
  9911. {
  9912. mtrace();
  9913. struct tm tp;
  9914. char buf[28]={0};
  9915. char timebuf[50]={0};
  9916. DEBUG_INFO("handleHeartbeatResponse...\n");
  9917. json_object *Heartbeat;
  9918. Heartbeat = json_tokener_parse(payload);
  9919. if(!is_error(Heartbeat))
  9920. {
  9921. // Required data
  9922. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9923. }
  9924. json_object_put(BootNotification);
  9925. if(FirstHeartBeat == 0)
  9926. {
  9927. FirstHeartBeat = 1;
  9928. DEBUG_INFO("FirstHeartBeat \n");
  9929. }
  9930. HeartBeatWithNOResponse = 0;
  9931. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9932. tp.tm_isdst = -1;
  9933. //time_t utc = mktime(&tp);
  9934. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9935. memset(timebuf, 0, sizeof timebuf);
  9936. sprintf(timebuf,"date -s '%s'",buf);
  9937. system(timebuf);
  9938. //==============================================
  9939. // RTC sync
  9940. //==============================================
  9941. system("/sbin/hwclock -w --systohc");
  9942. //===============================================
  9943. //Print Out HeartBeat log
  9944. //===============================================
  9945. {
  9946. double diff_t;
  9947. struct tm tp,tp1;
  9948. // BootNotification Receive Time
  9949. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9950. tp.tm_isdst = -1;
  9951. time_t BootNotificationReceiveTime = mktime(&tp);
  9952. //HeartBeat Receive Time
  9953. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9954. tp1.tm_isdst = -1;
  9955. time_t HeartBeatReceiveTime = mktime(&tp1);
  9956. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9957. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9958. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9959. {
  9960. HeartBeatCountPerHour = (int)diff_t / 3600;
  9961. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9962. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9963. }
  9964. }
  9965. }
  9966. void handleMeterValuesResponse(char *payload, int gun_index)
  9967. {
  9968. mtrace();
  9969. DEBUG_INFO("handleMeterValuesResponse...\n");
  9970. }
  9971. void handleStartTransactionResponse(char *payload, int gun_index)
  9972. {
  9973. mtrace();
  9974. //int transactionIdInt = 0;
  9975. FILE *outfile;
  9976. char data[100]={0};
  9977. DEBUG_INFO("handleStartTransactionResponse...\n");
  9978. json_object *StartTransaction;
  9979. StartTransaction = json_tokener_parse(payload);
  9980. if(!is_error(StartTransaction))
  9981. {
  9982. // Required data
  9983. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9984. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9985. // Optional data
  9986. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9987. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9988. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9989. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9990. }
  9991. json_object_put(StartTransaction);
  9992. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9993. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9994. //-----------Start : write to the Queue TransactionId file -----------------//
  9995. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9996. {}
  9997. else
  9998. {
  9999. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10000. if(log == NULL)
  10001. {
  10002. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10003. return ;
  10004. }
  10005. else
  10006. {
  10007. fclose(log);
  10008. }
  10009. }
  10010. // open file for writing
  10011. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10012. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10013. {
  10014. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10015. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10016. fputs(data, outfile);
  10017. fclose (outfile);
  10018. }
  10019. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10020. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10021. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10022. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10023. }
  10024. void handleStatusNotificationResponse(char *payload, int gun_index)
  10025. {
  10026. mtrace();
  10027. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10028. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10029. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10030. }
  10031. void handleStopTransactionnResponse(char *payload, int gun_index)
  10032. {
  10033. mtrace();
  10034. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10035. json_object *StopTransaction;
  10036. StopTransaction = json_tokener_parse(payload);
  10037. if(!is_error(StopTransaction))
  10038. {
  10039. // Optional data
  10040. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10041. {
  10042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10043. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10045. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10046. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10047. }
  10048. }
  10049. json_object_put(StopTransaction);
  10050. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10051. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10052. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10053. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10054. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10055. }
  10056. //==========================================
  10057. // Handle Error routine
  10058. //==========================================
  10059. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10060. {
  10061. mtrace();
  10062. #ifdef SystemLogMessage
  10063. DEBUG_INFO("errorCode: %s\n", errorCode);
  10064. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10065. DEBUG_INFO("errorDetails: %s\n", payload);
  10066. #endif
  10067. }
  10068. //===============================================
  10069. // Common routine
  10070. //===============================================
  10071. int initialConfigurationTable(void)
  10072. {
  10073. //clock_t start_t, end_t, total_t;
  10074. FILE *fp;
  10075. FILE *outfile;
  10076. char str[200]={0};
  10077. char sstr[100]={0};
  10078. int c = 0;
  10079. char *loc;
  10080. DEBUG_INFO("initialConfigurationTable...\n");
  10081. //start_t = clock();
  10082. //printf("Starting of the program, start_t = %ld\n", start_t);
  10083. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10084. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10085. {
  10086. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10087. if(outfile == NULL)
  10088. {
  10089. DEBUG_INFO("Error opening file\n");
  10090. return FALSE;
  10091. }
  10092. /*Core Profile*/
  10093. //AllowOfflineTxForUnknownId
  10094. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10095. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10096. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10097. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10098. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10099. //AuthorizationCacheEnabled
  10100. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10101. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10102. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10103. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10104. //AuthorizeRemoteTxRequests
  10105. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10107. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10108. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10109. //BlinkRepeat
  10110. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10112. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10113. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10114. //ClockAlignedDataInterval
  10115. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10117. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10118. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10119. //ConnectionTimeOut
  10120. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10122. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10123. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10124. //GetConfigurationMaxKeys
  10125. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10127. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10128. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10129. // HeartbeatInterval
  10130. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10131. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10132. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10133. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10134. // LightIntensity
  10135. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10136. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10138. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10139. // LocalAuthorizeOffline
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10141. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10142. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10143. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10144. // LocalPreAuthorize
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10146. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10149. // MaxEnergyOnInvalidId
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10152. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10153. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10154. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10155. // MeterValuesAlignedData
  10156. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10157. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10158. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "" );
  10159. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "");
  10160. // MeterValuesAlignedDataMaxLength
  10161. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10162. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10165. // MeterValuesSampledData
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10169. 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");
  10170. // MeterValuesSampledDataMaxLength
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10175. // MeterValueSampleInterval
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10180. // MinimumStatusDuration
  10181. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10184. server_cycle_Status = 120; //StatusNotification cycle
  10185. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10186. // NumberOfConnectors
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10190. {
  10191. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10192. }
  10193. else
  10194. {
  10195. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10196. }
  10197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10198. // ResetRetries
  10199. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10203. // ConnectorPhaseRotation
  10204. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10208. // ConnectorPhaseRotationMaxLength
  10209. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10213. // StopTransactionOnEVSideDisconnect
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10218. // StopTransactionOnInvalidId
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10223. // StopTxnAlignedData
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10226. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10227. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10228. // StopTxnAlignedDataMaxLength
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10230. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10231. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10232. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10233. // StopTxnSampledData
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10235. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10236. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10237. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10238. // StopTxnSampledDataMaxLength
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10240. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10241. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10242. {
  10243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10244. }
  10245. else
  10246. {
  10247. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10248. }
  10249. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10251. // SupportedFeatureProfiles
  10252. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10255. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10256. // SupportedFeatureProfilesMaxLength
  10257. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10258. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10260. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10261. // TransactionMessageAttempts
  10262. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10263. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10264. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10265. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10266. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10267. // TransactionMessageRetryInterval
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10269. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10270. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10271. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10272. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10273. // UnlockConnectorOnEVSideDisconnect
  10274. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10275. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10277. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10278. // WebSocketPingInterval
  10279. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10280. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10282. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10283. //* Local Auth List Management Profile*/
  10284. #if 0
  10285. //For OCTT Test Case
  10286. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10289. #endif
  10290. #if 1
  10291. //LocalAuthListEnabled
  10292. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10294. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10295. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10296. #endif
  10297. //LocalAuthListMaxLength
  10298. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10299. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10300. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10301. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10302. //SendLocalListMaxLength
  10303. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10304. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10305. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10306. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10307. //ReserveConnectorZeroSupported
  10308. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10311. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10312. //* Smart Charging Profile */
  10313. //ChargeProfileMaxStackLevel
  10314. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10318. // ChargingScheduleAllowedChargingRateUnit
  10319. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10320. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10322. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10323. // ChargingScheduleMaxPeriods
  10324. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10327. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10328. // ConnectorSwitch3to1PhaseSupported
  10329. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10332. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10333. // MaxChargingProfilesInstalled
  10334. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10336. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10338. fclose(outfile);
  10339. }
  10340. else
  10341. {
  10342. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10343. char keystr[60]={0};
  10344. char readonlystr[10]={0};
  10345. char valuestr[100]={0};
  10346. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10347. if(fp == NULL) {
  10348. DEBUG_INFO("Error opening file");
  10349. return FALSE;
  10350. }
  10351. while( fgets (str, sizeof(str), fp)!=NULL )
  10352. {
  10353. //DEBUG_INFO("Get Configuration \n");
  10354. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10355. //*************************key*********************************/
  10356. loc = strstr(str, "key");
  10357. c = 0;
  10358. memset(sstr ,0, sizeof(sstr) );
  10359. while (loc[strlen("key")+3+c] != '\"')
  10360. {
  10361. sstr[c] = loc[strlen("key")+3+c];
  10362. c++;
  10363. }
  10364. sstr[c] = '\0';
  10365. strcpy(keystr,sstr);
  10366. //*************************readonly*********************************/
  10367. loc = strstr(str, "readonly");
  10368. c = 0;
  10369. memset(sstr ,0, sizeof(sstr) );
  10370. while (loc[strlen("readonly")+2+c] != ',')
  10371. {
  10372. sstr[c] = loc[strlen("readonly")+2+c];
  10373. c++;
  10374. }
  10375. sstr[c] = '\0';
  10376. strcpy(readonlystr,sstr);
  10377. //*************************value*********************************/
  10378. loc = strstr(str, "value");
  10379. c = 0;
  10380. memset(sstr ,0, sizeof(sstr) );
  10381. while (loc[strlen("value")+3+c] != '\"')
  10382. {
  10383. sstr[c] = loc[strlen("value")+3+c];
  10384. c++;
  10385. }
  10386. sstr[c] = '\0';
  10387. strcpy(valuestr,sstr);
  10388. // DEBUG_INFO("keystr=%s\n",keystr);
  10389. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10390. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10391. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10392. {
  10393. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10394. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10395. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10396. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10397. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10398. }
  10399. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10400. {
  10401. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10402. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10403. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10404. }
  10405. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10406. {
  10407. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10408. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10409. }
  10410. if(strcmp(keystr, "BlinkRepeat") == 0)
  10411. {
  10412. //Charger.BlinkRepeat = Integer.parseInt(value);
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10415. }
  10416. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10417. {
  10418. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10420. }
  10421. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10422. {
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10425. }
  10426. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10427. {
  10428. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10430. }
  10431. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10432. {
  10433. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10435. HeartBeatWaitTime = atoi(valuestr);
  10436. }
  10437. if(strcmp(keystr, "LightIntensity") == 0)
  10438. {
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10440. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10441. }
  10442. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10443. {
  10444. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10445. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10446. }
  10447. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10448. {
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10450. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10451. }
  10452. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10453. {
  10454. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10455. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10456. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10457. }
  10458. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10459. {
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10462. }
  10463. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10464. {
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10467. }
  10468. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10469. {
  10470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10471. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10472. }
  10473. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10474. {
  10475. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10476. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10477. }
  10478. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10479. {
  10480. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10482. }
  10483. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10484. {
  10485. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10487. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10488. }
  10489. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10490. {
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10492. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10493. }
  10494. if(strcmp(keystr, "ResetRetries") == 0)
  10495. {
  10496. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10497. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10498. }
  10499. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10500. {
  10501. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10502. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10503. }
  10504. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10505. {
  10506. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10507. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10508. }
  10509. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10510. {
  10511. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10512. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10513. }
  10514. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10515. {
  10516. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10517. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10518. }
  10519. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10520. {
  10521. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10522. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10523. }
  10524. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10525. {
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10528. }
  10529. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10533. }
  10534. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10538. }
  10539. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10543. }
  10544. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10548. }
  10549. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10553. TransactionMessageAttemptsValue = atoi(valuestr);
  10554. }
  10555. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10556. {
  10557. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10558. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10559. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10560. }
  10561. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10562. {
  10563. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10565. }
  10566. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10567. {
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10570. }
  10571. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10572. {
  10573. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10575. }
  10576. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10577. {
  10578. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10579. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10580. }
  10581. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10582. {
  10583. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10584. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10585. }
  10586. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10587. {
  10588. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10590. }
  10591. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10592. {
  10593. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10594. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10595. }
  10596. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10597. {
  10598. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10599. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10600. }
  10601. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10602. {
  10603. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10604. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10605. }
  10606. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10607. {
  10608. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10609. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10610. }
  10611. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10612. {
  10613. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10614. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10615. }
  10616. }
  10617. fclose(fp);
  10618. }
  10619. return 0;
  10620. }
  10621. void StoreConfigurationTable(void)
  10622. {
  10623. FILE *outfile;
  10624. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10625. if(outfile == NULL)
  10626. {
  10627. DEBUG_INFO("Error opening file");
  10628. return ;
  10629. }
  10630. /*Core Profile*/
  10631. //AllowOfflineTxForUnknownId
  10632. /*
  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, "TRUE" );
  10637. */
  10638. //DEBUG_INFO("data=%s\n",data);
  10639. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10640. //AuthorizationCacheEnabled
  10641. /*
  10642. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10643. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10645. */
  10646. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10647. //AuthorizeRemoteTxRequests
  10648. /*
  10649. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10650. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10652. */
  10653. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10654. //BlinkRepeat
  10655. /*
  10656. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10657. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10659. */
  10660. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10661. //ClockAlignedDataInterval
  10662. /*
  10663. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10664. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10666. */
  10667. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10668. //ConnectionTimeOut
  10669. /*
  10670. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10671. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10672. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10673. */
  10674. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10675. //GetConfigurationMaxKeys
  10676. /*
  10677. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10678. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10679. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10680. */
  10681. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10682. // HeartbeatInterval
  10683. /*
  10684. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10685. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10686. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10687. */
  10688. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10689. // LightIntensity
  10690. /*
  10691. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10692. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10693. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10694. */
  10695. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10696. // LocalAuthorizeOffline
  10697. /*
  10698. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10699. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10700. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10701. */
  10702. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10703. // LocalPreAuthorize
  10704. /*
  10705. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10708. */
  10709. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10710. // MaxEnergyOnInvalidId
  10711. /*
  10712. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10713. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10715. */
  10716. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10718. // MeterValuesAlignedData
  10719. /*
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10723. */
  10724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10725. // MeterValuesAlignedDataMaxLength
  10726. /*
  10727. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10730. */
  10731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10732. // MeterValuesSampledData
  10733. /*
  10734. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10737. */
  10738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10739. // MeterValuesSampledDataMaxLength
  10740. /*
  10741. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10744. */
  10745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10746. // MeterValueSampleInterval
  10747. /*
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10751. */
  10752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10753. // MinimumStatusDuration
  10754. /*
  10755. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10758. */
  10759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10760. // NumberOfConnectors
  10761. /*
  10762. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10765. {
  10766. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10767. }
  10768. else
  10769. {
  10770. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10771. }
  10772. */
  10773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10774. // ResetRetries
  10775. /*
  10776. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10779. */
  10780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10781. // ConnectorPhaseRotation
  10782. /*
  10783. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10786. */
  10787. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10788. // ConnectorPhaseRotationMaxLength
  10789. /*
  10790. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10791. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10793. */
  10794. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10795. // StopTransactionOnEVSideDisconnect
  10796. /*
  10797. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10800. */
  10801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10802. // StopTransactionOnInvalidId
  10803. /*
  10804. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10807. */
  10808. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10809. // StopTxnAlignedData
  10810. /*
  10811. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10812. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10814. */
  10815. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10816. // StopTxnAlignedDataMaxLength
  10817. /*
  10818. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10821. */
  10822. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10823. // StopTxnSampledData
  10824. /*
  10825. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10828. */
  10829. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10830. // StopTxnSampledDataMaxLength
  10831. /*
  10832. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10833. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10835. */
  10836. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10837. // SupportedFeatureProfiles
  10838. /*
  10839. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10842. */
  10843. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10844. // SupportedFeatureProfilesMaxLength
  10845. /*
  10846. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10849. */
  10850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10851. // TransactionMessageAttempts
  10852. /*
  10853. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10856. */
  10857. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10858. // TransactionMessageRetryInterval
  10859. /*
  10860. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10861. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10863. */
  10864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10865. // UnlockConnectorOnEVSideDisconnect
  10866. /*
  10867. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10870. */
  10871. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10872. // WebSocketPingInterval
  10873. /*
  10874. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10875. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10877. */
  10878. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10879. //* Local Auth List Management Profile*/
  10880. //LocalAuthListEnabled
  10881. /*
  10882. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10885. */
  10886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10887. //LocalAuthListMaxLength
  10888. /*
  10889. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10892. */
  10893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10894. //SendLocalListMaxLength
  10895. /*
  10896. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10899. */
  10900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10901. //ReserveConnectorZeroSupported
  10902. /*
  10903. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10906. */
  10907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10908. //* Smart Charging Profile */
  10909. //ChargeProfileMaxStackLevel
  10910. /*
  10911. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10914. */
  10915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10916. // ChargingScheduleAllowedChargingRateUnit
  10917. /*
  10918. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10921. */
  10922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10923. // ChargingScheduleMaxPeriods
  10924. /*
  10925. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10928. */
  10929. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10930. // ConnectorSwitch3to1PhaseSupported
  10931. /*
  10932. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10935. */
  10936. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10937. // MaxChargingProfilesInstalled
  10938. /*
  10939. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10942. */
  10943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10944. fclose(outfile);
  10945. }
  10946. void getKeyValue(char *keyReq)
  10947. {
  10948. int isEmpty = FALSE;
  10949. int isKnowKey = FALSE;
  10950. DEBUG_INFO("keyReq = %s\n", keyReq);
  10951. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10952. isEmpty = TRUE;
  10953. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10954. {
  10955. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10957. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10958. {
  10959. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10960. }
  10961. else
  10962. {
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10964. }
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10966. isKnowKey = TRUE;
  10967. }
  10968. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10969. {
  10970. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10972. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10973. {
  10974. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10975. }
  10976. else
  10977. {
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10979. }
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10981. isKnowKey = TRUE;
  10982. }
  10983. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10984. {
  10985. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10987. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10988. {
  10989. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10990. }
  10991. else
  10992. {
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10994. }
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10996. isKnowKey = TRUE;
  10997. }
  10998. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10999. {
  11000. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11002. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11003. {
  11004. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11005. }
  11006. else
  11007. {
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11009. }
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11011. isKnowKey = TRUE;
  11012. }
  11013. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11014. {
  11015. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11017. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11018. {
  11019. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11020. }
  11021. else
  11022. {
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11024. }
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11026. isKnowKey = TRUE;
  11027. }
  11028. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11029. {
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11032. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11033. {
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11035. }
  11036. else
  11037. {
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11039. }
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11041. isKnowKey = TRUE;
  11042. }
  11043. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11044. {
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11047. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11050. }
  11051. else
  11052. {
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11054. }
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11056. isKnowKey = TRUE;
  11057. }
  11058. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11059. {
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11062. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11065. }
  11066. else
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11069. }
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11071. isKnowKey = TRUE;
  11072. }
  11073. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11074. {
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11077. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11080. }
  11081. else
  11082. {
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11084. }
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11086. isKnowKey = TRUE;
  11087. }
  11088. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11092. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11095. }
  11096. else
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11099. }
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11101. isKnowKey = TRUE;
  11102. }
  11103. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11107. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11110. }
  11111. else
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11114. }
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11116. isKnowKey = TRUE;
  11117. }
  11118. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11125. }
  11126. else
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11129. }
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11131. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11132. isKnowKey = TRUE;
  11133. }
  11134. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11177. isKnowKey = TRUE;
  11178. }
  11179. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11186. }
  11187. else
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11190. }
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11192. isKnowKey = TRUE;
  11193. }
  11194. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11201. }
  11202. else
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11205. }
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11207. isKnowKey = TRUE;
  11208. }
  11209. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11216. }
  11217. else
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11220. }
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11222. isKnowKey = TRUE;
  11223. }
  11224. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11231. }
  11232. else
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11235. }
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11237. isKnowKey = TRUE;
  11238. }
  11239. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11246. }
  11247. else
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11250. }
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11252. isKnowKey = TRUE;
  11253. }
  11254. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11258. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11261. }
  11262. else
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11265. }
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11267. isKnowKey = TRUE;
  11268. }
  11269. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11276. }
  11277. else
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11280. }
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11282. isKnowKey = TRUE;
  11283. }
  11284. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11288. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11291. }
  11292. else
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11295. }
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11297. isKnowKey = TRUE;
  11298. }
  11299. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11303. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11306. }
  11307. else
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11310. }
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11312. isKnowKey = TRUE;
  11313. }
  11314. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11315. {
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11321. }
  11322. else
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11325. }
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11327. isKnowKey = TRUE;
  11328. }
  11329. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11333. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11336. }
  11337. else
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11340. }
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11342. isKnowKey = TRUE;
  11343. }
  11344. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11351. }
  11352. else
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11355. }
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11357. isKnowKey = TRUE;
  11358. }
  11359. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11363. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11366. }
  11367. else
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11370. }
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11372. isKnowKey = TRUE;
  11373. }
  11374. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11381. }
  11382. else
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11385. }
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11387. isKnowKey = TRUE;
  11388. }
  11389. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11393. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11396. }
  11397. else
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11400. }
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11402. isKnowKey = TRUE;
  11403. }
  11404. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11408. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11411. }
  11412. else
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11415. }
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11417. isKnowKey = TRUE;
  11418. }
  11419. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11423. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11426. }
  11427. else
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11430. }
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11432. isKnowKey = TRUE;
  11433. }
  11434. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11438. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11441. }
  11442. else
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11445. }
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11447. isKnowKey = TRUE;
  11448. }
  11449. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11453. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11456. }
  11457. else
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11460. }
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11462. isKnowKey = TRUE;
  11463. }
  11464. #if 1
  11465. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11468. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11469. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11472. }
  11473. else
  11474. {
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11476. }
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11478. isKnowKey = TRUE;
  11479. }
  11480. #endif
  11481. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11482. {
  11483. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11484. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11485. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11486. {
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11488. }
  11489. else
  11490. {
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11492. }
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11494. isKnowKey = TRUE;
  11495. }
  11496. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11497. {
  11498. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11499. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11500. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11501. {
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11503. }
  11504. else
  11505. {
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11507. }
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11509. isKnowKey = TRUE;
  11510. }
  11511. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11512. {
  11513. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11514. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11515. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11516. {
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11518. }
  11519. else
  11520. {
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11522. }
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11524. isKnowKey = TRUE;
  11525. }
  11526. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11527. {
  11528. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11529. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11530. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11531. {
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11533. }
  11534. else
  11535. {
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11537. }
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11539. isKnowKey = TRUE;
  11540. }
  11541. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11542. {
  11543. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11544. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11545. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11546. {
  11547. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11548. }
  11549. else
  11550. {
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11552. }
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11554. isKnowKey = TRUE;
  11555. }
  11556. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11559. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11560. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11563. }
  11564. else
  11565. {
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11567. }
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11569. isKnowKey = TRUE;
  11570. }
  11571. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11574. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11575. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11578. }
  11579. else
  11580. {
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11582. }
  11583. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11584. isKnowKey = TRUE;
  11585. }
  11586. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11589. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11590. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11593. }
  11594. else
  11595. {
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11597. }
  11598. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11599. isKnowKey = TRUE;
  11600. }
  11601. //=========================================================
  11602. if(!isEmpty && !isKnowKey)
  11603. {
  11604. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11605. strcpy(unknownkey[UnknownKeynum], keyReq);
  11606. UnknownKeynum = UnknownKeynum + 1;
  11607. }
  11608. }
  11609. void processUnkownKey(void)
  11610. {
  11611. DEBUG_INFO("processUnkownKey...\n");
  11612. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11613. for(int index=0; index < UnknownKeynum; index++)
  11614. {
  11615. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11616. {
  11617. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11618. }
  11619. }
  11620. }
  11621. int setKeyValue(char *key, char *value)
  11622. {
  11623. int isSuccess = NotSupported;
  11624. int check_ascii=0;
  11625. char str[10]={0};
  11626. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11627. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11628. {
  11629. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11630. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11631. {
  11632. strcpy(str, (const char*)value);
  11633. for(int i = 0; str[i]; i++){
  11634. str[i] = tolower(str[i]);
  11635. }
  11636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11637. isSuccess = ConfigurationStatus_Accepted;
  11638. }
  11639. else
  11640. {
  11641. isSuccess = ConfigurationStatus_Rejected;
  11642. }
  11643. }
  11644. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11645. {
  11646. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11647. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11648. {
  11649. strcpy(str, (const char*)value);
  11650. for(int i = 0; str[i]; i++){
  11651. str[i] = tolower(str[i]);
  11652. }
  11653. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11654. isSuccess = ConfigurationStatus_Accepted;
  11655. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11656. }
  11657. else
  11658. {
  11659. isSuccess = ConfigurationStatus_Rejected;
  11660. }
  11661. }
  11662. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11663. {
  11664. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11665. {
  11666. strcpy(str, (const char*)value);
  11667. for(int i = 0; str[i]; i++)
  11668. {
  11669. str[i] = tolower(str[i]);
  11670. }
  11671. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11672. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11673. isSuccess = ConfigurationStatus_Accepted;
  11674. }
  11675. else
  11676. {
  11677. isSuccess = ConfigurationStatus_Rejected;
  11678. }
  11679. }
  11680. if(strcmp(key, "BlinkRepeat") == 0)
  11681. {
  11682. //Charger.BlinkRepeat = Integer.parseInt(value);
  11683. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11684. {
  11685. check_ascii = value[0];
  11686. if( (check_ascii < 48) || (check_ascii > 57) )
  11687. {
  11688. isSuccess = ConfigurationStatus_Rejected;
  11689. }
  11690. else
  11691. {
  11692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11693. isSuccess = ConfigurationStatus_Accepted;
  11694. }
  11695. }
  11696. else
  11697. {
  11698. isSuccess = ConfigurationStatus_Rejected;
  11699. }
  11700. }
  11701. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11702. {
  11703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11704. {
  11705. check_ascii = value[0];
  11706. if( (check_ascii < 48) || (check_ascii > 57) )
  11707. {
  11708. isSuccess = ConfigurationStatus_Rejected;
  11709. }
  11710. else
  11711. {
  11712. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11714. isSuccess = ConfigurationStatus_Accepted;
  11715. }
  11716. }
  11717. else
  11718. {
  11719. isSuccess = ConfigurationStatus_Rejected;
  11720. }
  11721. }
  11722. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11723. {
  11724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11725. {
  11726. check_ascii = value[0];
  11727. if( (check_ascii < 48) || (check_ascii > 57) )
  11728. {
  11729. isSuccess = ConfigurationStatus_Rejected;
  11730. }
  11731. else
  11732. {
  11733. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11734. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11735. isSuccess = ConfigurationStatus_Accepted;
  11736. }
  11737. }
  11738. else
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. }
  11743. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11744. {
  11745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11746. {
  11747. check_ascii = value[0];
  11748. if( (check_ascii < 48) || (check_ascii > 57) )
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. else
  11753. {
  11754. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11755. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11756. isSuccess = ConfigurationStatus_Accepted;
  11757. }
  11758. }
  11759. else
  11760. {
  11761. isSuccess = ConfigurationStatus_Rejected;
  11762. }
  11763. }
  11764. if(strcmp(key, "HeartbeatInterval") == 0)
  11765. {
  11766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11767. {
  11768. check_ascii = value[0];
  11769. if( (check_ascii < 48) || (check_ascii > 57) )
  11770. {
  11771. isSuccess = ConfigurationStatus_Rejected;
  11772. }
  11773. else
  11774. {
  11775. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11776. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11777. HeartBeatWaitTime = atoi(value);
  11778. isSuccess = ConfigurationStatus_Accepted;
  11779. }
  11780. }
  11781. else
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. }
  11786. if(strcmp(key, "LightIntensity") == 0)
  11787. {
  11788. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11789. {
  11790. check_ascii = value[0];
  11791. if( (check_ascii < 48) || (check_ascii > 57) )
  11792. {
  11793. isSuccess = ConfigurationStatus_Rejected;
  11794. }
  11795. else
  11796. {
  11797. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11798. isSuccess = ConfigurationStatus_Accepted;
  11799. }
  11800. }
  11801. else
  11802. {
  11803. isSuccess = ConfigurationStatus_Rejected;
  11804. }
  11805. }
  11806. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11807. {
  11808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11809. {
  11810. strcpy(str, (const char*)value);
  11811. for(int i = 0; str[i]; i++)
  11812. {
  11813. str[i] = tolower(str[i]);
  11814. }
  11815. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11816. isSuccess = ConfigurationStatus_Accepted;
  11817. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11818. }
  11819. else
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. }
  11824. if(strcmp(key, "LocalPreAuthorize") == 0)
  11825. {
  11826. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11827. {
  11828. strcpy(str, (const char*)value);
  11829. for(int i = 0; str[i]; i++)
  11830. {
  11831. str[i] = tolower(str[i]);
  11832. }
  11833. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11834. isSuccess = ConfigurationStatus_Accepted;
  11835. }
  11836. else
  11837. {
  11838. isSuccess = ConfigurationStatus_Rejected;
  11839. }
  11840. }
  11841. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11842. {
  11843. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11844. {
  11845. check_ascii = value[0];
  11846. if( (check_ascii < 48) || (check_ascii > 57) )
  11847. {
  11848. isSuccess = ConfigurationStatus_Rejected;
  11849. }
  11850. else
  11851. {
  11852. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11853. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11854. isSuccess = ConfigurationStatus_Accepted;
  11855. }
  11856. }
  11857. else
  11858. {
  11859. isSuccess = ConfigurationStatus_Rejected;
  11860. }
  11861. }
  11862. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11863. {
  11864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11865. {
  11866. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11867. isSuccess = ConfigurationStatus_Accepted;
  11868. }
  11869. else
  11870. {
  11871. isSuccess = ConfigurationStatus_Rejected;
  11872. }
  11873. }
  11874. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11875. {
  11876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11877. {
  11878. check_ascii = value[0];
  11879. if( (check_ascii < 48) || (check_ascii > 57) )
  11880. {
  11881. isSuccess = ConfigurationStatus_Rejected;
  11882. }
  11883. else
  11884. {
  11885. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11887. isSuccess = ConfigurationStatus_Accepted;
  11888. }
  11889. }
  11890. else
  11891. {
  11892. isSuccess = ConfigurationStatus_Rejected;
  11893. }
  11894. }
  11895. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11896. {
  11897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11898. {
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11900. isSuccess = ConfigurationStatus_Accepted;
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11910. {
  11911. check_ascii = value[0];
  11912. if( (check_ascii < 48) || (check_ascii > 57) )
  11913. {
  11914. isSuccess = ConfigurationStatus_Rejected;
  11915. }
  11916. else
  11917. {
  11918. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11919. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11920. isSuccess = ConfigurationStatus_Accepted;
  11921. }
  11922. }
  11923. else
  11924. {
  11925. isSuccess = ConfigurationStatus_Rejected;
  11926. }
  11927. }
  11928. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11929. {
  11930. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11931. {
  11932. check_ascii = value[0];
  11933. if( (check_ascii < 48) || (check_ascii > 57) )
  11934. {
  11935. isSuccess = ConfigurationStatus_Rejected;
  11936. }
  11937. else
  11938. {
  11939. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11941. isSuccess = ConfigurationStatus_Accepted;
  11942. }
  11943. }
  11944. else
  11945. {
  11946. isSuccess = ConfigurationStatus_Rejected;
  11947. }
  11948. }
  11949. if(strcmp(key, "MinimumStatusDuration") == 0)
  11950. {
  11951. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11952. {
  11953. check_ascii = value[0];
  11954. if( (check_ascii < 48) || (check_ascii > 57) )
  11955. {
  11956. isSuccess = ConfigurationStatus_Rejected;
  11957. }
  11958. else
  11959. {
  11960. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11961. {
  11962. isSuccess = ConfigurationStatus_Rejected;
  11963. }
  11964. else
  11965. {
  11966. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11967. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11968. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11969. isSuccess = ConfigurationStatus_Accepted;
  11970. }
  11971. }
  11972. }
  11973. else
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. }
  11978. if(strcmp(key, "NumberOfConnectors") == 0)
  11979. {
  11980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11981. {
  11982. check_ascii = value[0];
  11983. if( (check_ascii < 48) || (check_ascii > 57) )
  11984. {
  11985. isSuccess = ConfigurationStatus_Rejected;
  11986. }
  11987. else
  11988. {
  11989. //Charger.ResetRetries = Integer.parseInt(value);
  11990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11991. isSuccess = ConfigurationStatus_Accepted;
  11992. }
  11993. }
  11994. else
  11995. {
  11996. isSuccess = ConfigurationStatus_Rejected;
  11997. }
  11998. }
  11999. if(strcmp(key, "ResetRetries") == 0)
  12000. {
  12001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12002. {
  12003. check_ascii = value[0];
  12004. if( (check_ascii < 48) || (check_ascii > 57) )
  12005. {
  12006. isSuccess = ConfigurationStatus_Rejected;
  12007. }
  12008. else
  12009. {
  12010. //Charger.ResetRetries = Integer.parseInt(value);
  12011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12012. isSuccess = ConfigurationStatus_Accepted;
  12013. }
  12014. }
  12015. else
  12016. {
  12017. isSuccess = ConfigurationStatus_Rejected;
  12018. }
  12019. }
  12020. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12021. {
  12022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12023. {
  12024. strcpy(str, (const char*)value);
  12025. for(int i = 0; str[i]; i++)
  12026. {
  12027. str[i] = tolower(str[i]);
  12028. }
  12029. if(strcmp(str, "notapplicable")== 0)
  12030. {
  12031. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12032. isSuccess = ConfigurationStatus_Accepted;
  12033. }
  12034. else if(strcmp(str, "unknown")== 0)
  12035. {
  12036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12037. isSuccess = ConfigurationStatus_Accepted;
  12038. }
  12039. else if(strcmp(str, "rst")== 0)
  12040. {
  12041. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12042. isSuccess = ConfigurationStatus_Accepted;
  12043. }
  12044. else if(strcmp(str, "rts")== 0)
  12045. {
  12046. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12047. isSuccess = ConfigurationStatus_Accepted;
  12048. }
  12049. else if(strcmp(str, "srt")== 0)
  12050. {
  12051. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12052. isSuccess = ConfigurationStatus_Accepted;
  12053. }
  12054. else if(strcmp(str, "str")== 0)
  12055. {
  12056. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. }
  12059. else if(strcmp(str, "trs")== 0)
  12060. {
  12061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12062. isSuccess = ConfigurationStatus_Accepted;
  12063. }
  12064. else if(strcmp(str, "tsr")== 0)
  12065. {
  12066. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12067. isSuccess = ConfigurationStatus_Accepted;
  12068. }
  12069. else
  12070. {
  12071. isSuccess = ConfigurationStatus_Rejected;
  12072. }
  12073. }
  12074. else
  12075. {
  12076. isSuccess = ConfigurationStatus_Rejected;
  12077. }
  12078. }
  12079. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12080. {
  12081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12082. {
  12083. check_ascii = value[0];
  12084. if( (check_ascii < 48) || (check_ascii > 57) )
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. else
  12089. {
  12090. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12091. isSuccess = ConfigurationStatus_Accepted;
  12092. }
  12093. }
  12094. else
  12095. {
  12096. isSuccess = ConfigurationStatus_Rejected;
  12097. }
  12098. }
  12099. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12100. {
  12101. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12102. {
  12103. strcpy(str, (const char*)value);
  12104. for(int i = 0; str[i]; i++)
  12105. {
  12106. str[i] = tolower(str[i]);
  12107. }
  12108. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. }
  12112. else
  12113. {
  12114. isSuccess = ConfigurationStatus_Rejected;
  12115. }
  12116. }
  12117. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12118. {
  12119. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12120. {
  12121. strcpy(str, (const char*)value);
  12122. for(int i = 0; str[i]; i++)
  12123. {
  12124. str[i] = tolower(str[i]);
  12125. }
  12126. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12128. isSuccess = ConfigurationStatus_Accepted;
  12129. }
  12130. else
  12131. {
  12132. isSuccess = ConfigurationStatus_Rejected;
  12133. }
  12134. }
  12135. if(strcmp(key, "StopTxnAlignedData") == 0)
  12136. {
  12137. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12138. {
  12139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12140. isSuccess = ConfigurationStatus_Accepted;
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12148. {
  12149. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12150. {
  12151. check_ascii = value[0];
  12152. if( (check_ascii < 48) || (check_ascii > 57) )
  12153. {
  12154. isSuccess = ConfigurationStatus_Rejected;
  12155. }
  12156. else
  12157. {
  12158. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12159. isSuccess = ConfigurationStatus_Accepted;
  12160. }
  12161. }
  12162. else
  12163. {
  12164. isSuccess = ConfigurationStatus_Rejected;
  12165. }
  12166. }
  12167. if(strcmp(key, "StopTxnSampledData") == 0)
  12168. {
  12169. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12170. {
  12171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12172. isSuccess = ConfigurationStatus_Accepted;
  12173. }
  12174. else
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. }
  12179. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12180. {
  12181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12182. {
  12183. check_ascii = value[0];
  12184. if( (check_ascii < 48) || (check_ascii > 57) )
  12185. {
  12186. isSuccess = ConfigurationStatus_Rejected;
  12187. }
  12188. else
  12189. {
  12190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12191. isSuccess = ConfigurationStatus_Accepted;
  12192. }
  12193. }
  12194. else
  12195. {
  12196. isSuccess = ConfigurationStatus_Rejected;
  12197. }
  12198. }
  12199. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12200. {
  12201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12202. {
  12203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12204. isSuccess = ConfigurationStatus_Accepted;
  12205. }
  12206. else
  12207. {
  12208. isSuccess = ConfigurationStatus_Rejected;
  12209. }
  12210. }
  12211. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12212. {
  12213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12214. {
  12215. check_ascii = value[0];
  12216. if( (check_ascii < 48) || (check_ascii > 57) )
  12217. {
  12218. isSuccess = ConfigurationStatus_Rejected;
  12219. }
  12220. else
  12221. {
  12222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12223. isSuccess = ConfigurationStatus_Accepted;
  12224. }
  12225. }
  12226. else
  12227. {
  12228. isSuccess = ConfigurationStatus_Rejected;
  12229. }
  12230. }
  12231. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12232. {
  12233. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12234. {
  12235. check_ascii = value[0];
  12236. if( (check_ascii < 48) || (check_ascii > 57) )
  12237. {
  12238. isSuccess = ConfigurationStatus_Rejected;
  12239. }
  12240. else
  12241. {
  12242. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12244. TransactionMessageAttemptsValue = atoi(value);
  12245. isSuccess = ConfigurationStatus_Accepted;
  12246. }
  12247. }
  12248. else
  12249. {
  12250. isSuccess = ConfigurationStatus_Rejected;
  12251. }
  12252. }
  12253. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12254. {
  12255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12256. {
  12257. check_ascii = value[0];
  12258. if( (check_ascii < 48) || (check_ascii > 57) )
  12259. {
  12260. isSuccess = ConfigurationStatus_Rejected;
  12261. }
  12262. else
  12263. {
  12264. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12266. TransactionMessageRetryIntervalValue = atoi(value);
  12267. isSuccess = ConfigurationStatus_Accepted;
  12268. }
  12269. }
  12270. else
  12271. {
  12272. isSuccess = ConfigurationStatus_Rejected;
  12273. }
  12274. }
  12275. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12276. {
  12277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12278. {
  12279. strcpy(str, (const char*)value);
  12280. for(int i = 0; str[i]; i++)
  12281. {
  12282. str[i] = tolower(str[i]);
  12283. }
  12284. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12286. isSuccess = ConfigurationStatus_Accepted;
  12287. }
  12288. else
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. }
  12293. if(strcmp(key, "WebSocketPingInterval") == 0)
  12294. {
  12295. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12296. {
  12297. check_ascii = value[0];
  12298. if( (check_ascii < 48) || (check_ascii > 57) )
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. else
  12303. {
  12304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12305. isSuccess = ConfigurationStatus_Accepted;
  12306. }
  12307. }
  12308. else
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. }
  12313. #if 0
  12314. //For OCPP Test Case
  12315. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12316. {
  12317. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12318. {
  12319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12320. isSuccess = ConfigurationStatus_Accepted;
  12321. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12322. }
  12323. else
  12324. {
  12325. isSuccess = ConfigurationStatus_Rejected;
  12326. }
  12327. }
  12328. #endif
  12329. #if 1
  12330. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12331. {
  12332. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12333. {
  12334. strcpy(str, (const char*)value);
  12335. for(int i = 0; str[i]; i++)
  12336. {
  12337. str[i] = tolower(str[i]);
  12338. }
  12339. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12340. isSuccess = ConfigurationStatus_Accepted;
  12341. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12342. }
  12343. else
  12344. {
  12345. isSuccess = ConfigurationStatus_Rejected;
  12346. }
  12347. }
  12348. #endif
  12349. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12350. {
  12351. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12352. {
  12353. check_ascii = value[0];
  12354. if( (check_ascii < 48) || (check_ascii > 57) )
  12355. {
  12356. isSuccess = ConfigurationStatus_Rejected;
  12357. }
  12358. else
  12359. {
  12360. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12361. isSuccess = ConfigurationStatus_Accepted;
  12362. }
  12363. }
  12364. else
  12365. {
  12366. isSuccess = ConfigurationStatus_Rejected;
  12367. }
  12368. }
  12369. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12370. {
  12371. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12372. {
  12373. check_ascii = value[0];
  12374. if( (check_ascii < 48) || (check_ascii > 57) )
  12375. {
  12376. isSuccess = ConfigurationStatus_Rejected;
  12377. }
  12378. else
  12379. {
  12380. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12381. isSuccess = ConfigurationStatus_Accepted;
  12382. }
  12383. }
  12384. else
  12385. {
  12386. isSuccess = ConfigurationStatus_Rejected;
  12387. }
  12388. }
  12389. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12390. {
  12391. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].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.ReservationProfile[ReserveConnectorZeroSupported].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, "ChargeProfileMaxStackLevel") == 0)
  12407. {
  12408. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].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.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12418. isSuccess = ConfigurationStatus_Accepted;
  12419. }
  12420. }
  12421. else
  12422. {
  12423. isSuccess = ConfigurationStatus_Rejected;
  12424. }
  12425. }
  12426. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12427. {
  12428. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12429. {
  12430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12431. isSuccess = ConfigurationStatus_Accepted;
  12432. }
  12433. else
  12434. {
  12435. isSuccess = ConfigurationStatus_Rejected;
  12436. }
  12437. }
  12438. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12439. {
  12440. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12441. {
  12442. check_ascii = value[0];
  12443. if( (check_ascii < 48) || (check_ascii > 57) )
  12444. {
  12445. isSuccess = ConfigurationStatus_Rejected;
  12446. }
  12447. else
  12448. {
  12449. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12450. isSuccess = ConfigurationStatus_Accepted;
  12451. }
  12452. }
  12453. else
  12454. {
  12455. isSuccess = ConfigurationStatus_Rejected;
  12456. }
  12457. }
  12458. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12459. {
  12460. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12461. {
  12462. strcpy(str, (const char*)value);
  12463. for(int i = 0; str[i]; i++)
  12464. {
  12465. str[i] = tolower(str[i]);
  12466. }
  12467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12468. isSuccess = ConfigurationStatus_Accepted;
  12469. }
  12470. else
  12471. {
  12472. isSuccess = ConfigurationStatus_Rejected;
  12473. }
  12474. }
  12475. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12476. {
  12477. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12478. {
  12479. check_ascii = value[0];
  12480. if( (check_ascii < 48) || (check_ascii > 57) )
  12481. {
  12482. isSuccess = ConfigurationStatus_Rejected;
  12483. }
  12484. else
  12485. {
  12486. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12487. isSuccess = ConfigurationStatus_Accepted;
  12488. }
  12489. }
  12490. else
  12491. {
  12492. isSuccess = ConfigurationStatus_Rejected;
  12493. }
  12494. }
  12495. return isSuccess;
  12496. }
  12497. int TransactionMessageAttemptsGet(void)
  12498. {
  12499. return TransactionMessageAttemptsValue;
  12500. }
  12501. int FirstHeartBeatResponse(void)
  12502. {
  12503. return FirstHeartBeat;
  12504. }
  12505. int TransactionMessageRetryIntervalGet(void)
  12506. {
  12507. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12508. }
  12509. int ReadHttpStatus(int sock)
  12510. {
  12511. //char c;
  12512. char buff[1024]="",*ptr=buff+1;
  12513. int bytes_received, status;
  12514. DEBUG_INFO("Begin Response ..\n");
  12515. while((bytes_received = recv(sock, ptr, 1, 0))){
  12516. if(bytes_received==-1){
  12517. perror("ReadHttpStatus");
  12518. exit(1);
  12519. }
  12520. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12521. ptr++;
  12522. }
  12523. *ptr=0;
  12524. ptr=buff+1;
  12525. sscanf(ptr,"%*s %d ", &status);
  12526. DEBUG_INFO("%s\n",ptr);
  12527. DEBUG_INFO("status=%d\n",status);
  12528. DEBUG_INFO("End Response ..\n");
  12529. return (bytes_received>0)?status:0;
  12530. }
  12531. //the only filed that it parsed is 'Content-Length'
  12532. int ParseHeader(int sock)
  12533. {
  12534. //char c;
  12535. char buff[1024]="",*ptr=buff+4;
  12536. int bytes_received;
  12537. DEBUG_INFO("Begin HEADER ..\n");
  12538. while((bytes_received = recv(sock, ptr, 1, 0))){
  12539. if(bytes_received==-1){
  12540. perror("Parse Header");
  12541. exit(1);
  12542. }
  12543. if(
  12544. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12545. (ptr[-1]=='\r') && (*ptr=='\n' )
  12546. ) break;
  12547. ptr++;
  12548. }
  12549. *ptr=0;
  12550. ptr=buff+4;
  12551. //printf("%s",ptr);
  12552. if(bytes_received){
  12553. ptr=strstr(ptr,"Content-Length:");
  12554. if(ptr){
  12555. sscanf(ptr,"%*s %d",&bytes_received);
  12556. }else
  12557. bytes_received=-1; //unknown size
  12558. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12559. }
  12560. DEBUG_INFO("End HEADER ..\n");
  12561. return bytes_received ;
  12562. }
  12563. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12564. {
  12565. char rmFileCmd[100]={0};
  12566. char FilePath[100]={0};
  12567. char ftpbuf[200];
  12568. int systemresult;
  12569. //DEBUG_INFO("filename=%s\n",filename);
  12570. //DEBUG_INFO("url=%s\n",url);
  12571. sprintf(FilePath,"/mnt/%s",filename);
  12572. if((access(FilePath,F_OK))!=-1)
  12573. {
  12574. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12575. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12576. system(rmFileCmd);
  12577. }
  12578. memset(ftpbuf, 0, sizeof(ftpbuf));
  12579. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12580. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12581. systemresult = system(ftpbuf);
  12582. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12583. if(systemresult != 0)
  12584. {
  12585. DEBUG_INFO("http DownLoad error!\n");
  12586. return FALSE;
  12587. }
  12588. return TRUE;
  12589. }
  12590. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12591. {
  12592. char rmFileCmd[100]={0};
  12593. char FilePath[100]={0};
  12594. char ftpbuf[200];
  12595. int systemresult;
  12596. //char temp[100];
  12597. sprintf(FilePath,"/mnt/%s",filename);
  12598. if((access(FilePath,F_OK))!=-1)
  12599. {
  12600. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12601. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12602. system(rmFileCmd);
  12603. }
  12604. memset(ftpbuf, 0, sizeof(ftpbuf));
  12605. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12606. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12607. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12608. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12609. systemresult = system(ftpbuf);
  12610. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12611. if(systemresult != 0)
  12612. {
  12613. printf("wget error!\n");
  12614. return FALSE;
  12615. }
  12616. return TRUE;
  12617. }
  12618. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12619. {
  12620. char rmFileCmd[100]={0};
  12621. char FilePath[100]={0};
  12622. char ftpbuf[200];
  12623. int systemresult;
  12624. //DEBUG_INFO("filename=%s\n",filename);
  12625. //DEBUG_INFO("url=%s\n",url);
  12626. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12627. if((access(FilePath,F_OK))!=-1)
  12628. {
  12629. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12630. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12631. system(rmFileCmd);
  12632. }
  12633. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12634. if(fp == NULL)
  12635. {
  12636. DEBUG_INFO("log is NULL\n");
  12637. return FALSE;
  12638. }
  12639. else
  12640. {
  12641. fprintf(fp, "%s\n", url);
  12642. fprintf(fp, "%s\n", filename);
  12643. fclose(fp);
  12644. }
  12645. memset(ftpbuf, 0, sizeof(ftpbuf));
  12646. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12647. systemresult = system(ftpbuf);
  12648. DEBUG_INFO("systemresult = %d\n",systemresult);
  12649. if(systemresult != 0)
  12650. {
  12651. DEBUG_INFO("http upload error!\n");
  12652. return FALSE;
  12653. }
  12654. return TRUE;
  12655. }
  12656. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12657. {
  12658. struct hostent* server;
  12659. char *IPbuffer;
  12660. char ftpbuf[200];
  12661. int systemresult;
  12662. // To retrieve host information
  12663. server = gethostbyname(location);
  12664. // To convert an Internet network
  12665. // address into ASCII string
  12666. IPbuffer = inet_ntoa(*((struct in_addr*)
  12667. server->h_addr_list[0]));
  12668. memset(ftpbuf, 0, sizeof(ftpbuf));
  12669. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12670. /* format : ftpput -u username -p passwd IP target source*/
  12671. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12672. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12673. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12674. systemresult = system(ftpbuf);
  12675. DEBUG_INFO("systemresult=%d\n",systemresult);
  12676. if(systemresult != 0)
  12677. {
  12678. DEBUG_INFO("ftpput error!\n");
  12679. return FALSE;
  12680. }
  12681. return TRUE;
  12682. }
  12683. /**
  12684. * Place the contents of the specified file into a memory buffer
  12685. *
  12686. * @param[in] filename The path and name of the file to read
  12687. * @param[out] filebuffer A pointer to the contents in memory
  12688. * @return status 0 success, 1 on failure
  12689. */
  12690. int get_file_contents(const char* filename, char** outbuffer) {
  12691. FILE* file = NULL;
  12692. long filesize;
  12693. const int blocksize = 1;
  12694. size_t readsize;
  12695. char* filebuffer;
  12696. // Open the file
  12697. file = fopen(filename, "r");
  12698. if (NULL == file)
  12699. {
  12700. printf("'%s' not opened\n", filename);
  12701. exit(EXIT_FAILURE);
  12702. }
  12703. // Determine the file size
  12704. fseek(file, 0, SEEK_END);
  12705. filesize = ftell(file);
  12706. rewind (file);
  12707. // Allocate memory for the file contents
  12708. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12709. *outbuffer = filebuffer;
  12710. if (filebuffer == NULL)
  12711. {
  12712. fputs ("malloc out-of-memory", stderr);
  12713. exit(EXIT_FAILURE);
  12714. }
  12715. // Read in the file
  12716. readsize = fread(filebuffer, blocksize, filesize, file);
  12717. if (readsize != filesize)
  12718. {
  12719. fputs ("didn't read file completely",stderr);
  12720. exit(EXIT_FAILURE);
  12721. }
  12722. // Clean exit
  12723. fclose(file);
  12724. return EXIT_SUCCESS;
  12725. }
  12726. static int selectSqlCount = 0;
  12727. static int callback(void *data, int argc, char **argv, char **azColName){
  12728. int i;
  12729. //printf("%s: ", (const char*)data);
  12730. selectSqlCount = argc;
  12731. for(i = 0; i<argc; i++){
  12732. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12733. }
  12734. //printf("\n");
  12735. return 0;
  12736. }
  12737. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12738. //int i;
  12739. //printf("%s:\n", (const char*)data);
  12740. localversion = argv[5] ? atoi(argv[5]) : 0;
  12741. //printf("localversion=%d\n", localversion);
  12742. return 0;
  12743. }
  12744. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12745. //int i;
  12746. //printf("%s:\n", (const char*)data);
  12747. //idTag
  12748. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12749. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12750. //parentIdTag
  12751. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12752. //expir_date
  12753. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12754. //status
  12755. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12756. //version
  12757. idTagQuery.listVersionInt = atoi(argv[5]);
  12758. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12759. return 0;
  12760. }
  12761. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12762. {
  12763. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12764. // printf("localversion=%d\n", localversion);
  12765. return 0;
  12766. }
  12767. //=========================================
  12768. // Sqlite3 related function
  12769. //=========================================
  12770. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12771. {
  12772. for (int i = 0; i < n_columns; i++)
  12773. {
  12774. DEBUG_INFO("%s/t", col_values[i]);
  12775. }
  12776. DEBUG_INFO("/n");
  12777. return 0;
  12778. }
  12779. void OCPP_getListVerion()
  12780. {
  12781. int rc = 0;
  12782. // const char* data = "Callback function called";
  12783. char sql[100];
  12784. char zErrMsg[100];
  12785. memset(sql, 0, 100);
  12786. memset(zErrMsg, 0, 100);
  12787. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12788. /* Execute SQL statement */
  12789. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12790. if( rc != SQLITE_OK )
  12791. {
  12792. DEBUG_INFO("SQL error: %s", zErrMsg);
  12793. }
  12794. }
  12795. void OCPP_getIdTag(char idTag[])
  12796. {
  12797. int rc = 0;
  12798. // const char* data = "Callback function called";
  12799. char sql[100];
  12800. char zErrMsg[100];
  12801. memset(sql, 0, 100);
  12802. memset(zErrMsg, 0, 100);
  12803. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12804. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12805. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12806. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12807. /* Execute SQL statement */
  12808. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12809. if( rc != SQLITE_OK )
  12810. {
  12811. DEBUG_INFO("SQL error: %s", zErrMsg);
  12812. }
  12813. //return ver;
  12814. }
  12815. void OCPP_get_TableAuthlocalAllData(void)
  12816. {
  12817. int rc = 0;
  12818. char sql[100];
  12819. char zErrMsg[100];
  12820. memset(sql, 0, 100);
  12821. memset(zErrMsg, 0, 100);
  12822. sprintf(sql,"select * from ocpp_auth_local ");
  12823. /* Execute SQL statement */
  12824. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12825. if( rc != SQLITE_OK )
  12826. {
  12827. DEBUG_INFO("SQL error: %s", zErrMsg);
  12828. }
  12829. //return ver;
  12830. }
  12831. int OCPP_cleanLocalList()
  12832. {
  12833. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12834. char *errMsg = 0;
  12835. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12836. if (SQLITE_OK != rc)
  12837. {
  12838. DEBUG_INFO("%s\n",errMsg);
  12839. return FALSE;
  12840. }
  12841. return TRUE;
  12842. }
  12843. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12844. {
  12845. int isSuccess = FALSE;
  12846. int ret = 0;
  12847. //const char* data = "Callback function called";
  12848. char sql[300];
  12849. char zErrMsg[200];
  12850. memset(sql, 0, 300);
  12851. memset(zErrMsg, 0, 200);
  12852. 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);
  12853. //* Execute SQL statement */
  12854. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12855. if( ret != SQLITE_OK )
  12856. {
  12857. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12858. return isSuccess;
  12859. }
  12860. memset(sql, 0, 300);
  12861. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12862. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12863. if( ret != SQLITE_OK )
  12864. {
  12865. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12866. return isSuccess;
  12867. }
  12868. isSuccess = TRUE;
  12869. return isSuccess;
  12870. }
  12871. void OCPP_deleteIdTag(char idTag[])
  12872. {
  12873. //int ver = 0;
  12874. //int isSuccess = FALSE;
  12875. int rc = 0;
  12876. char sql[100];
  12877. char zErrMsg[100];
  12878. memset(sql, 0, 100);
  12879. memset(zErrMsg, 0, 100);
  12880. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12881. //* Execute SQL statement */
  12882. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12883. if( rc != SQLITE_OK )
  12884. {
  12885. DEBUG_INFO("SQL error: %s", zErrMsg);
  12886. }
  12887. }
  12888. int GetOcppServerURL()
  12889. {
  12890. int result = FALSE;
  12891. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12892. memset(OcppHost, 0, sizeof(OcppHost));
  12893. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12894. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12895. {
  12896. #if 1
  12897. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12898. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12899. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12900. #endif
  12901. result = TRUE;
  12902. goto End;
  12903. }
  12904. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12905. {
  12906. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12907. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12908. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12909. result = TRUE;
  12910. goto End;
  12911. }
  12912. else
  12913. {
  12914. strcpy(OcppHost,"");
  12915. }
  12916. End:
  12917. return result;
  12918. }
  12919. int GetOcppPath()
  12920. {
  12921. int result = FALSE;
  12922. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12923. {
  12924. if(OcppTempPath == NULL)
  12925. {
  12926. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12927. }
  12928. else
  12929. {
  12930. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12931. }
  12932. result = TRUE;
  12933. goto End;
  12934. }
  12935. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12936. {
  12937. if(OcppTempPath == NULL)
  12938. {
  12939. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12940. }
  12941. else
  12942. {
  12943. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12944. }
  12945. result = TRUE;
  12946. goto End;
  12947. }
  12948. else
  12949. {
  12950. strcpy(OcppPath,"");
  12951. }
  12952. End:
  12953. return result;
  12954. }
  12955. int GetOcppPort()
  12956. {
  12957. return OcppPort;
  12958. }
  12959. int GetOcppConnStatus(void)
  12960. {
  12961. return ShmOCPP16Data->OcppConnStatus;
  12962. }
  12963. void SetOcppConnStatus(uint8_t status)
  12964. {
  12965. ShmOCPP16Data->OcppConnStatus = status;
  12966. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12967. }
  12968. int GetHeartBeatWithNOResponse(void)
  12969. {
  12970. return HeartBeatWithNOResponse;
  12971. }
  12972. void SetHeartBeatWithNOResponse(void)
  12973. {
  12974. HeartBeatWithNOResponse = 0;
  12975. }
  12976. void GetStartTransactionIdTag(int gun_index)
  12977. {
  12978. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  12979. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12980. DEBUG_INFO("gun_index=%d StartTransactionIdTagTemp=%s\n",gun_index,StartTransactionIdTagTemp);
  12981. }
  12982. int GetTransactionId(int gunindex, unsigned char idTag[])
  12983. {
  12984. char ch;
  12985. FILE *fptr1;
  12986. int temptransactionId;
  12987. char str[100]={0};
  12988. temptransactionId = 0;
  12989. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12990. {
  12991. DEBUG_INFO("test 1 \n");
  12992. return temptransactionId;
  12993. }
  12994. /*------ Read the file ----------------*/
  12995. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12996. if (!fptr1)
  12997. {
  12998. DEBUG_INFO("test 2 \n");
  12999. //printf(" File not found or unable to open the input file!!\n");
  13000. return temptransactionId;
  13001. }
  13002. ch=fgetc(fptr1);
  13003. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13004. rewind(fptr1);
  13005. if(ch!=EOF)
  13006. {
  13007. // printf("%c",ch);
  13008. while (fgets(str, 100, fptr1) != NULL)
  13009. {
  13010. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13011. if(str[0]=='\0')
  13012. {
  13013. break;
  13014. }
  13015. char *revbuf[8] = {0}; //存放分割後的子字串
  13016. int num = 0;//分割後子字串的個數
  13017. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13018. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13019. {
  13020. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13021. {
  13022. temptransactionId = atoi(revbuf[2]);
  13023. break;
  13024. }
  13025. }
  13026. }
  13027. }
  13028. fclose(fptr1);
  13029. /*------- End of reading ---------------*/
  13030. return temptransactionId;
  13031. }
  13032. void SetTransactionIdZero(int transactionId)
  13033. {
  13034. char ch;
  13035. FILE *fptr1, *fptr2;
  13036. int temptransactionId = 0;
  13037. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13038. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13039. if (!fptr1)
  13040. {
  13041. //printf(" File not found or unable to open the input file!!\n");
  13042. return ;
  13043. }
  13044. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13045. if (!fptr2)
  13046. {
  13047. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13048. fclose(fptr1);
  13049. return ;
  13050. }
  13051. ch=fgetc(fptr1);
  13052. rewind(fptr1);
  13053. if(ch!=EOF)
  13054. {
  13055. // copy all contents to the temporary file except the specific line
  13056. while (fgets(str, 100, fptr1) != NULL)
  13057. {
  13058. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13059. if(str[0]=='\0')
  13060. {
  13061. break;
  13062. }
  13063. char *revbuf[8] = {0};
  13064. int num = 0;
  13065. strcpy(strtemp, str);
  13066. splitstring(str,",",revbuf,&num);
  13067. if(revbuf[2][0] != '\0')
  13068. {
  13069. temptransactionId = atoi(revbuf[2]);
  13070. if(transactionId != temptransactionId)
  13071. {
  13072. fprintf(fptr2, "%s\n", strtemp);
  13073. }
  13074. }
  13075. }
  13076. }
  13077. fclose(fptr1);
  13078. fclose(fptr2);
  13079. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13080. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13081. /*------ Read the file ----------------*/
  13082. }
  13083. int InternetDisconnect(void)
  13084. {
  13085. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13086. }
  13087. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13088. void storeTempStopTransaction(int gun_index)
  13089. {
  13090. char guid[37]={0};
  13091. int tempIndex = 0;
  13092. DEBUG_INFO("storeTempStopTransaction...\n");
  13093. memset(queuedata, 0, sizeof(queuedata));
  13094. //ENERGY_ACTIVE_IMPORT_REGISTER
  13095. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13096. if(gunType[gun_index] == 'J')
  13097. {
  13098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13099. {
  13100. tempIndex = ((gun_index==2) ? 1: 0);
  13101. }
  13102. else
  13103. {
  13104. tempIndex = gun_index;
  13105. }
  13106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13107. {
  13108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13109. {
  13110. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13111. }
  13112. }// END OF CHAdeMO_QUANTITY
  13113. }
  13114. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13115. {
  13116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13117. {
  13118. tempIndex = ((gun_index==2) ? 1: 0);
  13119. }
  13120. else
  13121. {
  13122. tempIndex = gun_index;
  13123. }
  13124. for (int index = 0; index < CCS_QUANTITY; index++)
  13125. {
  13126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13127. {
  13128. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13129. }
  13130. }// END OF CCS_QUANTITY
  13131. }
  13132. else if(gunType[gun_index] == 'G')
  13133. {
  13134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13135. {
  13136. tempIndex = ((gun_index==2) ? 1: 0);
  13137. }
  13138. else
  13139. {
  13140. tempIndex = gun_index;
  13141. }
  13142. for (int index = 0; index < GB_QUANTITY; index++)
  13143. {
  13144. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13145. {
  13146. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13147. }
  13148. }// END OF GB_QUANTITY
  13149. }
  13150. else
  13151. {
  13152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13153. {
  13154. tempIndex = 2;
  13155. }
  13156. else
  13157. {
  13158. tempIndex = gun_index;
  13159. }
  13160. for (int index = 0; index < AC_QUANTITY; index++)
  13161. {
  13162. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13163. {
  13164. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13165. }
  13166. }// END OF AC_QUANTITY
  13167. }
  13168. //Stop Transaction Time
  13169. struct timeval tmnow;
  13170. struct tm *tm;
  13171. char buf[28];//, usec_buf[6];
  13172. gettimeofday(&tmnow, NULL);
  13173. time_t t;
  13174. t = time(NULL);
  13175. /*UTC time and date*/
  13176. tm = gmtime(&t);
  13177. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13179. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13180. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13181. random_uuid(guid);
  13182. /***********************************transactionData******************************************************/
  13183. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13184. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13185. //=================================
  13186. //1. Transaction_Begin
  13187. //=================================
  13188. // Energy.Active.Export.Interval
  13189. //idx_sample=0;
  13190. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13192. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13193. 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*/]);
  13194. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13195. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13196. {
  13197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13198. }
  13199. else
  13200. {
  13201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13202. }
  13203. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13204. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13205. //=================================
  13206. //2. Transaction_End
  13207. //=================================
  13208. //2.1 Current.Export
  13209. //idx_sample=1;
  13210. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13211. if(gunType[gun_index] == 'J')
  13212. {
  13213. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13214. {
  13215. tempIndex = ((gun_index==2) ? 1: 0);
  13216. }
  13217. else
  13218. {
  13219. tempIndex = gun_index;
  13220. }
  13221. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13222. {
  13223. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13224. {
  13225. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13226. }
  13227. }// End of for CHAdeMO_QUANTITY
  13228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13229. }
  13230. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13231. {
  13232. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13233. {
  13234. tempIndex = ((gun_index==2) ? 1: 0);
  13235. }
  13236. else
  13237. {
  13238. tempIndex = gun_index;
  13239. }
  13240. for (int index = 0; index < CCS_QUANTITY; index++)
  13241. {
  13242. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13243. {
  13244. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13245. }
  13246. }// End of for CCS_QUANTITY
  13247. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13248. }
  13249. else if(gunType[gun_index] == 'G')
  13250. {
  13251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13252. {
  13253. tempIndex = ((gun_index==2) ? 1: 0);
  13254. }
  13255. else
  13256. {
  13257. tempIndex = gun_index;
  13258. }
  13259. for (int index = 0; index < GB_QUANTITY; index++)
  13260. {
  13261. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13262. {
  13263. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13264. }
  13265. }// End of for GB_QUANTITY
  13266. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13267. }
  13268. else
  13269. {
  13270. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13271. {
  13272. tempIndex = 2;
  13273. }
  13274. else
  13275. {
  13276. tempIndex = gun_index;
  13277. }
  13278. for (int index = 0; index < AC_QUANTITY; index++)
  13279. {
  13280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13281. {
  13282. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13283. }
  13284. }// End of for AC_QUANTITY
  13285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13286. }
  13287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13288. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13290. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13291. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13292. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13293. //2.2 Energy.Active.Export.Interval
  13294. //idx_sample=2;
  13295. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13296. if(gunType[gun_index] == 'J')
  13297. {
  13298. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13299. {
  13300. tempIndex = ((gun_index==2) ? 1: 0);
  13301. }
  13302. else
  13303. {
  13304. tempIndex = gun_index;
  13305. }
  13306. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13307. {
  13308. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13309. {
  13310. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13311. }
  13312. }// END OF CHAdeMO_QUANTITY
  13313. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13314. }
  13315. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13316. {
  13317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13318. {
  13319. tempIndex = ((gun_index==2) ? 1: 0);
  13320. }
  13321. else
  13322. {
  13323. tempIndex = gun_index;
  13324. }
  13325. for (int index = 0; index < CCS_QUANTITY; index++)
  13326. {
  13327. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13328. {
  13329. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13330. }
  13331. }// END OF CCS_QUANTITY
  13332. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13333. }
  13334. else if(gunType[gun_index] == 'G')
  13335. {
  13336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13337. {
  13338. tempIndex = ((gun_index==2) ? 1: 0);
  13339. }
  13340. else
  13341. {
  13342. tempIndex = gun_index;
  13343. }
  13344. for (int index = 0; index < GB_QUANTITY; index++)
  13345. {
  13346. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13347. {
  13348. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13349. }
  13350. }// END OF GB_QUANTITY
  13351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13352. }
  13353. else
  13354. {
  13355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13356. {
  13357. tempIndex = 2;
  13358. }
  13359. else
  13360. {
  13361. tempIndex = gun_index;
  13362. }
  13363. for (int index = 0; index < AC_QUANTITY; index++)
  13364. {
  13365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13366. {
  13367. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13368. }
  13369. }// END OF AC_QUANTITY
  13370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13371. }
  13372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13375. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13378. //2.3 Power.Active.Export
  13379. //idx_sample=3;
  13380. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13381. if(gunType[gun_index] == 'J')
  13382. {
  13383. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13384. {
  13385. tempIndex = ((gun_index==2) ? 1: 0);
  13386. }
  13387. else
  13388. {
  13389. tempIndex = gun_index;
  13390. }
  13391. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13392. {
  13393. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13394. {
  13395. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13396. }
  13397. } // End for CHAdeMO_QUANTITY
  13398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13399. }
  13400. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13401. {
  13402. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13403. {
  13404. tempIndex = ((gun_index==2) ? 1: 0);
  13405. }
  13406. else
  13407. {
  13408. tempIndex = gun_index;
  13409. }
  13410. for (int index = 0; index < CCS_QUANTITY; index++)
  13411. {
  13412. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13413. {
  13414. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13415. }
  13416. } // END for CCS_QUANTITY
  13417. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13418. }
  13419. else if(gunType[gun_index] == 'G')
  13420. {
  13421. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13422. {
  13423. tempIndex = ((gun_index==2) ? 1: 0);
  13424. }
  13425. else
  13426. {
  13427. tempIndex = gun_index;
  13428. }
  13429. for (int index = 0; index < GB_QUANTITY; index++)
  13430. {
  13431. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13432. {
  13433. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13434. }
  13435. }// END for GB_QUANTITY
  13436. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13437. }
  13438. else
  13439. {
  13440. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13441. {
  13442. tempIndex = 2;
  13443. }
  13444. else
  13445. {
  13446. tempIndex = gun_index;
  13447. }
  13448. for (int index = 0; index < AC_QUANTITY; index++)
  13449. {
  13450. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13451. {
  13452. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13453. }
  13454. } // END for AC_QUANTITY
  13455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13456. }
  13457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13458. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13460. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13463. //2.4 Voltage
  13464. //idx_sample=4;
  13465. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13466. if(gunType[gun_index] == 'J')
  13467. {
  13468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13469. {
  13470. tempIndex = ((gun_index==2) ? 1: 0);
  13471. }
  13472. else
  13473. {
  13474. tempIndex = gun_index;
  13475. }
  13476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13477. {
  13478. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13479. {
  13480. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13481. }
  13482. } // END OF FOR CHAdeMO_QUANTITY
  13483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13484. }
  13485. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13486. {
  13487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13488. {
  13489. tempIndex = ((gun_index==2) ? 1: 0);
  13490. }
  13491. else
  13492. {
  13493. tempIndex = gun_index;
  13494. }
  13495. for (int index = 0; index < CCS_QUANTITY; index++)
  13496. {
  13497. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13498. {
  13499. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13500. }
  13501. } // END OF FOR CCS_QUANTITY
  13502. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13503. }
  13504. else if(gunType[gun_index] == 'G')
  13505. {
  13506. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13507. {
  13508. tempIndex = ((gun_index==2) ? 1: 0);
  13509. }
  13510. else
  13511. {
  13512. tempIndex = gun_index;
  13513. }
  13514. for (int index = 0; index < GB_QUANTITY; index++)
  13515. {
  13516. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13517. {
  13518. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13519. }
  13520. } // END OF FOR GB_QUANTITY
  13521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13522. }
  13523. else
  13524. {
  13525. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13526. {
  13527. tempIndex = 2;
  13528. }
  13529. else
  13530. {
  13531. tempIndex = gun_index;
  13532. }
  13533. for (int index = 0; index < AC_QUANTITY; index++)
  13534. {
  13535. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13536. {
  13537. 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
  13538. }
  13539. } // END OF FOR AC_QUANTITY
  13540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13541. }
  13542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13545. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13548. //2.5 SoC
  13549. //idx_sample=5;
  13550. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13551. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13552. {
  13553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13554. {
  13555. tempIndex = ((gun_index==2) ? 1: 0);
  13556. }
  13557. else
  13558. {
  13559. tempIndex = gun_index;
  13560. }
  13561. if(gunType[gun_index] == 'J')
  13562. {
  13563. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13564. {
  13565. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13566. {
  13567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13568. }
  13569. }
  13570. }
  13571. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13572. {
  13573. for (int index = 0; index < CCS_QUANTITY; index++)
  13574. {
  13575. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13576. {
  13577. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13578. }
  13579. }
  13580. }
  13581. else if(gunType[gun_index] == 'G')
  13582. {
  13583. for (int index = 0; index < GB_QUANTITY; index++)
  13584. {
  13585. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13586. {
  13587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13588. }
  13589. }
  13590. }
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13597. } // END FOR DC CASE
  13598. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13599. {
  13600. sprintf(queuedata,"%d,[%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\"}]}]}]"
  13601. ,gun_index + 1
  13602. ,MESSAGE_TYPE_CALL
  13603. ,guid
  13604. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13605. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13606. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13607. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13608. ,"PowerLoss"
  13609. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13610. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13611. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13612. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13613. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13614. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13615. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13616. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13617. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13618. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13619. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13620. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13621. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13622. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13623. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13624. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13625. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13626. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13627. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13628. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13629. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13630. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13631. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13632. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13633. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13634. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13635. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13636. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13637. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13638. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13639. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13640. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13641. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13642. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13643. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13644. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13645. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13646. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13647. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13648. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13649. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13650. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13651. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13652. );
  13653. }
  13654. else
  13655. {
  13656. sprintf(queuedata,"%d,[%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\"}]}]}]"
  13657. ,gun_index + 1
  13658. ,MESSAGE_TYPE_CALL
  13659. ,guid
  13660. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13661. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13662. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13663. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13664. ,"PowerLoss"
  13665. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13701. );
  13702. }
  13703. // Check File "TempStopTransaction" Exist
  13704. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13705. {
  13706. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13707. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13708. }
  13709. else
  13710. {
  13711. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13712. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13713. if(log == NULL)
  13714. {
  13715. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13716. return ;
  13717. }
  13718. else
  13719. {
  13720. fclose(log);
  13721. }
  13722. }
  13723. //Add TempStopTransaction | Update TempStopTransaction
  13724. // open file for writing
  13725. FILE *outfile;
  13726. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13727. //DEBUG_INFO("data = %s\n", queuedata);
  13728. fputs(queuedata, outfile);
  13729. fputs("\n", outfile);
  13730. fclose (outfile);
  13731. }
  13732. void checkTempStopTransaction(int gun_index)
  13733. {
  13734. FILE *fptr1;
  13735. char ch;
  13736. char str[1200]={0};
  13737. char guid[37]={0};
  13738. char tempdata[65]={0};
  13739. char connectorStr[2]={0};
  13740. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13741. //TempStopTransaction格式: 槍號,StopTransaction封包
  13742. if (!fptr1)
  13743. {
  13744. //printf(" File not found or unable to open the input file!!\n");
  13745. return ;
  13746. }
  13747. ch=fgetc(fptr1);
  13748. //printf(" Now the content of the file %s is : \n",fname);
  13749. rewind(fptr1);
  13750. if(ch!=EOF)
  13751. {
  13752. // copy all contents to the temporary file except the specific line
  13753. while (fgets(str, 1200, fptr1) != NULL)
  13754. {
  13755. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13756. if(str[0]=='\0')
  13757. {
  13758. break;
  13759. }
  13760. //TempStopTransaction格式: 槍號,StopTransaction封包
  13761. strncpy(connectorStr, str, 1);
  13762. if(atoi(connectorStr) != (gun_index+1))
  13763. {
  13764. DEBUG_INFO("atoi(connectorStr)=%d\n",atoi(connectorStr));
  13765. return ;
  13766. }
  13767. //random_uuid(guid);
  13768. strncpy(guid, str+6, 36); //copy guid
  13769. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13770. if(hashmap_operation(0, guid, tempdata) == 1)
  13771. {
  13772. DEBUG_INFO("StopTransaction mapitem pass\n");
  13773. }
  13774. queue_operation(4, guid, str);//addq(guid, queuedata); ---> remove temporally
  13775. memset(str,0,sizeof str);
  13776. }
  13777. }
  13778. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13779. fclose(fptr1);
  13780. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13781. }
  13782. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13783. {
  13784. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13785. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13786. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13787. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13788. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13789. }
  13790. int GetWebSocketPingInterval(void)
  13791. {
  13792. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13793. }
  13794. int GetServerSign(void)
  13795. {
  13796. return server_sign;
  13797. }
  13798. void SetServerSign(int value)
  13799. {
  13800. server_sign = value;
  13801. }
  13802. int GetBootNotificationInterval(void)
  13803. {
  13804. return BootNotificationInterval;
  13805. }
  13806. int GetInternetConn(void)
  13807. {
  13808. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13809. }
  13810. void InitialSystemValue(void)
  13811. {
  13812. int connectorIndex = 0;
  13813. //int valueASCII = 0;
  13814. server_cycle_Status = 120;
  13815. gunTotalNumber=0;
  13816. SystemInitial = 0;
  13817. localversion=0;
  13818. BootNotificationInterval = 0;
  13819. authorizeRetryTimes = 0;
  13820. GunStatusInterval = 10;
  13821. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13822. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13823. //Hear Beat
  13824. HeartBeatWithNOResponse = 0;
  13825. HeartBeatCountPerHour = 0;
  13826. HeartBeatWaitTime = 10;
  13827. FirstHeartBeat = 0;
  13828. FirmwareStatusNotificationStatus = 3; // Idle
  13829. DiagnosticsStatusNotificationStatus = 0; // Idle
  13830. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  13831. memset(statusModeChage, 0, sizeof(statusModeChage));
  13832. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13833. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13834. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13835. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13836. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13837. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13838. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13839. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13840. memset(gunType, 0, sizeof(gunType));
  13841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13842. {
  13843. //check connector / socket type (index: 8, 9, 10)
  13844. for(int index=7; index <10 ; index++)
  13845. {
  13846. if(index != 8)
  13847. {
  13848. // DC Connector
  13849. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13850. {
  13851. SystemInitial = SystemInitial + 1;
  13852. gunTotalNumber = gunTotalNumber + 1;
  13853. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13854. connectorIndex = connectorIndex + 1;
  13855. }
  13856. }
  13857. else
  13858. {
  13859. // AC Connector
  13860. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13861. {
  13862. SystemInitial = SystemInitial + 1;
  13863. gunTotalNumber = gunTotalNumber + 1;
  13864. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13865. connectorIndex = connectorIndex + 1;
  13866. }
  13867. }
  13868. }
  13869. //DEBUG_INFO("DC ...\n");
  13870. }
  13871. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13872. {
  13873. //check connector / socket type (index: 8, 9, 10)
  13874. for(int index=7; index <10 ; index++)
  13875. {
  13876. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13877. {
  13878. SystemInitial = SystemInitial + 1;
  13879. gunTotalNumber = gunTotalNumber + 1;
  13880. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13881. connectorIndex = connectorIndex + 1;
  13882. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13883. }
  13884. }
  13885. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  13886. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  13887. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  13888. //DEBUG_INFO("AC ...\n");
  13889. }
  13890. //Status && ConnectorPlugIn Setting
  13891. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13892. {
  13893. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13894. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13895. }
  13896. for (int index = 0; index < CCS_QUANTITY; index++)
  13897. {
  13898. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13899. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13900. }
  13901. for (int index = 0; index < GB_QUANTITY; index++)
  13902. {
  13903. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13904. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13905. }
  13906. for (int index = 0; index < AC_QUANTITY; index++)
  13907. {
  13908. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13909. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13910. }
  13911. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13912. {
  13913. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13914. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13915. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13916. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13917. }
  13918. // Charger PRE_SYS_MODE
  13919. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13920. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13921. clientTime.Heartbeat=time((time_t*)NULL);
  13922. sleep(1);
  13923. }
  13924. void LWS_Send(char * str)
  13925. {
  13926. //=====================================================
  13927. // Check InternetConn 0: disconnected, 1: connected
  13928. //====================================================
  13929. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13930. {
  13931. DEBUG_INFO("\n offline now !!!\n");
  13932. return;
  13933. }
  13934. pthread_mutex_lock(&lock);
  13935. memset(SendBuffer, 0, SendBufLen);
  13936. sprintf((char *)SendBuffer, "%s", str);
  13937. pthread_mutex_unlock(&lock);
  13938. lws_callback_on_writable(wsi_client);
  13939. lws_service(context, 100);//timeout_ms
  13940. }