MessageHandler.c 628 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181
  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_send = 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 struct Charger_Info Charger;
  108. extern sqlite3 *db;
  109. int TransactionMessageAttemptsGet(void);
  110. int TransactionMessageRetryIntervalGet(void);
  111. int GetOcppConnStatus(void);
  112. void SetOcppConnStatus(uint8_t status);
  113. int setKeyValue(char *key, char *value);
  114. void OCPP_get_TableAuthlocalAllData(void);
  115. void processUnkownKey(void);
  116. struct StructOCPPMeterValue
  117. {
  118. unsigned char TimeStamp[28];
  119. struct StructSampledValue SampledValue[10];
  120. };
  121. struct ClientTime
  122. {
  123. unsigned int Heartbeat;
  124. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  125. unsigned int StartTransaction;
  126. unsigned int StopTransaction;
  127. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }clientTime;
  129. typedef union
  130. {
  131. //Operations Initiated by Central System
  132. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  133. struct
  134. {
  135. //CsMsgValue[0]
  136. unsigned char StatusNotificationReq :1; //bit 0,
  137. unsigned char StatusNotificationConf :1; //bit 0,
  138. unsigned char :6; //bit 2~7
  139. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  140. }CpinitiateMsg;
  141. CpinitiateMsg cpinitateMsg;
  142. //==========================================
  143. // Init all Enumeration & Mapping String
  144. //==========================================
  145. /*ChargePointErrorCode*/
  146. typedef enum {
  147. ConnectorLockFailure,
  148. EVCommunicationError,
  149. GroundFailure,
  150. HighTemperature,
  151. InternalError,
  152. LocalListConflict,
  153. NoError,
  154. OtherError,
  155. OverCurrentFailure,
  156. OverVoltage,
  157. PowerMeterFailure,
  158. PowerSwitchFailure,
  159. ReaderFailure,
  160. ResetFailure,
  161. UnderVoltage,
  162. WeakSignal
  163. } ChargePointErrorCode;
  164. #if 0
  165. static char *ChargePointErrorCodeStr[] = {
  166. MACROSTR(ConnectorLockFailure),
  167. MACROSTR(EVCommunicationError),
  168. MACROSTR(GroundFailure),
  169. MACROSTR(HighTemperature),
  170. MACROSTR(InternalError),
  171. MACROSTR(LocalListConflict),
  172. MACROSTR(NoError),
  173. MACROSTR(OtherError),
  174. MACROSTR(OverCurrentFailure),
  175. MACROSTR(OverVoltage),
  176. MACROSTR(PowerMeterFailure),
  177. MACROSTR(PowerSwitchFailure),
  178. MACROSTR(ReaderFailure),
  179. MACROSTR(ResetFailure),
  180. MACROSTR(UnderVoltage),
  181. MACROSTR(WeakSignal)
  182. };
  183. #endif
  184. /*ChargePointStatus*/
  185. typedef enum {
  186. Available =0,
  187. Preparing,
  188. Charging,
  189. SuspendedEVSE,
  190. SuspendedEV,
  191. Finishing,
  192. Reserved,
  193. Unavailable,
  194. Faulted
  195. } ChargePointStatus;
  196. static char * ChargePointStatusStr[] = {
  197. MACROSTR(Available),
  198. MACROSTR(Preparing),
  199. MACROSTR(Charging),
  200. MACROSTR(SuspendedEVSE),
  201. MACROSTR(SuspendedEV),
  202. MACROSTR(Finishing),
  203. MACROSTR(Reserved),
  204. MACROSTR(Unavailable),
  205. MACROSTR(Faulted)
  206. };
  207. /*AvailabilityType*/
  208. typedef enum {
  209. RegistrationStatus_Accepted,
  210. RegistrationStatus_Pending,
  211. RegistrationStatus_Rejected
  212. } RegistrationStatus;
  213. static char *RegistrationStatusStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(Pending),
  216. MACROSTR(Rejected)
  217. };
  218. /*AvailabilityType*/
  219. typedef enum {
  220. Inoperative,
  221. Operative
  222. } AvailabilityType;
  223. static char *AvailabilityTypeStr[] = {
  224. MACROSTR(Inoperative),
  225. MACROSTR(Operative)
  226. };
  227. /*AvailabilityStatus*/
  228. typedef enum {
  229. Accepted,
  230. Rejected,
  231. Scheduled
  232. } AvailabilityStatus;
  233. static char *AvailabilityStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected),
  236. MACROSTR(Scheduled)
  237. };
  238. /*ConfigurationStatus*/
  239. typedef enum {
  240. ConfigurationStatus_Accepted,
  241. ConfigurationStatus_Rejected,
  242. RebootRequired,
  243. NotSupported
  244. } ConfigurationStatus;
  245. static char *ConfigurationStatusStr[] = {
  246. MACROSTR(Accepted),
  247. MACROSTR(Rejected),
  248. MACROSTR(RebootRequired),
  249. MACROSTR(NotSupported)
  250. };
  251. /*ClearCacheStatus*/
  252. typedef enum {
  253. ClearCacheStatus_Accepted,
  254. ClearCacheStatus_Rejected
  255. } ClearCacheStatus;
  256. static char *ClearCacheStatusStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected)
  259. };
  260. /*ChargingProfilePurposeType*/
  261. typedef enum {
  262. ChargePointMaxProfile,
  263. TxDefaultProfile,
  264. TxProfile
  265. } ChargingProfilePurposeType;
  266. static char *ChargingProfilePurposeTypeStr[] = {
  267. MACROSTR(ChargePointMaxProfile),
  268. MACROSTR(TxDefaultProfile),
  269. MACROSTR(TxProfile)
  270. };
  271. /*ChargingProfileStatus*/
  272. typedef enum {
  273. ChargingProfileStatus_Accepted,
  274. ChargingProfileStatus_Rejected,
  275. ChargingProfileStatus_NotSupported
  276. } ChargingProfileStatus;
  277. static char *ChargingProfileStatusStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(Rejected),
  280. MACROSTR(NotSupported)
  281. };
  282. /*ClearChargingProfileStatus*/
  283. typedef enum {
  284. ClearChargingProfileStatus_Accepted,
  285. ClearChargingProfileStatus_Unknown
  286. } ClearChargingProfileStatus;
  287. static char *ClearChargingProfileStatusStr[] = {
  288. MACROSTR(Accepted),
  289. MACROSTR(Unknown)
  290. };
  291. /*GetCompositeScheduleStatus*/
  292. typedef enum {
  293. GetCompositeScheduleStatus_Accepted,
  294. GetCompositeScheduleStatus_Rejected
  295. } GetCompositeScheduleStatus;
  296. static char *GetCompositeScheduleStatusStr[] = {
  297. MACROSTR(Accepted),
  298. MACROSTR(Rejected)
  299. };
  300. /*ChargingRateUnitType*/
  301. typedef enum {
  302. ChargingRateUnitType_W,
  303. ChargingRateUnitType_A
  304. } ChargingRateUnitType;
  305. /*AuthorizationStatus*/
  306. typedef enum {
  307. AuthorizationStatus_Accepted ,
  308. AuthorizationStatus_Blocked ,
  309. AuthorizationStatus_Expired ,
  310. AuthorizationStatus_Invalid ,
  311. AuthorizationStatus_ConcurrentTx
  312. } AuthorizationStatus;
  313. /*UpdateType*/
  314. typedef enum {
  315. Differential ,
  316. Full
  317. } UpdateType;
  318. static char *UpdateTypeStr[] = {
  319. MACROSTR(Differential),
  320. MACROSTR(Full)
  321. };
  322. /*UpdateStatus*/
  323. typedef enum {
  324. UpdateStatus_Accepted ,
  325. UpdateStatus_Failed ,
  326. UpdateStatus_NotSupported ,
  327. UpdateStatus_VersionMismatch
  328. } UpdateStatus;
  329. static char *UpdateStatusStr[] = {
  330. MACROSTR(Accepted),
  331. MACROSTR(Failed),
  332. MACROSTR(NotSupported),
  333. MACROSTR(VersionMismatch)
  334. };
  335. /*RemoteStartStopStatus*/
  336. typedef enum {
  337. RemoteStartStopStatus_Accepted,
  338. RemoteStartStopStatus_Rejected
  339. } RemoteStartStopStatus;
  340. static char *RemoteStartStopStatusStr[] = {
  341. MACROSTR(Accepted),
  342. MACROSTR(Rejected)
  343. };
  344. /*ReservationStatus*/
  345. typedef enum {
  346. ReservationStatus_Accepted,
  347. ReservationStatus_Faulted,
  348. ReservationStatus_Occupied,
  349. ReservationStatus_Rejected,
  350. ReservationStatus_Unavailable
  351. } ReservationStatus;
  352. static char *ReservationStatusStr[] = {
  353. MACROSTR(Accepted),
  354. MACROSTR(Faulted),
  355. MACROSTR(Occupied),
  356. MACROSTR(Rejected),
  357. MACROSTR(Unavailable)
  358. };
  359. /*ResetType*/
  360. typedef enum {
  361. Hard,
  362. Soft
  363. } ResetType;
  364. static char *ResetTypeStr[] = {
  365. MACROSTR(Hard),
  366. MACROSTR(Soft)
  367. };
  368. /*ResetStatus*/
  369. typedef enum {
  370. ResetStatus_Accepted,
  371. ResetStatus_Rejected
  372. } ResetStatus;
  373. static char *ResetStatusStr[] = {
  374. MACROSTR(Accepted),
  375. MACROSTR(Rejected)
  376. };
  377. /*DiagnosticsStatus*/
  378. typedef enum {
  379. DiagnosticsStatus_Idle,
  380. DiagnosticsStatus_Uploaded,
  381. DiagnosticsStatus_UploadFailed,
  382. DiagnosticsStatus_Uploading
  383. } DiagnosticsStatus;
  384. static char * DiagnosticsStatusStr[] = {
  385. MACROSTR(Idle),
  386. MACROSTR(Uploaded),
  387. MACROSTR(UploadFailed),
  388. MACROSTR(Uploading)
  389. };
  390. /*FirmwareStatus*/
  391. typedef enum {
  392. FirmwareStatus_Downloaded,
  393. FirmwareStatus_DownloadFailed,
  394. FirmwareStatus_Downloading,
  395. FirmwareStatus_Idle,
  396. FirmwareStatus_InstallationFailed,
  397. FirmwareStatus_Installing,
  398. FirmwareStatus_Installed
  399. } FirmwareStatus;
  400. static char * FirmwareStatusStr[] = {
  401. MACROSTR(Downloaded),
  402. MACROSTR(DownloadFailed),
  403. MACROSTR(Downloading),
  404. MACROSTR(Idle),
  405. MACROSTR(InstallationFailed),
  406. MACROSTR(Installing),
  407. MACROSTR(Installed)
  408. };
  409. /*MessageTrigger*/
  410. typedef enum {
  411. BootNotification,
  412. DiagnosticsStatusNotification,
  413. FirmwareStatusNotification,
  414. Heartbeat,
  415. MeterValues,
  416. StatusNotification
  417. } MessageTrigger;
  418. static char * MessageTriggerStr[] = {
  419. MACROSTR(BootNotification),
  420. MACROSTR(DiagnosticsStatusNotification),
  421. MACROSTR(FirmwareStatusNotification),
  422. MACROSTR(Heartbeat),
  423. MACROSTR(MeterValues),
  424. MACROSTR(StatusNotification)
  425. };
  426. /*TriggerMessageStatus*/
  427. typedef enum {
  428. TriggerMessageStatus_Accepted ,
  429. TriggerMessageStatus_Rejected ,
  430. TriggerMessageStatus_NotImplemented
  431. } TriggerMessageStatus;
  432. static char * TriggerMessageStatusStr[] = {
  433. MACROSTR(Accepted),
  434. MACROSTR(Rejected),
  435. MACROSTR(NotImplemented)
  436. };
  437. /*UnlockStatus*/
  438. typedef enum {
  439. Unlocked,
  440. UnlockFailed,
  441. UnlockStatus_NotSupported
  442. } UnlockStatus;
  443. static char * UnlockStatusStr[] = {
  444. MACROSTR(Unlocked),
  445. MACROSTR(UnlockFailed),
  446. MACROSTR(NotSupported)
  447. };
  448. /*StopTransactionReason*/
  449. typedef enum {
  450. EmergencyStop,
  451. EVDisconnected,
  452. HardReset,
  453. Local,
  454. Other,
  455. PowerLoss,
  456. Reboot,
  457. Remote,
  458. SoftReset,
  459. UnlockCommand,
  460. DeAuthorized
  461. } StopTransactionReason;
  462. #if 0
  463. static char * StopTransactionReasonStr[] = {
  464. MACROSTR(EmergencyStop),
  465. MACROSTR(EVDisconnected),
  466. MACROSTR(HardReset),
  467. MACROSTR(Local),
  468. MACROSTR(Other),
  469. MACROSTR(PowerLoss),
  470. MACROSTR(Reboot),
  471. MACROSTR(Remote),
  472. MACROSTR(SoftReset),
  473. MACROSTR(UnlockCommand),
  474. MACROSTR(DeAuthorized)
  475. };
  476. #endif
  477. /*CancelReservationStatus*/
  478. typedef enum {
  479. CancelReservationStatus_Accepted,
  480. CancelReservationStatus_Rejected
  481. } CancelReservationStatus;
  482. static char * CancelReservationStatusStr[] = {
  483. MACROSTR(Accepted),
  484. MACROSTR(Rejected)
  485. };
  486. /*ReadingContext*/
  487. typedef enum {
  488. ReadingContext_Interruption_Begin,
  489. ReadingContext_Interruption_End,
  490. ReadingContext_Other,
  491. ReadingContext_Sample_Clock,
  492. ReadingContext_Sample_Periodic ,
  493. ReadingContext_Transaction_Begin ,
  494. ReadingContext_Transaction_End,
  495. ReadingContext_Trigger
  496. } ReadingContext;
  497. static char * ReadingContextStr[] = {
  498. MACROSTR(Interruption.Begin),
  499. MACROSTR(Interruption.End),
  500. MACROSTR(Other),
  501. MACROSTR(Sample.Clock),
  502. MACROSTR(Sample.Periodic),
  503. MACROSTR(Transaction.Begin),
  504. MACROSTR(Transaction.End),
  505. MACROSTR(Trigger)
  506. };
  507. /*ValueFormat*/
  508. typedef enum {
  509. Raw,
  510. SignedData
  511. } ValueFormat;
  512. static char * ValueFormatStr[] = {
  513. MACROSTR(Raw),
  514. MACROSTR(SignedData)
  515. };
  516. /*Measurand*/
  517. typedef enum {
  518. Current_Export ,
  519. Current_Import,
  520. Current_Offered,
  521. Energy_Active_Export_Register,
  522. Energy_Active_Import_Register,
  523. Energy_Reactive_Export_Register,
  524. Energy_Reactive_Import_Register,
  525. Energy_Active_Export_Interval,
  526. Energy_Active_Import_Interval,
  527. Energy_Reactive_Export_Interval,
  528. Energy_Reactive_Import_Interval,
  529. Frequency,
  530. Power_Active_Export ,
  531. Power_Active_Import,
  532. Power_Factor,
  533. Power_Offered,
  534. Power_Reactive_Export,
  535. Power_Reactive_Import,
  536. RPM,
  537. SoC,
  538. Temperature ,
  539. Voltage
  540. } Measurand;
  541. static char * MeasurandStr[] = {
  542. MACROSTR(Current.Export),
  543. MACROSTR(Current.Import),
  544. MACROSTR(Current.Offered),
  545. MACROSTR(Energy.Active.Export.Register),
  546. MACROSTR(Energy.Active.Import.Register),
  547. MACROSTR(Energy.Reactive.Export.Register),
  548. MACROSTR(Energy.Reactive.Import.Register),
  549. MACROSTR(Energy.Active.Export.Interval),
  550. MACROSTR(Energy.Active.Import.Interval),
  551. MACROSTR(Energy.Reactive.Export.Interval),
  552. MACROSTR(Energy.Reactive.Import.Interval),
  553. MACROSTR(Frequency),
  554. MACROSTR(Power.Active.Export),
  555. MACROSTR(Power.Active.Import),
  556. MACROSTR(Power.Factor),
  557. MACROSTR(Power.Offered),
  558. MACROSTR(Power.Reactive.ExportMACROSTR),
  559. MACROSTR(Power.Reactive.Import),
  560. MACROSTR(RPM),
  561. MACROSTR(SoC),
  562. MACROSTR(Temperature),
  563. MACROSTR(Voltage)
  564. };
  565. /*Location*/
  566. typedef enum {
  567. Location_Body,
  568. Location_Cable,
  569. Location_EV,
  570. Location_Inlet ,
  571. Location_Outlet
  572. } Location;
  573. static char * LocationStr[] = {
  574. MACROSTR(Body),
  575. MACROSTR(Cable),
  576. MACROSTR(EV),
  577. MACROSTR(Inlet),
  578. MACROSTR(Outlet)
  579. };
  580. /*Phase*/
  581. typedef enum {
  582. L1,
  583. L2,
  584. L3,
  585. N,
  586. L1_N,
  587. L2_N,
  588. L3_N,
  589. L1_L2,
  590. L2_L3,
  591. L3_L1
  592. } Phase;
  593. static char * PhaseStr[] = {
  594. MACROSTR(L1),
  595. MACROSTR(L2),
  596. MACROSTR(L3),
  597. MACROSTR(N),
  598. MACROSTR(L1-N),
  599. MACROSTR(L2-N),
  600. MACROSTR(L3-N),
  601. MACROSTR(L1-L2),
  602. MACROSTR(L2-L3),
  603. MACROSTR(L3-L1)
  604. };
  605. /*UnitOfMeasure*/
  606. typedef enum {
  607. UnitOfMeasure_Wh,
  608. UnitOfMeasure_kWh ,
  609. UnitOfMeasure_varh ,
  610. UnitOfMeasure_kvarh ,
  611. UnitOfMeasure_W ,
  612. UnitOfMeasure_kW ,
  613. UnitOfMeasure_VA ,
  614. UnitOfMeasure_kVA ,
  615. UnitOfMeasure_var ,
  616. UnitOfMeasure_kvar ,
  617. UnitOfMeasure_A ,
  618. UnitOfMeasure_V ,
  619. UnitOfMeasure_Celsius ,
  620. UnitOfMeasure_Fahrenheit ,
  621. UnitOfMeasure_K ,
  622. UnitOfMeasure_Percent
  623. } UnitOfMeasure;
  624. static char * UnitOfMeasureStr[] = {
  625. MACROSTR(Wh),
  626. MACROSTR(kWh),
  627. MACROSTR(varh),
  628. MACROSTR(kvarh),
  629. MACROSTR(W),
  630. MACROSTR(kW),
  631. MACROSTR(VA),
  632. MACROSTR(kVA),
  633. MACROSTR(var),
  634. MACROSTR(kvar),
  635. MACROSTR(A),
  636. MACROSTR(V),
  637. MACROSTR(Celsius),
  638. MACROSTR(Fahrenheit),
  639. MACROSTR(K),
  640. MACROSTR(Percent)
  641. };
  642. enum LocalAuthListManagementProfile{
  643. LocalAuthListEnabled=0,
  644. LocalAuthListMaxLength,
  645. SendLocalListMaxLength,
  646. _LocalAuthListManagementProfile_CNT
  647. };
  648. enum ReservationProfile{
  649. ReserveConnectorZeroSupported
  650. };
  651. enum SmartChargingProfile{
  652. ChargeProfileMaxStackLevel,
  653. ChargingScheduleAllowedChargingRateUnit,
  654. ChargingScheduleMaxPeriods,
  655. ConnectorSwitch3to1PhaseSupported,
  656. MaxChargingProfilesInstalled
  657. };
  658. enum ChargerSystemStatus{
  659. ChargerSystemStatus_Booting,
  660. ChargerSystemStatus_Idle,
  661. ChargerSystemStatus_Authorizing,
  662. ChargerSystemStatus_Preparing,
  663. ChargerSystemStatus_Charging,
  664. ChargerSystemStatus_Terminating,
  665. ChargerSystemStatus_Alarm,
  666. ChargerSystemStatus_Fault
  667. };
  668. enum GetConfigurationKey {
  669. GetConfiguration_AllowOfflineTxForUnknownId=0,
  670. GetConfiguration_AuthorizationCacheEnabled,
  671. GetConfiguration_AuthorizeRemoteTxRequests,
  672. GetConfiguration_BlinkRepeat,
  673. GetConfiguration_ClockAlignedDataInterval,
  674. GetConfiguration_ConnectionTimeOut,
  675. GetConfiguration_GetConfigurationMaxKeys,
  676. GetConfiguration_HeartbeatInterval,
  677. GetConfiguration_LightIntensity,
  678. GetConfiguration_LocalAuthorizeOffline,
  679. GetConfiguration_LocalPreAuthorize,
  680. GetConfiguration_MaxEnergyOnInvalidId,
  681. GetConfiguration_MeterValuesAlignedData,
  682. GetConfiguration_MeterValuesAlignedDataMaxLength,
  683. GetConfiguration_MeterValuesSampledData,
  684. GetConfiguration_MeterValuesSampledDataMaxLength,
  685. GetConfiguration_MeterValueSampleInterval,
  686. GetConfiguration_MinimumStatusDuration,
  687. GetConfiguration_NumberOfConnectors,
  688. GetConfiguration_ResetRetries,
  689. GetConfiguration_ConnectorPhaseRotation,
  690. GetConfiguration_ConnectorPhaseRotationMaxLength,
  691. GetConfiguration_StopTransactionOnEVSideDisconnect,
  692. GetConfiguration_StopTransactionOnInvalidId,
  693. GetConfiguration_StopTxnAlignedData,
  694. GetConfiguration_StopTxnAlignedDataMaxLength,
  695. GetConfiguration_StopTxnSampledData,
  696. GetConfiguration_StopTxnSampledDataMaxLength,
  697. GetConfiguration_SupportedFeatureProfiles,
  698. GetConfiguration_SupportedFeatureProfilesMaxLength,
  699. GetConfiguration_TransactionMessageAttempts,
  700. GetConfiguration_TransactionMessageRetryInterval,
  701. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  702. GetConfiguration_WebSocketPingInterval,
  703. GetConfiguration_LocalAuthListEnabled,
  704. GetConfiguration_LocalAuthListMaxLength,
  705. GetConfiguration_SendLocalListMaxLength,
  706. GetConfiguration_ReserveConnectorZeroSupported,
  707. GetConfiguration_ChargeProfileMaxStackLevel,
  708. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  709. GetConfiguration_ChargingScheduleMaxPeriods,
  710. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  711. GetConfiguration_MaxChargingProfilesInstalled,
  712. };
  713. //GetConfiguration Array
  714. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  715. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  717. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  718. //==========================================
  719. // Check time passed since today
  720. //==========================================
  721. long long DiffTimebWithNow(struct timeb ST)
  722. {
  723. //return milli-second
  724. struct timeb ET;
  725. long long StartTime,StopTime;
  726. ftime(&ET);
  727. StartTime=(long long)ST.time;
  728. StopTime=(long long)ET.time;
  729. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  730. }
  731. int getTimePassSinceToday()
  732. {
  733. int result = -1;
  734. time_t t;
  735. struct tm *tmStartToday;
  736. struct timeb tbStartToday;
  737. t=time(NULL);
  738. tmStartToday=localtime(&t);
  739. tmStartToday->tm_hour = 0;
  740. tmStartToday->tm_min = 0;
  741. tmStartToday->tm_sec = 0;
  742. tbStartToday.time = mktime(tmStartToday);
  743. result = DiffTimebWithNow(tbStartToday)/1000;
  744. return result;
  745. }
  746. //==========================================
  747. // GetCompositeSchedule logic related function
  748. //==========================================
  749. int DiffTimebSec(struct timeb ST, struct timeb ET)
  750. {
  751. //return milli-second
  752. unsigned int StartTime,StopTime;
  753. StartTime=(unsigned int)ST.time;
  754. StopTime=(unsigned int)ET.time;
  755. return (StopTime-StartTime);
  756. }
  757. int DiffTimebWithNowSec(struct timeb ST)
  758. {
  759. //return milli-second
  760. struct timeb ET;
  761. unsigned int StartTime,StopTime;
  762. ftime(&ET);
  763. StartTime=(unsigned int)ST.time;
  764. StopTime=(unsigned int)ET.time;
  765. return (StopTime-StartTime);
  766. }
  767. int getStartStop(uint8_t *start, uint8_t *stop)
  768. {
  769. int result = -1;
  770. struct tm tmStart;
  771. struct timeb tbStart;
  772. struct tm tmStop;
  773. struct timeb tbStop;
  774. 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) &&
  775. (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))
  776. {
  777. tmStart.tm_year -= 1900;
  778. tmStart.tm_mon -= 1;
  779. tbStart.time = mktime(&tmStart);
  780. tbStart.millitm = 0;
  781. tmStop.tm_year -= 1900;
  782. tmStop.tm_mon -= 1;
  783. tbStop.time = mktime(&tmStop);
  784. tbStop.millitm = 0;
  785. result = DiffTimebSec(tbStart, tbStop);
  786. }
  787. else
  788. {
  789. DEBUG_WARN("Start or stop date parsing error.\r\n");
  790. }
  791. return result;
  792. }
  793. int getStartSinceToday(uint8_t *stop)
  794. {
  795. int result = -1;
  796. time_t t;
  797. struct tm *tmStartToday;
  798. struct timeb tbStartToday;
  799. struct tm tmStop;
  800. struct timeb tbStop;
  801. 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))
  802. {
  803. t=time(NULL);
  804. tmStartToday=localtime(&t);
  805. tmStartToday->tm_hour = 0;
  806. tmStartToday->tm_min = 0;
  807. tmStartToday->tm_sec = 0;
  808. tbStartToday.time = mktime(tmStartToday);
  809. tmStop.tm_year -= 1900;
  810. tmStop.tm_mon -= 1;
  811. tbStop.time = mktime(&tmStop);
  812. tbStop.millitm = 0;
  813. result = DiffTimebSec(tbStartToday, tbStop);
  814. }
  815. return result;
  816. }
  817. int getStartSinceWeek(uint8_t *stop)
  818. {
  819. int result = -1;
  820. time_t t;
  821. struct tm *tmStartWeek;
  822. struct timeb tbStartWeek;
  823. struct tm tmStop;
  824. struct timeb tbStop;
  825. 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))
  826. {
  827. t=time(NULL);
  828. tmStartWeek=localtime(&t);
  829. t-=86400*tmStartWeek->tm_wday;
  830. tmStartWeek=localtime(&t);
  831. tmStartWeek->tm_hour = 0;
  832. tmStartWeek->tm_min = 0;
  833. tmStartWeek->tm_sec = 0;
  834. tbStartWeek.time = mktime(tmStartWeek);
  835. tmStop.tm_year -= 1900;
  836. tmStop.tm_mon -= 1;
  837. tbStop.time = mktime(&tmStop);
  838. tbStop.millitm = 0;
  839. result = DiffTimebSec(tbStartWeek, tbStop);
  840. }
  841. return result;
  842. }
  843. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  844. {
  845. FILE *fp;
  846. char profileFileName[128];
  847. char *line = NULL;
  848. size_t len = 0;
  849. time_t CurrentTime;
  850. struct tm *tmComposite;
  851. struct StructChargingProfile maxProfile;
  852. struct StructChargingProfile defaultTxProfile;
  853. struct StructChargingProfile txProfile;
  854. struct StructChargingSchedulePeriod tmpPeriod;
  855. uint8_t limitMax=0;
  856. uint8_t limitDef=0;
  857. uint8_t limitTx=0;
  858. int compositePeriodIdx = 0;
  859. CurrentTime = time(NULL);
  860. tmComposite=localtime(&CurrentTime);
  861. 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);
  862. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  863. compositeProfile->ChargingSchedule.Duration = durationReq;
  864. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  865. {
  866. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  867. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  868. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  869. }
  870. compositeProfile->ChargingProfileId = 1;
  871. compositeProfile->StackLevel = 99 ;
  872. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  873. maxProfile.ChargingProfileId = -1;
  874. defaultTxProfile.ChargingProfileId = -1;
  875. txProfile.ChargingProfileId = -1;
  876. system("yes|rm /tmp/*.json");
  877. system("cp /Storage/OCPP/*.json /tmp");
  878. /*
  879. * Search valid charging profile
  880. */
  881. //DEBUG_INFO("====================================\n");
  882. // Search max profile
  883. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  884. if((access(profileFileName, F_OK))!=-1)
  885. {
  886. fp = fopen(profileFileName, "r");
  887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  888. {
  889. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  890. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  891. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  892. }
  893. maxProfile.ChargingProfileId = -1;
  894. maxProfile.StackLevel = -1;
  895. while(getline(&line, &len, fp) != -1)
  896. {
  897. json_object *obj = NULL;
  898. obj = json_tokener_parse(line);
  899. if(is_error(obj))
  900. {
  901. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  902. }
  903. else
  904. {
  905. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  906. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  907. )
  908. {
  909. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  910. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  911. )
  912. {
  913. struct tm tmFrom, tmTo;
  914. struct timeb tbFrom, tbTo;
  915. 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) &&
  916. (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))
  917. {
  918. tmFrom.tm_year -= 1900;
  919. tmFrom.tm_mon -= 1;
  920. tbFrom.time = mktime(&tmFrom);
  921. tmTo.tm_year -= 1900;
  922. tmTo.tm_mon -= 1;
  923. tbTo.time = mktime(&tmTo);
  924. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  925. {
  926. if(maxProfile.ChargingProfileId == -1)
  927. DEBUG_INFO("MaxProfile found.\n");
  928. else
  929. DEBUG_INFO("MaxProfile updated.\n");
  930. // Required item
  931. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  932. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  933. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  934. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  935. 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++)
  936. {
  937. 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"));
  938. 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")));
  939. 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?
  940. 3:
  941. 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")));
  942. }
  943. // Optional item
  944. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  945. {
  946. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  947. }
  948. else
  949. {
  950. sprintf((char*)maxProfile.ValidFrom, " ");
  951. }
  952. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  953. {
  954. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  955. }
  956. else
  957. {
  958. sprintf((char*)maxProfile.ValidTo, " ");
  959. }
  960. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  961. {
  962. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  963. }
  964. else
  965. {
  966. sprintf((char*)maxProfile.RecurrencyKind, " ");
  967. }
  968. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  969. {
  970. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  971. }
  972. else
  973. {
  974. maxProfile.TransactionId = -1;
  975. }
  976. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  977. {
  978. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  979. }
  980. else
  981. {
  982. maxProfile.ChargingSchedule.Duration = -1;
  983. }
  984. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  985. {
  986. 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")));
  987. }
  988. else
  989. {
  990. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  991. }
  992. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  993. {
  994. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  995. }
  996. else
  997. {
  998. maxProfile.ChargingSchedule.MinChargingRate = -1;
  999. }
  1000. }
  1001. }
  1002. }
  1003. else
  1004. {
  1005. if(maxProfile.ChargingProfileId == -1)
  1006. DEBUG_INFO("MaxProfile found.\n");
  1007. else
  1008. DEBUG_INFO("MaxProfile updated.\n");
  1009. // Required item
  1010. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1011. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1012. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1013. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1014. 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++)
  1015. {
  1016. 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"));
  1017. 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")));
  1018. 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?
  1019. 3:
  1020. 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")));
  1021. }
  1022. // Optional item
  1023. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1024. {
  1025. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1026. }
  1027. else
  1028. {
  1029. sprintf((char*)maxProfile.ValidFrom, " ");
  1030. }
  1031. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1032. {
  1033. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1034. }
  1035. else
  1036. {
  1037. sprintf((char*)maxProfile.ValidTo, " ");
  1038. }
  1039. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1040. {
  1041. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1042. }
  1043. else
  1044. {
  1045. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1046. }
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1048. {
  1049. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1050. }
  1051. else
  1052. {
  1053. maxProfile.TransactionId = -1;
  1054. }
  1055. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1056. {
  1057. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1058. }
  1059. else
  1060. {
  1061. maxProfile.ChargingSchedule.Duration = -1;
  1062. }
  1063. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1064. {
  1065. 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")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1070. }
  1071. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1072. {
  1073. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1074. }
  1075. else
  1076. {
  1077. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1078. }
  1079. }
  1080. }
  1081. }
  1082. json_object_put(obj);
  1083. }
  1084. fclose(fp);
  1085. /*
  1086. if(maxProfile.ChargingProfileId !=-1)
  1087. {
  1088. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1089. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1090. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1091. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1092. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1093. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1094. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1095. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1096. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1097. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1098. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1100. {
  1101. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1102. {
  1103. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1104. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1105. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1106. }
  1107. }
  1108. }
  1109. else
  1110. DEBUG_INFO("MaxProfile not found.\n");
  1111. DEBUG_INFO("------------------------------------\n");*/
  1112. }
  1113. // Search default tx profile
  1114. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1115. if((access(profileFileName, F_OK))==-1)
  1116. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1117. if((access(profileFileName, F_OK))!=-1)
  1118. {
  1119. fp = fopen(profileFileName, "r");
  1120. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1121. {
  1122. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1123. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1124. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1125. }
  1126. defaultTxProfile.ChargingProfileId = -1;
  1127. defaultTxProfile.StackLevel = -1;
  1128. while(getline(&line, &len, fp) != -1)
  1129. {
  1130. json_object *obj = NULL;
  1131. obj = json_tokener_parse(line);
  1132. if(is_error(obj))
  1133. {
  1134. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1135. }
  1136. else
  1137. {
  1138. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1139. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1140. )
  1141. {
  1142. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1143. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1144. )
  1145. {
  1146. struct tm tmFrom, tmTo;
  1147. struct timeb tbFrom, tbTo;
  1148. 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) &&
  1149. (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))
  1150. {
  1151. tmFrom.tm_year -= 1900;
  1152. tmFrom.tm_mon -= 1;
  1153. tbFrom.time = mktime(&tmFrom);
  1154. tmTo.tm_year -= 1900;
  1155. tmTo.tm_mon -= 1;
  1156. tbTo.time = mktime(&tmTo);
  1157. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1158. {
  1159. if(defaultTxProfile.ChargingProfileId == -1)
  1160. DEBUG_INFO("TxDefaultProfile found.\n");
  1161. else
  1162. DEBUG_INFO("TxDefaultProfile updated.\n");
  1163. // Required item
  1164. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1165. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1166. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1167. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1168. 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++)
  1169. {
  1170. 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"));
  1171. 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")));
  1172. 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?
  1173. 3:
  1174. 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")));
  1175. }
  1176. // Optional item
  1177. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1178. {
  1179. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1180. }
  1181. else
  1182. {
  1183. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1184. }
  1185. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1186. {
  1187. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1188. }
  1189. else
  1190. {
  1191. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1192. }
  1193. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1194. {
  1195. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1196. }
  1197. else
  1198. {
  1199. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1200. }
  1201. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1202. {
  1203. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1204. }
  1205. else
  1206. {
  1207. defaultTxProfile.TransactionId = -1;
  1208. }
  1209. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1210. {
  1211. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1212. }
  1213. else
  1214. {
  1215. defaultTxProfile.ChargingSchedule.Duration = -1;
  1216. }
  1217. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1218. {
  1219. 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")));
  1220. }
  1221. else
  1222. {
  1223. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1224. }
  1225. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1226. {
  1227. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1228. }
  1229. else
  1230. {
  1231. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. else
  1237. {
  1238. if(defaultTxProfile.ChargingProfileId == -1)
  1239. DEBUG_INFO("TxDefaultProfile found.\n");
  1240. else
  1241. DEBUG_INFO("TxDefaultProfile updated.\n");
  1242. // Required item
  1243. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1244. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1245. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1246. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1247. 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++)
  1248. {
  1249. 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"));
  1250. 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")));
  1251. 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?
  1252. 3:
  1253. 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")));
  1254. }
  1255. // Optional item
  1256. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1257. {
  1258. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1259. }
  1260. else
  1261. {
  1262. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1263. }
  1264. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1265. {
  1266. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1267. }
  1268. else
  1269. {
  1270. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1271. }
  1272. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1273. {
  1274. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1275. }
  1276. else
  1277. {
  1278. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1279. }
  1280. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1281. {
  1282. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1283. }
  1284. else
  1285. {
  1286. defaultTxProfile.TransactionId = -1;
  1287. }
  1288. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1289. {
  1290. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1291. }
  1292. else
  1293. {
  1294. defaultTxProfile.ChargingSchedule.Duration = -1;
  1295. }
  1296. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1297. {
  1298. 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")));
  1299. }
  1300. else
  1301. {
  1302. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1303. }
  1304. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1305. {
  1306. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1307. }
  1308. else
  1309. {
  1310. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. json_object_put(obj);
  1316. }
  1317. fclose(fp);
  1318. /*
  1319. if(defaultTxProfile.ChargingProfileId != -1)
  1320. {
  1321. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1322. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1323. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1324. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1325. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1326. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1327. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1328. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1329. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1330. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1331. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1332. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1333. {
  1334. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1335. {
  1336. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1337. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1338. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1339. }
  1340. }
  1341. }
  1342. else
  1343. DEBUG_INFO("TxDefaultProfile not found.\n");
  1344. DEBUG_INFO("------------------------------------\n");*/
  1345. }
  1346. // Search tx profile
  1347. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1348. if((access(profileFileName, F_OK))!=-1)
  1349. {
  1350. fp = fopen(profileFileName, "r");
  1351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1352. {
  1353. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1354. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1355. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1356. }
  1357. txProfile.ChargingProfileId = -1;
  1358. txProfile.StackLevel = -1;
  1359. while(getline(&line, &len, fp) != -1)
  1360. {
  1361. json_object *obj = NULL;
  1362. obj = json_tokener_parse(line);
  1363. if(is_error(obj))
  1364. {
  1365. DEBUG_ERROR("Parse txProfile from file error.\n");
  1366. }
  1367. else
  1368. {
  1369. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1370. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1371. )
  1372. {
  1373. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1374. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1375. )
  1376. {
  1377. struct tm tmFrom, tmTo;
  1378. struct timeb tbFrom, tbTo;
  1379. 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) &&
  1380. (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))
  1381. {
  1382. tmFrom.tm_year -= 1900;
  1383. tmFrom.tm_mon -= 1;
  1384. tbFrom.time = mktime(&tmFrom);
  1385. tmTo.tm_year -= 1900;
  1386. tmTo.tm_mon -= 1;
  1387. tbTo.time = mktime(&tmTo);
  1388. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1389. {
  1390. if(txProfile.ChargingProfileId == -1)
  1391. DEBUG_INFO("TxProfile found.\n");
  1392. else
  1393. DEBUG_INFO("TxProfile updated.\n");
  1394. // Required item
  1395. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1396. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1397. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1398. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1399. 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++)
  1400. {
  1401. 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"));
  1402. 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")));
  1403. 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?
  1404. 3:
  1405. 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")));
  1406. }
  1407. // Optional item
  1408. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1409. {
  1410. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1411. }
  1412. else
  1413. {
  1414. sprintf((char*)txProfile.ValidFrom, " ");
  1415. }
  1416. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1417. {
  1418. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1419. }
  1420. else
  1421. {
  1422. sprintf((char*)txProfile.ValidTo, " ");
  1423. }
  1424. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1425. {
  1426. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1427. }
  1428. else
  1429. {
  1430. sprintf((char*)txProfile.RecurrencyKind, " ");
  1431. }
  1432. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1433. {
  1434. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1435. }
  1436. else
  1437. {
  1438. txProfile.TransactionId = -1;
  1439. }
  1440. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1441. {
  1442. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1443. }
  1444. else
  1445. {
  1446. txProfile.ChargingSchedule.Duration = -1;
  1447. }
  1448. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1449. {
  1450. 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")));
  1451. }
  1452. else
  1453. {
  1454. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1455. }
  1456. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1457. {
  1458. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1459. }
  1460. else
  1461. {
  1462. txProfile.ChargingSchedule.MinChargingRate = -1;
  1463. }
  1464. }
  1465. }
  1466. }
  1467. else
  1468. {
  1469. if(txProfile.ChargingProfileId == -1)
  1470. DEBUG_INFO("TxProfile found.\n");
  1471. else
  1472. DEBUG_INFO("TxProfile updated.\n");
  1473. // Required item
  1474. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1475. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1476. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1477. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1478. 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++)
  1479. {
  1480. 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"));
  1481. 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")));
  1482. 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?
  1483. 3:
  1484. 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")));
  1485. }
  1486. // Optional item
  1487. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1488. {
  1489. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1490. }
  1491. else
  1492. {
  1493. sprintf((char*)txProfile.ValidFrom, " ");
  1494. }
  1495. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1496. {
  1497. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1498. }
  1499. else
  1500. {
  1501. sprintf((char*)txProfile.ValidTo, " ");
  1502. }
  1503. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1504. {
  1505. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1506. }
  1507. else
  1508. {
  1509. sprintf((char*)txProfile.RecurrencyKind, " ");
  1510. }
  1511. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1512. {
  1513. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1514. }
  1515. else
  1516. {
  1517. txProfile.TransactionId = -1;
  1518. }
  1519. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1520. {
  1521. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1522. }
  1523. else
  1524. {
  1525. txProfile.ChargingSchedule.Duration = -1;
  1526. }
  1527. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1528. {
  1529. 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")));
  1530. }
  1531. else
  1532. {
  1533. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1534. }
  1535. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1536. {
  1537. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1538. }
  1539. else
  1540. {
  1541. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1542. }
  1543. }
  1544. }
  1545. }
  1546. json_object_put(obj);
  1547. }
  1548. fclose(fp);
  1549. /*
  1550. if(defaultTxProfile.ChargingProfileId != -1)
  1551. {
  1552. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1553. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1554. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1555. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1556. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1557. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1558. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1559. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1560. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1561. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1562. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1563. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1564. {
  1565. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1566. {
  1567. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1568. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1569. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1570. }
  1571. }
  1572. }
  1573. else
  1574. DEBUG_INFO("TxProfile not found.\n");*/
  1575. }
  1576. /*
  1577. * Align found profile start schedule & periods
  1578. */
  1579. //DEBUG_INFO("====================================\n");
  1580. /*
  1581. // For local test usage, force modify found profile start schedule info
  1582. 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);
  1583. 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);
  1584. 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);
  1585. */
  1586. if(maxProfile.ChargingProfileId != -1)
  1587. {
  1588. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1589. {
  1590. if(maxProfile.ChargingSchedule.Duration != -1)
  1591. {
  1592. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1593. 0:
  1594. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1595. }
  1596. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1597. {
  1598. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1599. {
  1600. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1601. 0:
  1602. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1603. }
  1604. }
  1605. }
  1606. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1607. {
  1608. if(maxProfile.ChargingSchedule.Duration != -1)
  1609. {
  1610. 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?
  1611. 0:
  1612. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1613. }
  1614. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1615. {
  1616. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1617. {
  1618. 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?
  1619. 0:
  1620. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1621. }
  1622. }
  1623. }
  1624. else
  1625. {
  1626. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1627. {
  1628. if(maxProfile.ChargingSchedule.Duration != -1)
  1629. {
  1630. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1631. 0:
  1632. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1633. }
  1634. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1635. {
  1636. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1637. {
  1638. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1639. 0:
  1640. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1641. }
  1642. }
  1643. }
  1644. else
  1645. {
  1646. if(maxProfile.ChargingSchedule.Duration != -1)
  1647. {
  1648. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1649. 0:
  1650. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1651. }
  1652. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1653. {
  1654. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1655. {
  1656. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1657. 0:
  1658. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1659. }
  1660. }
  1661. }
  1662. }
  1663. /*
  1664. DEBUG_INFO("MaxProfile after align.\n");
  1665. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1666. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1667. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1668. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1669. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1670. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1671. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1672. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1673. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1674. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1675. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1676. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1677. {
  1678. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1679. {
  1680. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1681. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1682. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1683. }
  1684. }
  1685. DEBUG_INFO("------------------------------------\n");*/
  1686. }
  1687. if(defaultTxProfile.ChargingProfileId != -1)
  1688. {
  1689. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1690. {
  1691. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1692. {
  1693. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1694. 0:
  1695. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1696. }
  1697. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1698. {
  1699. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1700. {
  1701. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1702. 0:
  1703. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1704. }
  1705. }
  1706. }
  1707. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1708. {
  1709. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1710. {
  1711. 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?
  1712. 0:
  1713. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1714. }
  1715. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1716. {
  1717. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1718. {
  1719. 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?
  1720. 0:
  1721. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1722. }
  1723. }
  1724. }
  1725. else
  1726. {
  1727. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1728. {
  1729. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1730. {
  1731. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1732. 0:
  1733. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1734. }
  1735. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1736. {
  1737. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1738. {
  1739. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1740. 0:
  1741. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1748. {
  1749. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1750. 0:
  1751. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1752. }
  1753. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1754. {
  1755. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1756. {
  1757. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1758. 0:
  1759. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1760. }
  1761. }
  1762. }
  1763. }
  1764. /*
  1765. DEBUG_INFO("defaultTxProfile after align.\n");
  1766. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1767. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1768. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1769. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1770. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1771. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1772. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1773. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1774. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1775. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1776. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1777. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1778. {
  1779. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1780. {
  1781. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1782. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1783. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1784. }
  1785. }
  1786. DEBUG_INFO("------------------------------------\n");*/
  1787. }
  1788. if(txProfile.ChargingProfileId != -1)
  1789. {
  1790. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1791. {
  1792. if(txProfile.ChargingSchedule.Duration != -1)
  1793. {
  1794. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1795. 0:
  1796. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1797. }
  1798. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1799. {
  1800. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1801. {
  1802. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1803. 0:
  1804. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1805. }
  1806. }
  1807. }
  1808. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1809. {
  1810. if(txProfile.ChargingSchedule.Duration != -1)
  1811. {
  1812. 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?
  1813. 0:
  1814. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1815. }
  1816. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1817. {
  1818. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1819. {
  1820. 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?
  1821. 0:
  1822. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1823. }
  1824. }
  1825. }
  1826. else
  1827. {
  1828. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1829. {
  1830. if(txProfile.ChargingSchedule.Duration != -1)
  1831. {
  1832. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1833. 0:
  1834. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1835. }
  1836. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1837. {
  1838. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1839. {
  1840. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1841. 0:
  1842. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1843. }
  1844. }
  1845. }
  1846. else
  1847. {
  1848. if(txProfile.ChargingSchedule.Duration != -1)
  1849. {
  1850. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1851. 0:
  1852. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1853. }
  1854. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1855. {
  1856. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1857. {
  1858. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1859. 0:
  1860. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1861. }
  1862. }
  1863. }
  1864. }
  1865. /*
  1866. DEBUG_INFO("txProfile after align.\n");
  1867. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1868. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1869. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1870. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1871. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1872. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1873. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1874. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1875. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1876. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1877. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1878. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1879. {
  1880. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1881. {
  1882. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1883. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1884. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1885. }
  1886. }*/
  1887. }
  1888. /*
  1889. * Merge to conposite schedule
  1890. */
  1891. //DEBUG_INFO("====================================\n");
  1892. // Find each profile period quantity
  1893. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1894. {
  1895. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1896. limitMax = idx+1;
  1897. }
  1898. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1899. {
  1900. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1901. limitDef = idx+1;
  1902. }
  1903. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1904. {
  1905. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1906. limitTx = idx+1;
  1907. }
  1908. // TxProfile found, composite schedule based on it
  1909. if(txProfile.ChargingProfileId != -1)
  1910. {
  1911. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1912. {
  1913. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1914. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1915. {
  1916. if(maxProfile.ChargingProfileId != -1)
  1917. {
  1918. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1919. {
  1920. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1921. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1922. {
  1923. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1924. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1925. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1926. }
  1927. if(idxMaxPeriod == (limitMax-1))
  1928. {
  1929. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1930. {
  1931. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1932. {
  1933. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1934. compositePeriodIdx++;
  1935. }
  1936. else
  1937. {
  1938. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. else
  1945. {
  1946. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1947. {
  1948. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1949. compositePeriodIdx++;
  1950. }
  1951. else
  1952. {
  1953. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1954. }
  1955. }
  1956. }
  1957. if(idxTxPeriod == (limitTx-1))
  1958. {
  1959. if(defaultTxProfile.ChargingProfileId != -1)
  1960. {
  1961. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1962. {
  1963. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1964. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1965. {
  1966. if(maxProfile.ChargingProfileId != -1)
  1967. {
  1968. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1969. {
  1970. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1971. {
  1972. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1973. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1974. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1975. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1976. {
  1977. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1978. {
  1979. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1980. compositePeriodIdx++;
  1981. }
  1982. else
  1983. {
  1984. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1985. }
  1986. }
  1987. break;
  1988. }
  1989. }
  1990. }
  1991. else
  1992. {
  1993. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1994. {
  1995. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1996. compositePeriodIdx++;
  1997. }
  1998. else
  1999. {
  2000. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  2010. else if(defaultTxProfile.ChargingProfileId != -1)
  2011. {
  2012. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  2013. {
  2014. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  2015. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  2016. {
  2017. if(maxProfile.ChargingProfileId != -1)
  2018. {
  2019. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2020. {
  2021. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  2022. {
  2023. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  2024. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  2025. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  2026. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2027. {
  2028. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2029. {
  2030. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2031. compositePeriodIdx++;
  2032. }
  2033. else
  2034. {
  2035. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2036. }
  2037. }
  2038. break;
  2039. }
  2040. }
  2041. }
  2042. else
  2043. {
  2044. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2045. {
  2046. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2047. compositePeriodIdx++;
  2048. }
  2049. else
  2050. {
  2051. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2052. }
  2053. }
  2054. }
  2055. }
  2056. }
  2057. // Fill other period by MaxProfile
  2058. if(maxProfile.ChargingProfileId != -1)
  2059. {
  2060. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2061. {
  2062. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2063. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2064. {
  2065. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2066. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2067. {
  2068. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2069. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2070. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2071. }
  2072. if(idxMaxPeriod == (limitMax-1))
  2073. {
  2074. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2075. {
  2076. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2077. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2078. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2079. }
  2080. if(tmpPeriod.Limit != -1)
  2081. {
  2082. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2083. {
  2084. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2085. {
  2086. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2087. compositePeriodIdx++;
  2088. }
  2089. else
  2090. {
  2091. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2100. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2101. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2102. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2103. {
  2104. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2105. {
  2106. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2107. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2108. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2109. }
  2110. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2111. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2112. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2113. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2114. }
  2115. if(line)
  2116. free(line);
  2117. }
  2118. //==========================================
  2119. // Init all share memory
  2120. //==========================================
  2121. int InitShareMemory()
  2122. {
  2123. int result = PASS;
  2124. int MeterSMId;
  2125. //creat ShmSysConfigAndInfo
  2126. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2127. {
  2128. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2129. result = FAIL;
  2130. }
  2131. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2132. {
  2133. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2134. result = FAIL;
  2135. }
  2136. else
  2137. {}
  2138. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2139. {
  2140. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2141. result = FAIL;
  2142. }
  2143. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2144. {
  2145. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2146. result = FAIL;
  2147. }
  2148. else
  2149. {}
  2150. //creat ShmPsuData
  2151. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2152. {
  2153. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2154. result = FAIL;
  2155. }
  2156. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2157. {
  2158. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2159. result = FAIL;
  2160. }
  2161. else
  2162. {}
  2163. //creat ShmOCPP16Data
  2164. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2165. {
  2166. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2167. result = FAIL;
  2168. }
  2169. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2170. {
  2171. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2172. result = FAIL;
  2173. }
  2174. else
  2175. {}
  2176. /****************************** For Initial Settings************************************************/
  2177. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2178. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2179. // allocate Configuration memory address
  2180. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2181. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2182. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2183. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2184. //offline MeterValue Interval
  2185. TempMeterValueInterval = 0;
  2186. return result;
  2187. }
  2188. int ProcessShareMemory()
  2189. {
  2190. if(InitShareMemory() == FAIL)
  2191. {
  2192. DEBUG_ERROR("InitShareMemory NG\n");
  2193. if(ShmStatusCodeData!=NULL)
  2194. {
  2195. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2196. }
  2197. sleep(5);
  2198. return FAIL;
  2199. }
  2200. return PASS;
  2201. }
  2202. //---------------------common routine---------------------------//
  2203. int isOFFline(void)
  2204. {
  2205. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2206. {
  2207. if(TempMeterValueInterval >= 2 )
  2208. {
  2209. TempMeterValueInterval = 0;
  2210. return TRUE;
  2211. }
  2212. else
  2213. {
  2214. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2215. return FALSE;
  2216. }
  2217. }
  2218. else
  2219. {
  2220. return FALSE;
  2221. }
  2222. }
  2223. //---------------------------------------------
  2224. // new:
  2225. // enum SYSTEM_STATUS
  2226. // {
  2227. // SYS_MODE_BOOTING = 0,
  2228. // SYS_MODE_IDLE = 1,
  2229. // SYS_MODE_AUTHORIZING = 2,
  2230. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2231. // SYS_MODE_REASSIGN = 4,
  2232. // SYS_MODE_PREPARING = 5,
  2233. // SYS_MODE_PREPARE_FOR_EV = 6,
  2234. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2235. // SYS_MODE_CHARGING = 8,
  2236. // SYS_MODE_TERMINATING = 9,
  2237. // SYS_MODE_COMPLETE = 10,
  2238. // SYS_MODE_ALARM = 11,
  2239. // SYS_MODE_FAULT = 12,
  2240. // SYS_MODE_RESERVATION = 13,
  2241. // SYS_MODE_BOOKING = 14,
  2242. // SYS_MODE_MAINTAIN = 15,
  2243. // SYS_MODE_DEBUG = 16,
  2244. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2245. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2246. // SYS_MODE_UPDATE = 19
  2247. // };
  2248. //
  2249. //
  2250. //-----------------------------------------
  2251. void CheckSystemValue(void)
  2252. {
  2253. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2254. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2255. char filenmae[100]={0};
  2256. char str[100]={0};
  2257. //===============================
  2258. // send Heartbeat
  2259. //===============================
  2260. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2261. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2262. {
  2263. clientTime.Heartbeat=time((time_t*)NULL);
  2264. if(server_sign == TRUE)
  2265. {
  2266. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2267. }
  2268. else
  2269. {
  2270. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2271. }
  2272. }
  2273. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2274. {
  2275. //parameter for test
  2276. sendHeartbeatRequest(0);
  2277. //==============================================
  2278. // Reset Waiting Time
  2279. //==============================================
  2280. clientTime.Heartbeat=time((time_t*)NULL);
  2281. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2282. }
  2283. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2284. {
  2285. //===============================
  2286. // CSU Trigger Reset Conf
  2287. //===============================
  2288. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2289. {
  2290. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2291. }
  2292. //===============================
  2293. // CSU Trigger Authorize Request
  2294. //===============================
  2295. if(isWebsocketSendable && isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2296. {
  2297. sendAuthorizeRequest(0);
  2298. authorizeRetryTimes = authorizeRetryTimes + 1;
  2299. if(authorizeRetryTimes < 3)
  2300. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2301. }
  2302. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2303. {
  2304. authorizeRetryTimes = 0;
  2305. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2306. server_sign = FALSE;
  2307. }
  2308. 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))
  2309. {
  2310. sendAuthorizeRequest(0);
  2311. }
  2312. //===============================
  2313. // CSU Trigger Smart Charging Profilw
  2314. //===============================
  2315. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2316. {
  2317. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2318. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2319. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2320. }
  2321. //==============================================
  2322. // Charger start transaction
  2323. //==============================================
  2324. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2325. {
  2326. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2327. sendStartTransactionRequest(gun_index);
  2328. clientTime.StartTransaction = time((time_t*)NULL);
  2329. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2330. }
  2331. //==============================================
  2332. // Charger stop transaction
  2333. //==============================================
  2334. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2335. {
  2336. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2337. sendStopTransactionRequest(gun_index);
  2338. clientTime.StopTransaction = time((time_t*)NULL);
  2339. }
  2340. //==============================================
  2341. // Charger status report
  2342. //==============================================
  2343. //--- Check Mode Change ---//
  2344. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2345. if(gunType[gun_index] == 'J')
  2346. {
  2347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2348. {
  2349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2350. {
  2351. 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]*/ )
  2352. {
  2353. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2354. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2355. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2356. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2357. statusModeChage[gun_index] = TRUE;
  2358. }
  2359. #if 1 // for TempStopTransaction
  2360. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2361. {
  2362. checkTempStopTransaction(gun_index);
  2363. }
  2364. #endif
  2365. }
  2366. }
  2367. }
  2368. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2369. {
  2370. for (int index = 0; index < CCS_QUANTITY; index++)
  2371. {
  2372. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2373. {
  2374. 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]*/ )
  2375. {
  2376. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2377. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2378. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2379. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2380. statusModeChage[gun_index] = TRUE;
  2381. }
  2382. #if 1 // for TempStopTransaction
  2383. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2384. {
  2385. checkTempStopTransaction(gun_index);
  2386. }
  2387. #endif
  2388. }
  2389. }
  2390. }
  2391. else if(gunType[gun_index] == 'G')
  2392. {
  2393. for (int index = 0; index < GB_QUANTITY; index++)
  2394. {
  2395. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2396. {
  2397. 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]*/ )
  2398. {
  2399. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2400. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2401. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2402. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2403. statusModeChage[gun_index] = TRUE;
  2404. }
  2405. #if 1 // for TempStopTransaction
  2406. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2407. {
  2408. checkTempStopTransaction(gun_index);
  2409. }
  2410. #endif
  2411. }
  2412. }
  2413. }
  2414. else
  2415. {
  2416. for (int index = 0; index < AC_QUANTITY; index++)
  2417. {
  2418. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2419. {
  2420. 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]*/ )
  2421. {
  2422. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2423. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2424. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2425. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2426. statusModeChage[gun_index] = TRUE;
  2427. }
  2428. #if 1 // for TempStopTransaction
  2429. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2430. {
  2431. checkTempStopTransaction(gun_index);
  2432. }
  2433. #endif
  2434. }
  2435. }// END
  2436. }
  2437. if(isWebsocketSendable &&
  2438. (((server_sign == TRUE) && (SystemInitial > 0)) ||
  2439. ((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))))) )
  2440. {
  2441. if(SystemInitial > 0)
  2442. SystemInitial = SystemInitial -1;
  2443. sendStatusNotificationRequest(gun_index);
  2444. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2445. statusModeChage[gun_index] = FALSE;
  2446. }
  2447. //==============================================
  2448. // Meter report
  2449. //==============================================
  2450. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) ||
  2451. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2452. {
  2453. //check Transaction active
  2454. if(gunType[gun_index] == 'J')
  2455. {
  2456. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2457. {
  2458. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2459. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2460. {
  2461. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2462. {
  2463. reqSampleMeter[gun_index] = 1;
  2464. }
  2465. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2466. {
  2467. reqClockAlignMeter[gun_index] = 1;
  2468. }
  2469. }
  2470. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2471. {
  2472. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2473. if((access(filenmae,F_OK))!=-1)
  2474. {
  2475. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2476. sprintf(str,"rm -f %s",filenmae);
  2477. system(str);
  2478. }
  2479. }
  2480. }// End for CHAdeMO
  2481. }
  2482. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2483. {
  2484. for (int index = 0; index < CCS_QUANTITY; index++)
  2485. {
  2486. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2487. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2488. {
  2489. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2490. {
  2491. reqSampleMeter[gun_index] = 1;
  2492. }
  2493. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2494. {
  2495. reqClockAlignMeter[gun_index] = 1;
  2496. }
  2497. }
  2498. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2499. {
  2500. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2501. if((access(filenmae,F_OK))!=-1)
  2502. {
  2503. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2504. sprintf(str,"rm -f %s",filenmae);
  2505. system(str);
  2506. }
  2507. }
  2508. } // End for CCS
  2509. }
  2510. else if(gunType[gun_index] == 'G')
  2511. {
  2512. for (int index = 0; index < GB_QUANTITY; index++)
  2513. {
  2514. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2515. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2516. {
  2517. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2518. {
  2519. reqSampleMeter[gun_index] = 1;
  2520. }
  2521. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2522. {
  2523. reqClockAlignMeter[gun_index] = 1;
  2524. }
  2525. }
  2526. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2527. {
  2528. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2529. if((access(filenmae,F_OK))!=-1)
  2530. {
  2531. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2532. sprintf(str,"rm -f %s",filenmae);
  2533. system(str);
  2534. }
  2535. }
  2536. }// End for GB
  2537. }
  2538. else
  2539. {
  2540. for (int index = 0; index < AC_QUANTITY; index++)
  2541. {
  2542. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2543. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2544. {
  2545. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2546. {
  2547. reqSampleMeter[gun_index] = 1;
  2548. }
  2549. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2550. {
  2551. reqClockAlignMeter[gun_index] = 1;
  2552. }
  2553. }
  2554. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2555. {
  2556. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2557. if((access(filenmae,F_OK))!=-1)
  2558. {
  2559. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2560. sprintf(str,"rm -f %s",filenmae);
  2561. system(str);
  2562. }
  2563. }
  2564. }//End for AC
  2565. }
  2566. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2567. if(reqSampleMeter[gun_index] == 1)
  2568. {
  2569. sendMeterValuesRequest(gun_index);
  2570. storeTempStopTransaction(gun_index);
  2571. }
  2572. else if(reqClockAlignMeter[gun_index] == 1)
  2573. {
  2574. sendMeterValuesRequest(gun_index);
  2575. }
  2576. sleep(1);
  2577. }
  2578. //==============================================
  2579. // Check Connector reserved
  2580. //==============================================
  2581. //===============================
  2582. // Check if Reserve is expired
  2583. //===============================
  2584. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2585. {
  2586. double diff_t;
  2587. struct tm tp;
  2588. // current time
  2589. time_t t = time(NULL);
  2590. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2591. tp.tm_isdst = -1;
  2592. time_t utc = mktime(&tp);
  2593. diff_t = difftime(utc, t);
  2594. if(diff_t <= 0)
  2595. {
  2596. DEBUG_INFO("reserve expired.\n");
  2597. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2598. }
  2599. }//END OF Check if Reserve is expired
  2600. //==========================================
  2601. // csu trigger FirmwareStatusNotificationReq
  2602. //==========================================
  2603. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2604. {
  2605. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2606. }
  2607. //==========================================
  2608. // csu trigger CancelReservationConf
  2609. //==========================================
  2610. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2611. {
  2612. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2613. }
  2614. //==========================================
  2615. // csu trigger ChangeAvailabilityConf
  2616. //==========================================
  2617. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2618. {
  2619. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2620. }
  2621. //==========================================
  2622. // csu trigger UnlockConnectorConf
  2623. //==========================================
  2624. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2625. {
  2626. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2627. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2628. }
  2629. //==========================================
  2630. // csu trigger ReserveNowConf
  2631. //==========================================
  2632. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2633. {
  2634. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2635. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2636. }
  2637. //==========================================
  2638. // csu trigger DataTransferReq
  2639. //==========================================
  2640. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2641. {
  2642. sendDataTransferRequest(gun_index);
  2643. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2644. }
  2645. }
  2646. }
  2647. //==========================================
  2648. // send request routine
  2649. //==========================================
  2650. int sendAuthorizeRequest(int gun_index)
  2651. {
  2652. mtrace();
  2653. int result = FAIL;
  2654. char message[100]={0};
  2655. char guid[37];
  2656. char tempdata[65]={0};
  2657. DEBUG_INFO("sendAuthorizeRequest...\n");
  2658. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2659. //Local Authorize
  2660. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2661. {
  2662. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2663. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2664. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2665. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2666. result = PASS;
  2667. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2668. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2669. authorizeRetryTimes = 0;
  2670. return result;
  2671. }
  2672. 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))||
  2673. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2674. {
  2675. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2676. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2677. {
  2678. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2679. {
  2680. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2681. }
  2682. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2683. {
  2684. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2685. }
  2686. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2687. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2688. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2689. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2690. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2691. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2692. authorizeRetryTimes = 0;
  2693. return result;
  2694. }
  2695. else
  2696. {
  2697. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2698. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2699. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2700. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2701. result = PASS;
  2702. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2703. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2704. authorizeRetryTimes = 0;
  2705. return result;
  2706. }
  2707. }
  2708. //initailize struct Authorize
  2709. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2710. //get data from shared memory
  2711. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2712. random_uuid(guid);
  2713. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2714. LWS_Send(message);
  2715. sprintf(tempdata, "Authorize,%d", gun_index);
  2716. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2717. {
  2718. result = PASS;
  2719. DEBUG_INFO("Authorize mapItem pass\n");
  2720. }
  2721. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2722. return result;
  2723. }
  2724. int sendBootNotificationRequest(void)
  2725. {
  2726. mtrace();
  2727. int result = FAIL;
  2728. char message[500]={0}, payload[700]={0};
  2729. char guid[37]={0};
  2730. char tempdata[65]={0};
  2731. int IsGunCharging = FALSE;
  2732. //check Transaction active
  2733. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2734. {
  2735. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2736. {
  2737. IsGunCharging = TRUE;
  2738. }
  2739. }
  2740. for (int index = 0; index < CCS_QUANTITY; index++)
  2741. {
  2742. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2743. {
  2744. IsGunCharging = TRUE;
  2745. }
  2746. }
  2747. for (int index = 0; index < GB_QUANTITY; index++)
  2748. {
  2749. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2750. {
  2751. IsGunCharging = TRUE;
  2752. }
  2753. }
  2754. for (int index = 0; index < AC_QUANTITY; index++)
  2755. {
  2756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2757. {
  2758. IsGunCharging = TRUE;
  2759. }
  2760. }
  2761. if(IsGunCharging == TRUE)
  2762. {
  2763. server_sign = TRUE;
  2764. return result;
  2765. }
  2766. // Fill BootNotification fields
  2767. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2768. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2769. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2770. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2771. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2772. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2773. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2774. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2775. ShmOCPP16Data->ChargeBoxId
  2776. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2777. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2778. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2779. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2780. ,ShmOCPP16Data->BootNotification.CpIccid
  2781. ,ShmOCPP16Data->BootNotification.CpImsi);
  2782. random_uuid(guid);
  2783. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2784. LWS_Send(message);
  2785. sprintf(tempdata, "BootNotification,0");
  2786. 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*/)
  2787. {
  2788. result = PASS;
  2789. }
  2790. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2791. strcpy(queuedata,message);
  2792. return result;
  2793. }
  2794. int sendDataTransferRequest(int gun_index)
  2795. {
  2796. mtrace();
  2797. char message[1000]={0};
  2798. char guid[37]={0};
  2799. char tempdata[65]={0};
  2800. int result = FAIL;
  2801. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2802. random_uuid(guid);
  2803. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2804. MESSAGE_TYPE_CALL,
  2805. guid,
  2806. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2807. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2808. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2809. LWS_Send(message);
  2810. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2811. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2812. {
  2813. result = PASS;
  2814. DEBUG_INFO("DataTransfer mapItem pass\n");
  2815. }
  2816. return result;
  2817. }
  2818. int sendDiagnosticsStatusNotificationRequest(char *status)
  2819. {
  2820. mtrace();
  2821. int result = FAIL;
  2822. char message[110]={0};
  2823. char guid[37]={0};
  2824. char tempdata[65]={0};
  2825. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2826. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2827. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2828. random_uuid(guid);
  2829. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2830. LWS_Send(message);
  2831. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2832. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2833. {
  2834. result = PASS;
  2835. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2836. }
  2837. //#ifdef SystemLogMessage
  2838. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2839. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2840. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2841. //#endif
  2842. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2843. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2844. //record status
  2845. if(strcmp(status,"Idle")==0)
  2846. {
  2847. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2848. }
  2849. else if(strcmp(status,"Uploaded")==0)
  2850. {
  2851. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2852. }
  2853. else if(strcmp(status,"UploadFailed")==0)
  2854. {
  2855. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2856. }
  2857. else if(strcmp(status,"Uploading")==0)
  2858. {
  2859. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2860. }
  2861. return result;
  2862. }
  2863. int sendFirmwareStatusNotificationRequest(char *status)
  2864. {
  2865. mtrace();
  2866. int result = FAIL;
  2867. char message[110]={0};
  2868. char guid[37]={0};
  2869. char tempdata[65]={0};
  2870. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2871. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2872. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2873. random_uuid(guid);
  2874. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2875. LWS_Send(message);
  2876. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2877. 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*/)
  2878. {
  2879. result = PASS;
  2880. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2881. }
  2882. //#ifdef SystemLogMessage
  2883. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2884. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2885. //#endif
  2886. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2887. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2888. //record status
  2889. if(strcmp(status,"Downloaded")==0)
  2890. {
  2891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2892. }
  2893. else if(strcmp(status,"DownloadFailed")==0)
  2894. {
  2895. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2896. }
  2897. else if(strcmp(status,"Downloading")==0)
  2898. {
  2899. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2900. }
  2901. else if(strcmp(status,"Idle")==0)
  2902. {
  2903. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2904. }
  2905. else if(strcmp(status,"InstallationFailed")==0)
  2906. {
  2907. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2908. }
  2909. else if(strcmp(status,"Installing")==0)
  2910. {
  2911. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2912. }
  2913. else if(strcmp(status,"Installed")==0)
  2914. {
  2915. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2916. }
  2917. return result;
  2918. }
  2919. int sendHeartbeatRequest(int gun_index)
  2920. {
  2921. mtrace();
  2922. int result = FAIL;
  2923. char message[80]={0};
  2924. char guid[37]={0};
  2925. char tempdata[65]={0};
  2926. random_uuid(guid);
  2927. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2928. , MESSAGE_TYPE_CALL
  2929. , guid );
  2930. LWS_Send(message);
  2931. sprintf(tempdata, "Heartbeat,%d", 0);
  2932. 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*/)
  2933. {
  2934. result = PASS;
  2935. }
  2936. return result;
  2937. }
  2938. int sendStartTransactionRequest(int gun_index)
  2939. {
  2940. mtrace();
  2941. int result = FAIL;
  2942. char message[250]={0};
  2943. char guid[37]={0};
  2944. struct timeval tmnow;
  2945. struct tm *tm;
  2946. char buf[28];//, usec_buf[6];
  2947. char tempdata[65]={0};
  2948. int tempIndex = 0;
  2949. DEBUG_INFO("sendStartTransactionRequest...\n");
  2950. gettimeofday(&tmnow, NULL);
  2951. time_t t;
  2952. t = time(NULL);
  2953. /*UTC time and date*/
  2954. tm = gmtime(&t);
  2955. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2956. #if 0 // remove temporally
  2957. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2958. strcat(buf,".");
  2959. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2960. strcat(buf,usec_buf);
  2961. #endif
  2962. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2963. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2964. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2965. // clear StartTransaction Response
  2966. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2967. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2968. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2969. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2970. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2971. if(gunType[gun_index] == 'J')
  2972. {
  2973. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2974. {
  2975. tempIndex = ((gun_index==2) ? 1: 0);
  2976. }
  2977. else
  2978. {
  2979. tempIndex = gun_index;
  2980. }
  2981. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2982. {
  2983. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2984. {
  2985. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2986. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2987. }
  2988. }
  2989. }
  2990. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2991. {
  2992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2993. {
  2994. tempIndex = ((gun_index==2) ? 1: 0);
  2995. }
  2996. else
  2997. {
  2998. tempIndex = gun_index;
  2999. }
  3000. for (int index = 0; index < CCS_QUANTITY; index++)
  3001. {
  3002. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3003. {
  3004. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  3005. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  3006. }
  3007. }
  3008. }
  3009. else if(gunType[gun_index] == 'G')
  3010. {
  3011. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3012. {
  3013. tempIndex = ((gun_index==2) ? 1: 0);
  3014. }
  3015. else
  3016. {
  3017. tempIndex = gun_index;
  3018. }
  3019. for (int index = 0; index < GB_QUANTITY; index++)
  3020. {
  3021. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3022. {
  3023. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3024. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3025. }
  3026. }
  3027. }
  3028. else
  3029. {
  3030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3031. {
  3032. tempIndex = 2;
  3033. }
  3034. else
  3035. {
  3036. tempIndex = gun_index;
  3037. }
  3038. for (int index = 0; index < AC_QUANTITY; index++)
  3039. {
  3040. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3041. {
  3042. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3043. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3044. }
  3045. }
  3046. }
  3047. random_uuid(guid);
  3048. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3049. {
  3050. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3051. , gun_index +1
  3052. , MESSAGE_TYPE_CALL
  3053. , guid
  3054. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3055. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3056. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3057. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3058. }
  3059. else
  3060. {
  3061. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3062. , gun_index +1
  3063. , MESSAGE_TYPE_CALL
  3064. , guid
  3065. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3066. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3067. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3068. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3069. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3070. }
  3071. #if 1
  3072. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3073. 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*/)
  3074. {
  3075. result = PASS;
  3076. }
  3077. #endif
  3078. strcpy(queuedata, message);
  3079. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3080. /*
  3081. if(GetTransactionQueueNum() == 1)
  3082. {
  3083. LWS_Send(message + 2);
  3084. }*/
  3085. return result;
  3086. }
  3087. int sendStatusNotificationRequest(int gun_index)
  3088. {
  3089. mtrace();
  3090. int result = FAIL;
  3091. char message[600]={0};
  3092. char guid[37];
  3093. int currentStatus = 0;
  3094. struct timeval tmnow;
  3095. struct tm *tm;
  3096. char buf[28];//, usec_buf[6];
  3097. char tempdata[65]={0};
  3098. int tempIndex = 0;
  3099. gettimeofday(&tmnow, NULL);
  3100. time_t t;
  3101. t = time(NULL);
  3102. /*UTC time and date*/
  3103. tm = gmtime(&t);
  3104. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3105. #if 0 // remove temporally
  3106. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3107. strcat(buf,".");
  3108. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3109. strcat(buf,usec_buf);
  3110. #endif
  3111. printf("%s",buf);
  3112. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3113. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3114. // it's option
  3115. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3116. /*
  3117. enum _SYSTEM_STATUS
  3118. {
  3119. S_BOOTING = 0,
  3120. S_IDLE, = 1
  3121. S_AUTHORIZING, =2
  3122. S_REASSIGN_CHECK, =3
  3123. S_REASSIGN, =4
  3124. S_PRECHARGE, =5
  3125. S_PREPARING_FOR_EV, =6
  3126. S_PREPARING_FOR_EVSE, =7
  3127. S_CHARGING, =8
  3128. S_TERMINATING, =9
  3129. S_COMPLETE, =10
  3130. S_ALARM, =11
  3131. S_FAULT =12
  3132. }
  3133. */
  3134. //check Transaction active
  3135. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3136. if(gunType[gun_index] == 'J')
  3137. {
  3138. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3139. {
  3140. tempIndex = ((gun_index==2) ? 1: 0);
  3141. }
  3142. else
  3143. {
  3144. tempIndex = gun_index;
  3145. }
  3146. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3147. {
  3148. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3149. {
  3150. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3151. {
  3152. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3153. {
  3154. currentStatus = 1; //OCPP Status: Preparing
  3155. }
  3156. else
  3157. {
  3158. currentStatus = 0; //OCPP Status: Available
  3159. }
  3160. }
  3161. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3162. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3163. ) //S_PRECHARGE
  3164. {
  3165. currentStatus = 1; //OCPP Status: Preparing
  3166. }
  3167. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3168. {
  3169. currentStatus = 2; //OCPP Status: Charging
  3170. }
  3171. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3172. {
  3173. currentStatus = 5; //OCPP Status: Finishing
  3174. }
  3175. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3176. {
  3177. currentStatus = 4; //OCPP Status: SuspendedEV
  3178. }
  3179. 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
  3180. {
  3181. currentStatus = 7; //OCPP Status: Unavailable
  3182. }
  3183. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3184. {
  3185. currentStatus = 8; //OCPP Status: Faulted
  3186. }
  3187. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3188. {
  3189. currentStatus = 6; //OCPP Status: Reserved
  3190. }
  3191. } //end of the same index
  3192. }//end of for CHAdeMO_QUANTITY
  3193. }
  3194. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3195. {
  3196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3197. {
  3198. tempIndex = ((gun_index==2) ? 1: 0);
  3199. }
  3200. else
  3201. {
  3202. tempIndex = gun_index;
  3203. }
  3204. for (int index = 0; index < CCS_QUANTITY; index++)
  3205. {
  3206. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3207. {
  3208. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3209. {
  3210. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3211. {
  3212. currentStatus = 1; //OCPP Status: Preparing
  3213. }
  3214. else
  3215. {
  3216. currentStatus = 0; //OCPP Status: Available
  3217. }
  3218. }
  3219. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3220. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3221. ) //S_PRECHARGE
  3222. {
  3223. currentStatus = 1; //OCPP Status: Preparing
  3224. }
  3225. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3226. {
  3227. currentStatus = 2; //OCPP Status: Charging
  3228. }
  3229. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3230. {
  3231. currentStatus = 5; //OCPP Status: Finishing
  3232. }
  3233. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3234. {
  3235. currentStatus = 4; //OCPP Status: SuspendedEV
  3236. }
  3237. 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
  3238. {
  3239. currentStatus = 7; //OCPP Status : Unavailable
  3240. }
  3241. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3242. {
  3243. currentStatus = 8; //OCPP Status: Faulted
  3244. }
  3245. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3246. {
  3247. currentStatus = 6; //OCPP Status: Reserved
  3248. }
  3249. } //end of the same index
  3250. } // end of for CCS_QUANTITY
  3251. }
  3252. else if(gunType[gun_index] == 'G')
  3253. {
  3254. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3255. {
  3256. tempIndex = ((gun_index==2) ? 1: 0);
  3257. }
  3258. else
  3259. {
  3260. tempIndex = gun_index;
  3261. }
  3262. for (int index = 0; index < GB_QUANTITY; index++)
  3263. {
  3264. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3265. {
  3266. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3267. {
  3268. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3269. {
  3270. currentStatus = 1; //OCPP Status: Preparing
  3271. }
  3272. else
  3273. {
  3274. currentStatus = 0; //OCPP Status: Available
  3275. }
  3276. }
  3277. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3278. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3279. ) //S_PRECHARGE
  3280. {
  3281. currentStatus = 1; //OCPP Status: Preparing
  3282. }
  3283. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3284. {
  3285. currentStatus = 2; //OCPP Status: Charging
  3286. }
  3287. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3288. {
  3289. currentStatus = 5; //OCPP Status: Finishing
  3290. }
  3291. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3292. {
  3293. currentStatus = 4; //OCPP Status: SuspendedEV
  3294. }
  3295. 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
  3296. {
  3297. currentStatus = 7; //OCPP Status: Unavailable
  3298. }
  3299. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3300. {
  3301. currentStatus = 8; //OCPP Status: Faulted
  3302. }
  3303. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3304. {
  3305. currentStatus = 6; //OCPP Status: Reserved
  3306. }
  3307. } //end of the same index
  3308. } // end of for GB_QUANTITY
  3309. }
  3310. else
  3311. {
  3312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3313. {
  3314. tempIndex = 2;
  3315. }
  3316. else
  3317. {
  3318. tempIndex = gun_index;
  3319. }
  3320. for (int index = 0; index < AC_QUANTITY; index++)
  3321. {
  3322. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3323. {
  3324. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3325. {
  3326. 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))
  3327. {
  3328. currentStatus = 1; //OCPP Status: Preparing
  3329. }
  3330. else
  3331. {
  3332. currentStatus = 0; //OCPP Status: Available
  3333. }
  3334. }
  3335. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3336. {
  3337. currentStatus = 1; //OCPP Status: Preparing
  3338. }
  3339. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3340. {
  3341. currentStatus = 2; //OCPP Status: Charging
  3342. }
  3343. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3344. {
  3345. currentStatus = 5; //OCPP Status: Finishing
  3346. }
  3347. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3348. {
  3349. currentStatus = 4; //OCPP Status: SuspendedEV
  3350. }
  3351. 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
  3352. {
  3353. currentStatus = 7; //OCPP Status: Unavailable
  3354. }
  3355. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3356. {
  3357. currentStatus = 8; //OCPP Status: Faulted
  3358. }
  3359. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3360. {
  3361. currentStatus = 6; //OCPP Status: Reserved
  3362. }
  3363. }//end of the same index
  3364. }//end of for AC_QUANTITY
  3365. }
  3366. //it's option
  3367. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3368. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3369. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3370. random_uuid(guid);
  3371. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3372. , MESSAGE_TYPE_CALL
  3373. , guid
  3374. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3375. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3376. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3377. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3378. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3379. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3380. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3381. LWS_Send(message);
  3382. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3383. 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*/)
  3384. {
  3385. //DEBUG_ERROR("statusNotification mapitem pass");
  3386. result = PASS;
  3387. }
  3388. return result;
  3389. }
  3390. int sendStopTransactionRequest(int gun_index)
  3391. {
  3392. mtrace();
  3393. int result = FAIL;
  3394. //char message[1500]={0};
  3395. char guid[37]={0};
  3396. char tempdata[65]={0};
  3397. int tempIndex = 0;
  3398. //int idx_sample=0;
  3399. DEBUG_ERROR("sendStopTransactionRequest \n");
  3400. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3401. //ENERGY_ACTIVE_IMPORT_REGISTER
  3402. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3403. if(gunType[gun_index] == 'J')
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3406. {
  3407. tempIndex = ((gun_index==2) ? 1: 0);
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3416. {
  3417. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3418. }
  3419. }// END OF CHAdeMO_QUANTITY
  3420. }
  3421. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3422. {
  3423. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3424. {
  3425. tempIndex = ((gun_index==2) ? 1: 0);
  3426. }
  3427. else
  3428. {
  3429. tempIndex = gun_index;
  3430. }
  3431. for (int index = 0; index < CCS_QUANTITY; index++)
  3432. {
  3433. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3434. {
  3435. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3436. }
  3437. }// END OF CCS_QUANTITY
  3438. }
  3439. else if(gunType[gun_index] == 'G')
  3440. {
  3441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3442. {
  3443. tempIndex = ((gun_index==2) ? 1: 0);
  3444. }
  3445. else
  3446. {
  3447. tempIndex = gun_index;
  3448. }
  3449. for (int index = 0; index < GB_QUANTITY; index++)
  3450. {
  3451. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3452. {
  3453. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3454. }
  3455. }// END OF GB_QUANTITY
  3456. }
  3457. else
  3458. {
  3459. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3460. {
  3461. tempIndex = 2;
  3462. }
  3463. else
  3464. {
  3465. tempIndex = gun_index;
  3466. }
  3467. for (int index = 0; index < AC_QUANTITY; index++)
  3468. {
  3469. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3470. {
  3471. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3472. }
  3473. }// END OF AC_QUANTITY
  3474. }
  3475. //Stop Transaction Time
  3476. struct timeval tmnow;
  3477. struct tm *tm;
  3478. char buf[28];//, usec_buf[6];
  3479. gettimeofday(&tmnow, NULL);
  3480. time_t t;
  3481. t = time(NULL);
  3482. /*UTC time and date*/
  3483. tm = gmtime(&t);
  3484. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3486. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3487. random_uuid(guid);
  3488. /***********************************transactionData******************************************************/
  3489. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3490. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3491. //=================================
  3492. // Transaction_Begin
  3493. //=================================
  3494. // Energy.Active.Export.Interval
  3495. //idx_sample=0;
  3496. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3499. 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*/]);
  3500. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3501. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3502. {
  3503. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3504. }
  3505. else
  3506. {
  3507. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3508. }
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3511. //=================================
  3512. // Transaction_End
  3513. //=================================
  3514. //Current.Export
  3515. //idx_sample=1;
  3516. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3517. if(gunType[gun_index] == 'J')
  3518. {
  3519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3520. {
  3521. tempIndex = ((gun_index==2) ? 1: 0);
  3522. }
  3523. else
  3524. {
  3525. tempIndex = gun_index;
  3526. }
  3527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3528. {
  3529. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3530. {
  3531. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3532. }
  3533. }// End of for CHAdeMO_QUANTITY
  3534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3535. }
  3536. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3537. {
  3538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3539. {
  3540. tempIndex = ((gun_index==2) ? 1: 0);
  3541. }
  3542. else
  3543. {
  3544. tempIndex = gun_index;
  3545. }
  3546. for (int index = 0; index < CCS_QUANTITY; index++)
  3547. {
  3548. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3549. {
  3550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3551. }
  3552. }// End of for CCS_QUANTITY
  3553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3554. }
  3555. else if(gunType[gun_index] == 'G')
  3556. {
  3557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3558. {
  3559. tempIndex = ((gun_index==2) ? 1: 0);
  3560. }
  3561. else
  3562. {
  3563. tempIndex = gun_index;
  3564. }
  3565. for (int index = 0; index < GB_QUANTITY; index++)
  3566. {
  3567. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3568. {
  3569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3570. }
  3571. }// End of for GB_QUANTITY
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3573. }
  3574. else
  3575. {
  3576. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3577. {
  3578. tempIndex = 2;
  3579. }
  3580. else
  3581. {
  3582. tempIndex = gun_index;
  3583. }
  3584. for (int index = 0; index < AC_QUANTITY; index++)
  3585. {
  3586. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3587. {
  3588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3589. }
  3590. }// End of for AC_QUANTITY
  3591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3592. }
  3593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3596. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3597. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3598. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3599. //Energy.Active.Export.Interval
  3600. //idx_sample=2;
  3601. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3602. if(gunType[gun_index] == 'J')
  3603. {
  3604. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3605. {
  3606. tempIndex = ((gun_index==2) ? 1: 0);
  3607. }
  3608. else
  3609. {
  3610. tempIndex = gun_index;
  3611. }
  3612. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3613. {
  3614. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3615. {
  3616. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3617. }
  3618. }// END OF CHAdeMO_QUANTITY
  3619. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3620. }
  3621. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3622. {
  3623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3624. {
  3625. tempIndex = ((gun_index==2) ? 1: 0);
  3626. }
  3627. else
  3628. {
  3629. tempIndex = gun_index;
  3630. }
  3631. for (int index = 0; index < CCS_QUANTITY; index++)
  3632. {
  3633. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3634. {
  3635. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3636. }
  3637. }// END OF CCS_QUANTITY
  3638. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3639. }
  3640. else if(gunType[gun_index] == 'G')
  3641. {
  3642. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3643. {
  3644. tempIndex = ((gun_index==2) ? 1: 0);
  3645. }
  3646. else
  3647. {
  3648. tempIndex = gun_index;
  3649. }
  3650. for (int index = 0; index < GB_QUANTITY; index++)
  3651. {
  3652. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3653. {
  3654. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3655. }
  3656. }// END OF GB_QUANTITY
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3658. }
  3659. else
  3660. {
  3661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3662. {
  3663. tempIndex = 2;
  3664. }
  3665. else
  3666. {
  3667. tempIndex = gun_index;
  3668. }
  3669. for (int index = 0; index < AC_QUANTITY; index++)
  3670. {
  3671. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3672. {
  3673. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3674. }
  3675. }// END OF AC_QUANTITY
  3676. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3677. }
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3681. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3682. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3684. //Power.Active.Export
  3685. //idx_sample=3;
  3686. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3687. if(gunType[gun_index] == 'J')
  3688. {
  3689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3690. {
  3691. tempIndex = ((gun_index==2) ? 1: 0);
  3692. }
  3693. else
  3694. {
  3695. tempIndex = gun_index;
  3696. }
  3697. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3698. {
  3699. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3700. {
  3701. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3702. }
  3703. } // End for CHAdeMO_QUANTITY
  3704. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3705. }
  3706. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3707. {
  3708. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3709. {
  3710. tempIndex = ((gun_index==2) ? 1: 0);
  3711. }
  3712. else
  3713. {
  3714. tempIndex = gun_index;
  3715. }
  3716. for (int index = 0; index < CCS_QUANTITY; index++)
  3717. {
  3718. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3719. {
  3720. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3721. }
  3722. } // END for CCS_QUANTITY
  3723. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3724. }
  3725. else if(gunType[gun_index] == 'G')
  3726. {
  3727. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3728. {
  3729. tempIndex = ((gun_index==2) ? 1: 0);
  3730. }
  3731. else
  3732. {
  3733. tempIndex = gun_index;
  3734. }
  3735. for (int index = 0; index < GB_QUANTITY; index++)
  3736. {
  3737. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3738. {
  3739. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3740. }
  3741. }// END for GB_QUANTITY
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3743. }
  3744. else
  3745. {
  3746. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3747. {
  3748. tempIndex = 2;
  3749. }
  3750. else
  3751. {
  3752. tempIndex = gun_index;
  3753. }
  3754. for (int index = 0; index < AC_QUANTITY; index++)
  3755. {
  3756. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3757. {
  3758. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3759. }
  3760. } // END for AC_QUANTITY
  3761. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3762. }
  3763. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3766. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3767. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3769. //Voltage
  3770. //idx_sample=4;
  3771. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3772. if(gunType[gun_index] == 'J')
  3773. {
  3774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3775. {
  3776. tempIndex = ((gun_index==2) ? 1: 0);
  3777. }
  3778. else
  3779. {
  3780. tempIndex = gun_index;
  3781. }
  3782. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3783. {
  3784. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3785. {
  3786. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3787. }
  3788. } // END OF FOR CHAdeMO_QUANTITY
  3789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3790. }
  3791. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3792. {
  3793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3794. {
  3795. tempIndex = ((gun_index==2) ? 1: 0);
  3796. }
  3797. else
  3798. {
  3799. tempIndex = gun_index;
  3800. }
  3801. for (int index = 0; index < CCS_QUANTITY; index++)
  3802. {
  3803. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3804. {
  3805. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3806. }
  3807. } // END OF FOR CCS_QUANTITY
  3808. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3809. }
  3810. else if(gunType[gun_index] == 'G')
  3811. {
  3812. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3813. {
  3814. tempIndex = ((gun_index==2) ? 1: 0);
  3815. }
  3816. else
  3817. {
  3818. tempIndex = gun_index;
  3819. }
  3820. for (int index = 0; index < GB_QUANTITY; index++)
  3821. {
  3822. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3823. {
  3824. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3825. }
  3826. } // END OF FOR GB_QUANTITY
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3828. }
  3829. else
  3830. {
  3831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3832. {
  3833. tempIndex = 2;
  3834. }
  3835. else
  3836. {
  3837. tempIndex = gun_index;
  3838. }
  3839. for (int index = 0; index < AC_QUANTITY; index++)
  3840. {
  3841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3842. {
  3843. 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
  3844. }
  3845. } // END OF FOR AC_QUANTITY
  3846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3847. }
  3848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3851. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3854. //SoC
  3855. //idx_sample=5;
  3856. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3857. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3858. {
  3859. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3860. {
  3861. tempIndex = ((gun_index==2) ? 1: 0);
  3862. }
  3863. else
  3864. {
  3865. tempIndex = gun_index;
  3866. }
  3867. if(gunType[gun_index] == 'J')
  3868. {
  3869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3870. {
  3871. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3872. {
  3873. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3874. }
  3875. }
  3876. }
  3877. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3878. {
  3879. for (int index = 0; index < CCS_QUANTITY; index++)
  3880. {
  3881. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3882. {
  3883. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3884. }
  3885. }
  3886. }
  3887. else if(gunType[gun_index] == 'G')
  3888. {
  3889. for (int index = 0; index < GB_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3892. {
  3893. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3894. }
  3895. }
  3896. }
  3897. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3899. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3903. } // END FOR DC CASE
  3904. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3905. {
  3906. 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\"}]}]}]"
  3907. ,gun_index+1
  3908. ,MESSAGE_TYPE_CALL
  3909. ,guid
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3915. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3958. );
  3959. }
  3960. else
  3961. {
  3962. 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\"}]}]}]"
  3963. ,gun_index+1
  3964. ,MESSAGE_TYPE_CALL
  3965. ,guid
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3971. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4007. );
  4008. }
  4009. #if 1 // for TempStopTransaction
  4010. //Delete TempStopTransaction
  4011. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  4012. {
  4013. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  4014. }
  4015. #endif
  4016. #if 1
  4017. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4018. if(hashmap_operation(0, guid, tempdata) == 1)
  4019. {
  4020. result = PASS;
  4021. DEBUG_INFO("StopTransaction mapitem pass\n");
  4022. }
  4023. #endif
  4024. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4025. /*
  4026. if(GetTransactionQueueNum() == 1)
  4027. {
  4028. LWS_Send(queuedata+2);
  4029. }*/
  4030. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4031. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4032. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4033. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4034. {
  4035. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4036. }
  4037. //for test
  4038. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4039. return result;
  4040. }
  4041. int sendMeterValuesRequest(int gun_index)
  4042. {
  4043. mtrace();
  4044. int result = FAIL;
  4045. // char message[1500]={0};
  4046. char guid[37]={0};
  4047. //int idx_sample=0;
  4048. //int length = 0;
  4049. char tempdata[65]={0};
  4050. int tempIndex = 0;
  4051. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4052. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4053. /*
  4054. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0) && (ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4055. {
  4056. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4057. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4058. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4059. return result;
  4060. }*/
  4061. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4062. {
  4063. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4064. }
  4065. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4066. //set value
  4067. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4068. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4069. random_uuid(guid);
  4070. //UTC Date time
  4071. struct timeval tmnow;
  4072. struct tm *tm;
  4073. char buf[28];//, usec_buf[6];
  4074. gettimeofday(&tmnow, NULL);
  4075. time_t t;
  4076. t = time(NULL);
  4077. /*UTC time and date*/
  4078. tm = gmtime(&t);
  4079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4080. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4081. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4082. //idx_sample=0;
  4083. //********************************(1)Current.Export************************************************/
  4084. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4085. if(gunType[gun_index] == 'J')
  4086. {
  4087. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4088. {
  4089. tempIndex = ((gun_index==2) ? 1: 0);
  4090. }
  4091. else
  4092. {
  4093. tempIndex = gun_index;
  4094. }
  4095. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4096. {
  4097. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4098. {
  4099. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4100. }
  4101. }
  4102. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4103. }
  4104. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4105. {
  4106. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4107. {
  4108. tempIndex = ((gun_index==2) ? 1: 0);
  4109. }
  4110. else
  4111. {
  4112. tempIndex = gun_index;
  4113. }
  4114. for (int index = 0; index < CCS_QUANTITY; index++)
  4115. {
  4116. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4117. {
  4118. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4119. }
  4120. }
  4121. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4122. }
  4123. else if(gunType[gun_index] == 'G')
  4124. {
  4125. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4126. {
  4127. tempIndex = ((gun_index==2) ? 1: 0);
  4128. }
  4129. else
  4130. {
  4131. tempIndex = gun_index;
  4132. }
  4133. for (int index = 0; index < GB_QUANTITY; index++)
  4134. {
  4135. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4136. {
  4137. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4138. }
  4139. }
  4140. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4141. }
  4142. else
  4143. {
  4144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4145. {
  4146. tempIndex = 2;
  4147. }
  4148. else
  4149. {
  4150. tempIndex = gun_index;
  4151. }
  4152. for (int index = 0; index < AC_QUANTITY; index++)
  4153. {
  4154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4155. {
  4156. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4157. }
  4158. }
  4159. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4160. }
  4161. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4162. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4163. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4164. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4165. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4166. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4167. //idx_sample=1;
  4168. //********************************(2)Energy.Active.Import.Register ************************************************/
  4169. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4170. if(gunType[gun_index] == 'J')
  4171. {
  4172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4173. {
  4174. tempIndex = ((gun_index==2) ? 1: 0);
  4175. }
  4176. else
  4177. {
  4178. tempIndex = gun_index;
  4179. }
  4180. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4181. {
  4182. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4183. {
  4184. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4185. }
  4186. }
  4187. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4188. }
  4189. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4190. {
  4191. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4192. {
  4193. tempIndex = ((gun_index==2) ? 1: 0);
  4194. }
  4195. else
  4196. {
  4197. tempIndex = gun_index;
  4198. }
  4199. for (int index = 0; index < CCS_QUANTITY; index++)
  4200. {
  4201. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4202. {
  4203. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4204. }
  4205. }
  4206. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4207. }
  4208. else if(gunType[gun_index] == 'G')
  4209. {
  4210. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4211. {
  4212. tempIndex = ((gun_index==2) ? 1: 0);
  4213. }
  4214. else
  4215. {
  4216. tempIndex = gun_index;
  4217. }
  4218. for (int index = 0; index < GB_QUANTITY; index++)
  4219. {
  4220. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4221. {
  4222. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4223. }
  4224. }
  4225. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4226. }
  4227. else
  4228. {
  4229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4230. {
  4231. tempIndex = 2;
  4232. }
  4233. else
  4234. {
  4235. tempIndex = gun_index;
  4236. }
  4237. for (int index = 0; index < AC_QUANTITY; index++)
  4238. {
  4239. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4240. {
  4241. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4242. }
  4243. }
  4244. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4245. }
  4246. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4247. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4248. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4249. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4250. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4251. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4252. //idx_sample=2;
  4253. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4254. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4255. if(gunType[gun_index] == 'J')
  4256. {
  4257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4258. {
  4259. tempIndex = ((gun_index==2) ? 1: 0);
  4260. }
  4261. else
  4262. {
  4263. tempIndex = gun_index;
  4264. }
  4265. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4266. {
  4267. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4268. {
  4269. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4270. }
  4271. } // END OF FOR CHAdeMO_QUANTITY
  4272. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4273. }
  4274. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4275. {
  4276. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4277. {
  4278. tempIndex = ((gun_index==2) ? 1: 0);
  4279. }
  4280. else
  4281. {
  4282. tempIndex = gun_index;
  4283. }
  4284. for (int index = 0; index < CCS_QUANTITY; index++)
  4285. {
  4286. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4287. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4288. {
  4289. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4290. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4291. }
  4292. } // END OF CCS_QUANTITY
  4293. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4294. }
  4295. else if(gunType[gun_index] == 'G')
  4296. {
  4297. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4298. {
  4299. tempIndex = ((gun_index==2) ? 1: 0);
  4300. }
  4301. else
  4302. {
  4303. tempIndex = gun_index;
  4304. }
  4305. for (int index = 0; index < GB_QUANTITY; index++)
  4306. {
  4307. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4308. {
  4309. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4310. }
  4311. } // END OF GB_QUANTITY
  4312. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4313. }
  4314. else
  4315. {
  4316. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4317. {
  4318. tempIndex = 2;
  4319. }
  4320. else
  4321. {
  4322. tempIndex = gun_index;
  4323. }
  4324. for (int index = 0; index < AC_QUANTITY; index++)
  4325. {
  4326. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4327. {
  4328. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4329. }
  4330. }
  4331. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4332. }
  4333. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4334. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4335. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4336. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4337. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4338. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4339. //idx_sample=3;
  4340. //********************************(4)Power.Active.Export************************************************/
  4341. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4342. if(gunType[gun_index] == 'J')
  4343. {
  4344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4345. {
  4346. tempIndex = ((gun_index==2) ? 1: 0);
  4347. }
  4348. else
  4349. {
  4350. tempIndex = gun_index;
  4351. }
  4352. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4353. {
  4354. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4355. {
  4356. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4357. }
  4358. } // END OF FOR
  4359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4360. }
  4361. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4362. {
  4363. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4364. {
  4365. tempIndex = ((gun_index==2) ? 1: 0);
  4366. }
  4367. else
  4368. {
  4369. tempIndex = gun_index;
  4370. }
  4371. for (int index = 0; index < CCS_QUANTITY; index++)
  4372. {
  4373. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4374. {
  4375. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4376. }
  4377. }
  4378. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4379. }
  4380. else if(gunType[gun_index] == 'G')
  4381. {
  4382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4383. {
  4384. tempIndex = ((gun_index==2) ? 1: 0);
  4385. }
  4386. else
  4387. {
  4388. tempIndex = gun_index;
  4389. }
  4390. for (int index = 0; index < GB_QUANTITY; index++)
  4391. {
  4392. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4393. {
  4394. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4395. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4396. }
  4397. }
  4398. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4399. }
  4400. else
  4401. {
  4402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4403. {
  4404. tempIndex = 2;
  4405. }
  4406. else
  4407. {
  4408. tempIndex = gun_index;
  4409. }
  4410. for (int index = 0; index < AC_QUANTITY; index++)
  4411. {
  4412. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4413. {
  4414. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4415. }
  4416. }
  4417. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4418. }
  4419. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4420. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4421. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4422. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4423. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4425. //idx_sample=4;
  4426. //***********************************************(5)VOLTAGE******************************************************/
  4427. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4428. if(gunType[gun_index] == 'J')
  4429. {
  4430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4431. {
  4432. tempIndex = ((gun_index==2) ? 1: 0);
  4433. }
  4434. else
  4435. {
  4436. tempIndex = gun_index;
  4437. }
  4438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4439. {
  4440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4441. {
  4442. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4443. }
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4446. }
  4447. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4448. {
  4449. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4450. {
  4451. tempIndex = ((gun_index==2) ? 1: 0);
  4452. }
  4453. else
  4454. {
  4455. tempIndex = gun_index;
  4456. }
  4457. for (int index = 0; index < CCS_QUANTITY; index++)
  4458. {
  4459. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4460. {
  4461. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4462. }
  4463. }
  4464. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4465. }
  4466. else if(gunType[gun_index] == 'G')
  4467. {
  4468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4469. {
  4470. tempIndex = ((gun_index==2) ? 1: 0);
  4471. }
  4472. else
  4473. {
  4474. tempIndex = gun_index;
  4475. }
  4476. for (int index = 0; index < GB_QUANTITY; index++)
  4477. {
  4478. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4479. {
  4480. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4481. }
  4482. }
  4483. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4484. }
  4485. else
  4486. {
  4487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4488. {
  4489. tempIndex = 2;
  4490. }
  4491. else
  4492. {
  4493. tempIndex = gun_index;
  4494. }
  4495. for (int index = 0; index < AC_QUANTITY; index++)
  4496. {
  4497. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4498. {
  4499. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4500. }
  4501. }
  4502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4503. }
  4504. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4505. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4506. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4507. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4509. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4510. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4511. {
  4512. //idx_sample=5;
  4513. //sampledValue = NULL;
  4514. //***********************************************(6)SOC******************************************************/
  4515. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4516. {
  4517. tempIndex = ((gun_index==2) ? 1: 0);
  4518. }
  4519. else
  4520. {
  4521. tempIndex = gun_index;
  4522. }
  4523. if(gunType[gun_index] == 'J')
  4524. {
  4525. //tempIndex = ((gun_index==2) ? 1: 0);
  4526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4527. {
  4528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4529. {
  4530. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4531. }
  4532. }
  4533. }
  4534. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4535. {
  4536. //tempIndex = ((gun_index==2) ? 1: 0);
  4537. for (int index = 0; index < CCS_QUANTITY; index++)
  4538. {
  4539. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4540. {
  4541. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4542. }
  4543. }
  4544. }
  4545. else if(gunType[gun_index] == 'G')
  4546. {
  4547. //tempIndex = ((gun_index==2) ? 1: 0);
  4548. for (int index = 0; index < GB_QUANTITY; index++)
  4549. {
  4550. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4551. {
  4552. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4553. }
  4554. }
  4555. }
  4556. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4557. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4558. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4559. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4560. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4562. }
  4563. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4564. {
  4565. 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\"}]}]}]"
  4566. ,gun_index + 1
  4567. ,MESSAGE_TYPE_CALL
  4568. ,guid
  4569. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4570. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4571. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4614. );
  4615. }
  4616. else
  4617. {
  4618. 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\"}]}]}]"
  4619. ,gun_index + 1
  4620. ,MESSAGE_TYPE_CALL
  4621. ,guid
  4622. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4623. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4624. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4633. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4634. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4635. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4636. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4637. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4638. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4639. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4640. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4641. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4642. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4643. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4644. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4645. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4646. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4647. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4648. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4649. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4650. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4651. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4652. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4653. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4654. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4655. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4656. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4657. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4658. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4659. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4660. );
  4661. }
  4662. // Put request guid to hash map
  4663. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4664. 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*/)
  4665. {
  4666. result = PASS;
  4667. DEBUG_INFO("MeterValues mapitem pass\n");
  4668. }
  4669. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4670. /*
  4671. if(GetTransactionQueueNum() == 1)
  4672. {
  4673. LWS_Send(queuedata +2);
  4674. }*/
  4675. return result;
  4676. }
  4677. //==========================================
  4678. // send confirm routine
  4679. //==========================================
  4680. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4681. {
  4682. mtrace();
  4683. int result = FAIL;
  4684. char message[100]={0};
  4685. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4686. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4687. LWS_Send(message);
  4688. result = TRUE;
  4689. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4690. return result;
  4691. }
  4692. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4693. {
  4694. mtrace();
  4695. int result = FAIL;
  4696. char message[100]={0};
  4697. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4698. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4699. LWS_Send(message);
  4700. result = TRUE;
  4701. return result;
  4702. }
  4703. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4704. {
  4705. mtrace();
  4706. int result = FAIL;
  4707. char message[100]={0};
  4708. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4709. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4710. LWS_Send(message);
  4711. result = TRUE;
  4712. return result;
  4713. }
  4714. int sendClearCacheConfirmation(char *uuid,char *payload)
  4715. {
  4716. mtrace();
  4717. int result = FAIL;
  4718. char message[500]={0};
  4719. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4720. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4721. LWS_Send(message);
  4722. return result;
  4723. }
  4724. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4725. {
  4726. mtrace();
  4727. int result = FAIL;
  4728. char message[500]={0};
  4729. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4730. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4731. LWS_Send(message);
  4732. return result;
  4733. }
  4734. int sendDataTransferConfirmation(char *uuid,char *payload)
  4735. {
  4736. mtrace();
  4737. char statusStr[20]={0};
  4738. char dataStr[10]={0};
  4739. char sstr[20]={0};
  4740. int c = 0;
  4741. char *loc;
  4742. int result = FAIL;
  4743. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4744. /**********************status**************************/
  4745. loc = strstr(payload, "status");
  4746. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4747. c = 0;
  4748. while (loc[3+strlen("status")+c] != '\"')
  4749. {
  4750. sstr[c] = loc[3+strlen("status")+c];
  4751. c++;
  4752. }
  4753. sstr[c] = '\0';
  4754. strcpy(statusStr, sstr);
  4755. /**********************data**************************/
  4756. loc = strstr(payload, "data");
  4757. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4758. c = 0;
  4759. while (loc[3+strlen("data")+c] != '\"')
  4760. {
  4761. sstr[c] = loc[3+strlen("data")+c];
  4762. c++;
  4763. }
  4764. sstr[c] = '\0';
  4765. strcpy(dataStr, sstr);
  4766. return result;
  4767. }
  4768. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4769. {
  4770. mtrace();
  4771. int result = FAIL;
  4772. char message[1000]={0};
  4773. int CompositeScheduleIndex = 0;
  4774. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4775. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4776. if(nPeriod == 0)
  4777. {
  4778. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4779. {
  4780. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4781. ,MESSAGE_TYPE_CALLRESULT
  4782. ,uuid
  4783. ,payload
  4784. ,connectorIdInt);
  4785. }
  4786. else
  4787. {
  4788. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4789. ,MESSAGE_TYPE_CALLRESULT
  4790. ,uuid
  4791. ,payload
  4792. ,connectorIdInt
  4793. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4794. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4795. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4796. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4797. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4798. }
  4799. }
  4800. else
  4801. {
  4802. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4803. ,MESSAGE_TYPE_CALLRESULT
  4804. ,uuid
  4805. ,payload
  4806. ,connectorIdInt
  4807. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4808. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4809. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4810. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4811. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4812. {
  4813. if (idx_sample == 0)
  4814. {
  4815. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4816. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4817. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4818. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4819. }
  4820. else
  4821. {
  4822. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4823. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4824. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4825. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4826. }
  4827. }
  4828. sprintf(message + strlen(message), "]}}]");
  4829. }
  4830. LWS_Send(message);
  4831. result = TRUE;
  4832. return result;
  4833. }
  4834. int sendGetConfigurationConfirmation(char *uuid)
  4835. {
  4836. mtrace();
  4837. int result = FAIL;
  4838. int MaxKeySupported = 0;
  4839. int sentConfigurationNumber= 0;
  4840. int sentunConfigurationNumber= 0;
  4841. char message[4000]={0};
  4842. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4843. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4844. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4845. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4846. ,MESSAGE_TYPE_CALLRESULT
  4847. ,uuid );
  4848. //configuration key
  4849. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4850. {
  4851. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4852. {
  4853. if (sentConfigurationNumber == 0)
  4854. {
  4855. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4856. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4857. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4858. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4859. }
  4860. else
  4861. {
  4862. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4863. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4864. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4865. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4866. }
  4867. sentConfigurationNumber = sentConfigurationNumber + 1;
  4868. }
  4869. }
  4870. sprintf(message + strlen(message), "]");
  4871. if(UnknownKeynum != 0)
  4872. {
  4873. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4874. //unkown key
  4875. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4876. {
  4877. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4878. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4879. if(sentunConfigurationNumber == 0)
  4880. {
  4881. sprintf(message + strlen(message), "\"%s\""
  4882. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4883. }
  4884. else
  4885. {
  4886. sprintf(message + strlen(message), ",\"%s\""
  4887. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4888. }
  4889. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4890. }
  4891. sprintf(message + strlen(message), "]");
  4892. }
  4893. sprintf(message + strlen(message), "}]");
  4894. LWS_Send(message);
  4895. return result;
  4896. }
  4897. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4898. {
  4899. mtrace();
  4900. int result = FAIL;
  4901. char message[400]={0};
  4902. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4903. if(strcmp(payload,"")==0)
  4904. {
  4905. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4906. }
  4907. else
  4908. {
  4909. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4910. }
  4911. LWS_Send(message);
  4912. result = TRUE;
  4913. return result;
  4914. }
  4915. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4916. {
  4917. mtrace();
  4918. int result = FAIL;
  4919. char message[80]={0};
  4920. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4921. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4922. LWS_Send(message);
  4923. result = TRUE;
  4924. return result;
  4925. }
  4926. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4927. {
  4928. mtrace();
  4929. int result = FAIL;
  4930. char message[80]={0};
  4931. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4932. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4933. LWS_Send(message);
  4934. result = TRUE;
  4935. return result;
  4936. }
  4937. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4938. {
  4939. mtrace();
  4940. int result = FAIL;
  4941. char message[80]={0};
  4942. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4943. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4944. LWS_Send(message);
  4945. result = TRUE;
  4946. return result;
  4947. }
  4948. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4949. {
  4950. mtrace();
  4951. int result = FAIL;
  4952. char message[80]={0};
  4953. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4954. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4955. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4956. LWS_Send(message);
  4957. result = TRUE;
  4958. return result;
  4959. }
  4960. int sendResetConfirmation(char *uuid,char *payload)
  4961. {
  4962. mtrace();
  4963. int result = FAIL;
  4964. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4965. char message[80]={0};
  4966. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4967. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4968. LWS_Send(message);
  4969. result = TRUE;
  4970. return result;
  4971. }
  4972. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4973. {
  4974. mtrace();
  4975. int result = FAIL;
  4976. char message[500]={0};
  4977. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4978. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4979. LWS_Send(message);
  4980. result = TRUE;
  4981. return result;
  4982. }
  4983. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4984. {
  4985. mtrace();
  4986. int result = FAIL;
  4987. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4988. char message[80]={0};
  4989. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4990. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4991. LWS_Send(message);
  4992. result = TRUE;
  4993. return result;
  4994. }
  4995. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4996. {
  4997. mtrace();
  4998. int result = FAIL;
  4999. char message[80]={0};
  5000. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5002. LWS_Send(message);
  5003. result = TRUE;
  5004. return result;
  5005. }
  5006. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5007. {
  5008. mtrace();
  5009. int result = FAIL;
  5010. char message[80]={0};
  5011. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5012. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5013. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5014. LWS_Send(message);
  5015. result = TRUE;
  5016. return result;
  5017. }
  5018. int sendUpdateFirmwareConfirmation(char *uuid)
  5019. {
  5020. mtrace();
  5021. int result = FAIL;
  5022. char message[60]={0};
  5023. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5024. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5025. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5026. LWS_Send(message);
  5027. result = TRUE;
  5028. return result;
  5029. }
  5030. //==========================================
  5031. // send CallError routine
  5032. //==========================================
  5033. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5034. {
  5035. mtrace();
  5036. char message[220]={0};
  5037. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5038. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5039. LWS_Send(message);
  5040. }
  5041. //==========================================
  5042. // Handle server request routine Start
  5043. //==========================================
  5044. int handleCancelReservationRequest(char *uuid, char *payload)
  5045. {
  5046. mtrace();
  5047. int result = FAIL;
  5048. int gunNO = 0;
  5049. int reservationIdInt =0;
  5050. char comfirmstr[20];
  5051. DEBUG_INFO("handleCancelReservationRequest...\n");
  5052. json_object *CancelReservation;
  5053. CancelReservation = json_tokener_parse(payload);
  5054. if(!is_error(CancelReservation))
  5055. {
  5056. // Required data
  5057. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5058. }
  5059. json_object_put(CancelReservation);
  5060. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5061. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5062. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5063. //check Transaction active
  5064. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5065. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5066. {
  5067. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5068. {
  5069. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5070. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5071. if(gunType[2] == 'J')
  5072. {
  5073. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5074. }
  5075. else
  5076. {
  5077. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5078. }
  5079. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5080. goto end;
  5081. }
  5082. }
  5083. for (int index = 0; index < CCS_QUANTITY; index++)
  5084. {
  5085. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5086. {
  5087. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5088. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5089. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5090. {
  5091. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5092. }
  5093. else
  5094. {
  5095. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5096. }
  5097. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5098. goto end;
  5099. }
  5100. }
  5101. for (int index = 0; index < GB_QUANTITY; index++)
  5102. {
  5103. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5104. {
  5105. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5106. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5107. if(gunType[2] == 'G')
  5108. {
  5109. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5110. }
  5111. else
  5112. {
  5113. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5114. }
  5115. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5116. goto end;
  5117. }
  5118. }
  5119. for (int index = 0; index < AC_QUANTITY; index++)
  5120. {
  5121. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5122. {
  5123. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5124. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5125. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5126. {
  5127. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5128. }
  5129. else
  5130. {
  5131. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5132. }
  5133. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5134. goto end;
  5135. }
  5136. }
  5137. //The reservationId does NOT match the reservationId
  5138. sendCancelReservationConfirmation(uuid, comfirmstr);
  5139. end:
  5140. // Fill in ocpp packet uuid
  5141. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5142. return result;
  5143. }
  5144. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5145. {
  5146. mtrace();
  5147. int result = FAIL;
  5148. int gunIndex = 0;
  5149. char typeStr[16]={0};
  5150. char comfirmstr[20];
  5151. int specificId = FALSE;
  5152. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5153. json_object *ChangeAvailability;
  5154. ChangeAvailability = json_tokener_parse(payload);
  5155. if(!is_error(ChangeAvailability))
  5156. {
  5157. // Required data
  5158. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5159. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5160. }
  5161. json_object_put(ChangeAvailability);
  5162. if(gunIndex != 0)
  5163. {
  5164. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5165. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5166. }
  5167. else
  5168. {
  5169. for(int i=0; i < gunTotalNumber; i++)
  5170. {
  5171. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5172. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5173. }
  5174. }
  5175. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5176. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5177. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5178. {
  5179. specificId = TRUE;
  5180. }
  5181. if(specificId == FALSE)
  5182. goto end;
  5183. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5184. {
  5185. //----------------------gunIndex is 0 ------------------------------------------------//
  5186. if(gunIndex == 0)
  5187. {
  5188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5189. {
  5190. for(int i=0; i < gunTotalNumber; i++)
  5191. {
  5192. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5193. {
  5194. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5195. {
  5196. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5197. {
  5198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5199. goto end;
  5200. }
  5201. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5202. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5203. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5204. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5205. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5206. {
  5207. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5208. goto end;
  5209. }
  5210. }
  5211. }//END FOR CHAdeMO_QUANTITY
  5212. for (int index = 0; index < CCS_QUANTITY; index++)
  5213. {
  5214. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5215. {
  5216. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5217. {
  5218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5219. goto end;
  5220. }
  5221. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5222. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5223. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5224. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5225. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5226. {
  5227. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5228. goto end;
  5229. }
  5230. }
  5231. }//END FOR CCS_QUANTITY
  5232. for (int index = 0; index < GB_QUANTITY; index++)
  5233. {
  5234. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5235. {
  5236. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5237. {
  5238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5239. goto end;
  5240. }
  5241. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5242. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5243. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5244. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5245. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5246. {
  5247. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5248. goto end;
  5249. }
  5250. }
  5251. }// END FOR GB_QUANTITY
  5252. for (int index = 0; index < AC_QUANTITY; index++)
  5253. {
  5254. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5255. {
  5256. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5257. {
  5258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5259. goto end;
  5260. }
  5261. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5262. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5263. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5264. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5265. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5266. {
  5267. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5268. goto end;
  5269. }
  5270. }
  5271. }//END FOR AC_QUANTITY
  5272. }// END FOR gunTotalNumber
  5273. }
  5274. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5275. {
  5276. for(int i=0; i < gunTotalNumber; i++)
  5277. {
  5278. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5279. {
  5280. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5281. goto end;
  5282. }
  5283. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5284. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5285. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5286. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5287. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5288. {
  5289. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5290. goto end;
  5291. }
  5292. }
  5293. }
  5294. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5295. goto end;
  5296. }
  5297. //----------------------gunIndex is not 0 ------------------------------------------------//
  5298. //check Transaction active
  5299. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5300. {
  5301. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5302. {
  5303. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5304. {
  5305. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5306. goto end;
  5307. }
  5308. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5310. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5311. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5312. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5313. {
  5314. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5315. goto end;
  5316. }
  5317. else
  5318. {
  5319. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5320. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5321. goto end;
  5322. }
  5323. }
  5324. }//END FOR CHAdeMO_QUANTITY
  5325. for (int index = 0; index < CCS_QUANTITY; index++)
  5326. {
  5327. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5328. {
  5329. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5330. {
  5331. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5332. goto end;
  5333. }
  5334. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5335. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5336. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5337. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5338. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5339. {
  5340. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5341. goto end;
  5342. }
  5343. else
  5344. {
  5345. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5346. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5347. goto end;
  5348. }
  5349. }
  5350. }//END FOR CCS_QUANTITY
  5351. for (int index = 0; index < GB_QUANTITY; index++)
  5352. {
  5353. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5354. {
  5355. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5356. {
  5357. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5358. goto end;
  5359. }
  5360. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5361. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5362. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5363. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5364. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5365. {
  5366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5367. goto end;
  5368. }
  5369. else
  5370. {
  5371. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5372. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5373. goto end;
  5374. }
  5375. }
  5376. }// END FOR GB_QUANTITY
  5377. for (int index = 0; index < AC_QUANTITY; index++)
  5378. {
  5379. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5380. {
  5381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5382. {
  5383. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5384. goto end;
  5385. }
  5386. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5387. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5388. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5389. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5390. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5391. {
  5392. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5393. goto end;
  5394. }
  5395. else
  5396. {
  5397. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5398. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5399. goto end;
  5400. }
  5401. }
  5402. }//END FOR AC_QUANTITY
  5403. }//END FOR AvailabilityTypeStr[Inoperative]
  5404. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5405. {
  5406. //----------------------gunIndex is 0 ------------------------------------------------//
  5407. if(gunIndex == 0)
  5408. {
  5409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5410. {
  5411. for(int i=0; i < gunTotalNumber; i++)
  5412. {
  5413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5414. {
  5415. 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
  5416. {
  5417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5418. goto end;
  5419. }
  5420. }//END FOR CHAdeMO_QUANTITY
  5421. for (int index = 0; index < CCS_QUANTITY; index++)
  5422. {
  5423. 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
  5424. {
  5425. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5426. goto end;
  5427. }
  5428. }//END FOR CCS_QUANTITY
  5429. for (int index = 0; index < GB_QUANTITY; index++)
  5430. {
  5431. 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
  5432. {
  5433. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5434. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5435. goto end;
  5436. }
  5437. }// END FOR GB_QUANTITY
  5438. for (int index = 0; index < AC_QUANTITY; index++)
  5439. {
  5440. 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
  5441. {
  5442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5443. goto end;
  5444. }
  5445. }//END FOR CHAdeMO_QUANTITY
  5446. }// END FOR gunTotalNumber
  5447. }
  5448. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5449. {
  5450. for(int i=0; i < gunTotalNumber; i++)
  5451. {
  5452. for (int index = 0; index < AC_QUANTITY; index++)
  5453. {
  5454. 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
  5455. {
  5456. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5457. goto end;
  5458. }
  5459. }//END FOR CHAdeMO_QUANTITY
  5460. } // END FOR gunTotalNumber
  5461. }
  5462. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5463. goto end;
  5464. }
  5465. //----------------------gunIndex is not 0 ------------------------------------------------//
  5466. //check Transaction active
  5467. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5468. {
  5469. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5470. {
  5471. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5472. goto end;
  5473. }
  5474. }//END FOR CHAdeMO_QUANTITY
  5475. for (int index = 0; index < CCS_QUANTITY; index++)
  5476. {
  5477. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5478. {
  5479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5480. goto end;
  5481. }
  5482. }//END FOR CCS_QUANTITY
  5483. for (int index = 0; index < GB_QUANTITY; index++)
  5484. {
  5485. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5486. {
  5487. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5488. goto end;
  5489. }
  5490. }// END FOR GB_QUANTITY
  5491. for (int index = 0; index < AC_QUANTITY; index++)
  5492. {
  5493. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5494. {
  5495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5496. goto end;
  5497. }
  5498. }//END FOR AC_QUANTITY
  5499. }//END FOR AvailabilityTypeStr[Operative]
  5500. end:
  5501. if(gunIndex != 0)
  5502. {
  5503. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5504. }
  5505. else
  5506. {
  5507. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5508. }
  5509. if(gunIndex != 0)
  5510. {
  5511. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5512. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5513. }
  5514. else
  5515. {
  5516. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5517. {
  5518. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5519. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5520. }
  5521. }
  5522. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5523. return result;
  5524. }
  5525. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5526. {
  5527. mtrace();
  5528. int result = FAIL;
  5529. char keystr[40]={0};
  5530. char valuestr[100]={0};
  5531. char comfirmstr[20]={0};
  5532. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5533. json_object *ChangeConfiguration;
  5534. ChangeConfiguration = json_tokener_parse(payload);
  5535. if(!is_error(ChangeConfiguration))
  5536. {
  5537. // Required data
  5538. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5539. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5540. }
  5541. json_object_put(ChangeConfiguration);
  5542. if((uuid==NULL) || (payload ==NULL) )
  5543. {
  5544. DEBUG_ERROR("Payload is null\n");
  5545. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5546. }
  5547. else
  5548. {
  5549. int status = setKeyValue(keystr, valuestr);
  5550. switch(status)
  5551. {
  5552. case ConfigurationStatus_Accepted:
  5553. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5554. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5555. StoreConfigurationTable();
  5556. break;
  5557. case ConfigurationStatus_Rejected:
  5558. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5559. break;
  5560. case RebootRequired:
  5561. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5562. StoreConfigurationTable();
  5563. break;
  5564. case NotSupported:
  5565. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5566. break;
  5567. default:
  5568. break;
  5569. }
  5570. }
  5571. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5572. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5573. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5574. {
  5575. ChageWebSocketPingInterval(atoi(valuestr));
  5576. }
  5577. return result;
  5578. }
  5579. int handleClearCacheRequest(char *uuid, char *payload)
  5580. {
  5581. mtrace();
  5582. int result = FAIL;
  5583. char comfirmstr[20];
  5584. int fd;
  5585. char rmFileCmd[100]={0};
  5586. struct stat stats;
  5587. DEBUG_INFO("handleClearCacheRequest...\n");
  5588. stat("/Storage/OCPP", &stats);
  5589. // Check for directory existence
  5590. if (S_ISDIR(stats.st_mode) == 1)
  5591. {}
  5592. else
  5593. {
  5594. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5595. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5596. system(rmFileCmd);
  5597. }
  5598. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5599. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5600. {
  5601. DEBUG_INFO("AuthorizationCache file exist.\n");
  5602. }
  5603. else
  5604. {
  5605. DEBUG_INFO("AuthorizationCache file not exist\n");
  5606. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5607. if(log == NULL)
  5608. {
  5609. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5610. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5611. goto end;
  5612. }
  5613. else
  5614. {
  5615. fclose(log);
  5616. }
  5617. }
  5618. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5619. {
  5620. DEBUG_INFO("open AuthorizationCache file failed\n");
  5621. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5622. }
  5623. else
  5624. {
  5625. DEBUG_INFO("open AuthorizationCache file successful\n");
  5626. ftruncate(fd,0);
  5627. lseek(fd,0,SEEK_SET);
  5628. close(fd);
  5629. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5630. }
  5631. end:
  5632. sendClearCacheConfirmation(uuid, comfirmstr);
  5633. return result;
  5634. }
  5635. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5636. {
  5637. mtrace();
  5638. int result = FAIL;
  5639. int resultRename;
  5640. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5641. char chargingProfilePurposeStr[26]={0};
  5642. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5643. char tempchargingProfilePurposeStr[26]={0};
  5644. char sstr[160]={0};
  5645. char str[100]={0};
  5646. int c = 0;
  5647. char *loc;
  5648. char fname[200]={0};
  5649. char comfirmstr[20]={0};
  5650. char word[1600]={0};
  5651. int clearflag = FALSE;
  5652. int chargingProfileIdIsNULL = FALSE;
  5653. int connectorIsNULL = FALSE;
  5654. int chargingProfilePurposeIsNULL = FALSE;
  5655. int stackLevelIsNULL = FALSE;
  5656. //int GotoEnd = FALSE;
  5657. FILE *fptr1, *fptr2;
  5658. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5659. int n_chargingProfile=0;
  5660. int isEmptyFile = FALSE;
  5661. char sLineWord[1600]={0};
  5662. char chargingProfiles[10][100]={0};
  5663. int ChargeProfileCount = 0;
  5664. char ch;
  5665. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5666. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5667. json_object *ClearChargingProfile;
  5668. ClearChargingProfile = json_tokener_parse(payload);
  5669. if(!is_error(ClearChargingProfile))
  5670. {
  5671. // Optional data
  5672. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5673. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5674. else
  5675. chargingProfileIdIsNULL = TRUE;
  5676. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5677. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5678. else
  5679. connectorIsNULL = TRUE;
  5680. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5681. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5682. else
  5683. chargingProfilePurposeIsNULL = TRUE;
  5684. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5685. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5686. else
  5687. stackLevelIsNULL = TRUE;
  5688. }
  5689. json_object_put(ClearChargingProfile);
  5690. if(connectorIsNULL == FALSE)
  5691. {
  5692. switch(connectorIdInt)
  5693. {
  5694. case 0:
  5695. if(chargingProfilePurposeIsNULL == TRUE)
  5696. {
  5697. int l = 0;
  5698. strcpy(fname, ChargePointMaxProfile_JSON);
  5699. if((access(fname,F_OK))!=-1)
  5700. {
  5701. strcpy(chargingProfiles[l], fname);
  5702. l = l + 1;
  5703. }
  5704. strcpy(fname, TxDefaultProfile_0_JSON);
  5705. if((access(fname,F_OK))!=-1)
  5706. {
  5707. strcpy(chargingProfiles[l], fname);
  5708. l = l + 1;
  5709. }
  5710. ChargeProfileCount = l;
  5711. }
  5712. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5713. {
  5714. strcpy(fname, ChargePointMaxProfile_JSON);
  5715. if((access(fname,F_OK))!=-1)
  5716. {
  5717. strcpy(chargingProfiles[0], fname);
  5718. ChargeProfileCount = 1;
  5719. }
  5720. }
  5721. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5722. {
  5723. strcpy(fname, TxDefaultProfile_0_JSON);
  5724. if((access(fname,F_OK))!=-1)
  5725. {
  5726. strcpy(chargingProfiles[0], fname);
  5727. ChargeProfileCount = 1;
  5728. }
  5729. }
  5730. break;
  5731. default:
  5732. if(chargingProfilePurposeIsNULL == TRUE)
  5733. {
  5734. int m = 0;
  5735. memset(fname, 0, ARRAY_SIZE(fname));
  5736. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5737. if((access(fname,F_OK))!=-1)
  5738. {
  5739. strcpy(chargingProfiles[m], fname);
  5740. m = m + 1;
  5741. }
  5742. memset(fname, 0, ARRAY_SIZE(fname));
  5743. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5744. if((access(fname,F_OK))!=-1)
  5745. {
  5746. strcpy(chargingProfiles[m], fname);
  5747. m = m + 1;
  5748. }
  5749. ChargeProfileCount = m;
  5750. }
  5751. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5752. {
  5753. //strcpy(fname, TxDefaultProfile_1_JSON);
  5754. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5755. if((access(fname,F_OK))!=-1)
  5756. {
  5757. strcpy(chargingProfiles[0], fname);
  5758. ChargeProfileCount = 1;
  5759. }
  5760. }
  5761. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5762. {
  5763. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5764. if((access(fname,F_OK))!=-1)
  5765. {
  5766. strcpy(chargingProfiles[0], fname);
  5767. ChargeProfileCount = 1;
  5768. }
  5769. //strcpy(fname, TxProfile_1_JSON);
  5770. }
  5771. //strcpy(fname, ChargePointMaxProfile_JSON );
  5772. break;
  5773. }
  5774. }
  5775. else // Check all Charging Profiles
  5776. {
  5777. int i = 0;
  5778. char fnametemp[200]={0};
  5779. ChargeProfileCount = 0;
  5780. //Check ChargePointMaxProfile.json exit
  5781. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5782. {
  5783. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5784. i = i + 1;
  5785. }
  5786. //Check TxDefaultProfile_0.json exit
  5787. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5788. {
  5789. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5790. i = i + 1;
  5791. }
  5792. //Check TxDefaultProfile_%d.json
  5793. for(int j=1; j <= gunTotalNumber; j++)
  5794. {
  5795. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5796. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5797. if((access(fnametemp,F_OK))!=-1)
  5798. {
  5799. strcpy(chargingProfiles[i], fnametemp);
  5800. i = i + 1;
  5801. }
  5802. }
  5803. //Check TxProfile_%d.json
  5804. for(int j=1; j <= gunTotalNumber; j++)
  5805. {
  5806. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5807. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5808. if((access(fnametemp,F_OK))!=-1)
  5809. {
  5810. strcpy(chargingProfiles[i], fnametemp);
  5811. i = i + 1;
  5812. }
  5813. }
  5814. ChargeProfileCount = i;
  5815. }// End connectorIsNULL is TRUE
  5816. if(ChargeProfileCount == 0)
  5817. {
  5818. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5819. goto end;
  5820. }
  5821. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5822. {
  5823. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5824. goto end;
  5825. }
  5826. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5827. {
  5828. memset(str, 0, ARRAY_SIZE(str));
  5829. // clear temp file
  5830. sprintf(str,"rm -f %s",temp);
  5831. system(str);
  5832. for(int k=0; k < ChargeProfileCount; k++)
  5833. {
  5834. memset(str, 0, ARRAY_SIZE(str));
  5835. //clear file in C
  5836. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5837. system(str);
  5838. }
  5839. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5840. goto end;
  5841. }
  5842. else if(connectorIsNULL == TRUE)
  5843. {
  5844. for(int k=0; k < ChargeProfileCount; k++)
  5845. {
  5846. fptr1 = fopen(chargingProfiles[k], "r");
  5847. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5848. //Check Charging Profile Count
  5849. while(fscanf(fptr1, "%s", word) != EOF)
  5850. {
  5851. //DEBUG_INFO("word=%s\n",word);
  5852. if(strstr(word, "chargingProfileId")!= NULL)
  5853. {
  5854. //DEBUG_INFO("test chargingProfileId \n");
  5855. n_chargingProfile = n_chargingProfile + 1;
  5856. //DEBUG_INFO("chargingProfileId Found\n");
  5857. }
  5858. }
  5859. rewind(fptr1);
  5860. //search Charging Profile Element
  5861. //int i= 0;
  5862. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5863. {
  5864. //------------------------tempconnectorIdInt------------------------//
  5865. loc = strstr(sLineWord, "connectorId");
  5866. c = 0;
  5867. memset(sstr ,0, sizeof(sstr) );
  5868. while (loc[strlen("connectorId")+2+c] != ',')
  5869. {
  5870. sstr[c] = loc[strlen("connectorId")+2+c];
  5871. c++;
  5872. }
  5873. sstr[c] = '\0';
  5874. tempconnectorIdInt = atoi(sstr);
  5875. printf("file's gun number is %d\n", tempconnectorIdInt);
  5876. //--------------------------chargingProfileId--------------------//
  5877. c = 0;
  5878. loc = strstr(sLineWord, "chargingProfileId");
  5879. memset(sstr ,0, ARRAY_SIZE(sstr));
  5880. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5881. {
  5882. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5883. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5884. c++;
  5885. }
  5886. sstr[c] = '\0';
  5887. tempchargingProfileIdInt = atoi(sstr);
  5888. //stackLevel
  5889. c = 0;
  5890. loc = strstr(sLineWord, "stackLevel");
  5891. memset(sstr ,0, ARRAY_SIZE(sstr));
  5892. while (loc[strlen("stackLevel")+2+c] != ',')
  5893. {
  5894. sstr[c] = loc[strlen("stackLevel")+2+c];
  5895. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5896. c++;
  5897. }
  5898. sstr[c] = '\0';
  5899. tempstackLevelInt = atoi(sstr);
  5900. c = 0;
  5901. loc = strstr(sLineWord, "chargingProfilePurpose");
  5902. memset(sstr ,0, ARRAY_SIZE(sstr));
  5903. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5904. {
  5905. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5906. c++;
  5907. }
  5908. sstr[c] = '\0';
  5909. strcpy(tempchargingProfilePurposeStr, sstr);
  5910. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5911. {
  5912. //------- not write to fptr2-------//
  5913. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5914. //clearflag = TRUE;
  5915. }
  5916. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5917. {
  5918. //------- not write to fptr2-------//
  5919. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5920. }
  5921. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5922. {
  5923. //------- not write to fptr2-------//
  5924. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5925. }
  5926. else
  5927. {
  5928. fprintf(fptr2, sLineWord);//writing data into file
  5929. }
  5930. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5931. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5932. if(clearflag == TRUE)
  5933. {
  5934. fclose(fptr1);
  5935. fclose(fptr2);
  5936. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5937. system(str);
  5938. // clear temp file
  5939. sprintf(str,"rm -f %s",temp);
  5940. system(str);
  5941. }
  5942. else
  5943. {
  5944. fclose(fptr1);
  5945. fclose(fptr2);
  5946. memset(str, 0, ARRAY_SIZE(str));
  5947. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5948. system(str);
  5949. resultRename = rename(temp, chargingProfiles[k]);
  5950. if(resultRename == 0)
  5951. {
  5952. DEBUG_INFO("File ChargingProfile renamed successfully");
  5953. }
  5954. else
  5955. {
  5956. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5957. }
  5958. if(comfirmstr[0]== 0)
  5959. {
  5960. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5961. }
  5962. //Check chargingProfile is empty file
  5963. /*------ Read the file ----------------*/
  5964. fptr1=fopen(chargingProfiles[k],"r");
  5965. ch=fgetc(fptr1);
  5966. rewind(fptr1);
  5967. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  5968. if(ch!=EOF)
  5969. {
  5970. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5971. {
  5972. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5973. if(sLineWord[0]=='\0')
  5974. {
  5975. isEmptyFile = TRUE;
  5976. break;
  5977. }
  5978. else
  5979. {
  5980. isEmptyFile = FALSE;
  5981. break;
  5982. }
  5983. }
  5984. }
  5985. fclose(fptr1);
  5986. if(isEmptyFile == TRUE)
  5987. {
  5988. memset(str, 0, ARRAY_SIZE(str));
  5989. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5990. system(str);
  5991. }
  5992. }
  5993. }// End of while(int k=0; k < ChargePointCount; k++)
  5994. }
  5995. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5996. {
  5997. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5998. for(int k=0; k < ChargeProfileCount; k++)
  5999. {
  6000. fptr1 = fopen(chargingProfiles[k], "r");
  6001. fptr2 = fopen(temp, "w+");
  6002. //Check Charging Profile Count
  6003. while(fscanf(fptr1, "%s", word) != EOF)
  6004. {
  6005. //DEBUG_INFO("word=%s\n",word);
  6006. if(strstr(word, "chargingProfileId")!= NULL)
  6007. {
  6008. n_chargingProfile = n_chargingProfile + 1;
  6009. }
  6010. }
  6011. rewind(fptr1);
  6012. //search Charging Profile Element
  6013. //int i= 0;
  6014. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6015. {
  6016. //*************************tempconnectorIdInt*********************************/
  6017. loc = strstr(sLineWord, "connectorId");
  6018. c = 0;
  6019. memset(sstr ,0, ARRAY_SIZE(sstr));
  6020. while (loc[strlen("connectorId")+2+c] != ',')
  6021. {
  6022. sstr[c] = loc[strlen("connectorId")+2+c];
  6023. c++;
  6024. }
  6025. sstr[c] = '\0';
  6026. tempconnectorIdInt = atoi(sstr);
  6027. //chargingProfileId
  6028. c = 0;
  6029. loc = strstr(sLineWord, "chargingProfileId");
  6030. memset(sstr ,0, ARRAY_SIZE(sstr));
  6031. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6032. {
  6033. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6034. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6035. c++;
  6036. }
  6037. sstr[c] = '\0';
  6038. tempchargingProfileIdInt = atoi(sstr);
  6039. //stackLevel
  6040. c = 0;
  6041. loc = strstr(sLineWord, "stackLevel");
  6042. memset(sstr ,0, ARRAY_SIZE(sstr));
  6043. while (loc[strlen("stackLevel")+2+c] != ',')
  6044. {
  6045. sstr[c] = loc[strlen("stackLevel")+2+c];
  6046. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6047. c++;
  6048. }
  6049. sstr[c] = '\0';
  6050. tempstackLevelInt = atoi(sstr);
  6051. c = 0;
  6052. loc = strstr(sLineWord, "chargingProfilePurpose");
  6053. memset(sstr ,0, ARRAY_SIZE(sstr));
  6054. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6055. {
  6056. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6057. c++;
  6058. }
  6059. sstr[c] = '\0';
  6060. strcpy(tempchargingProfilePurposeStr, sstr);
  6061. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6062. {
  6063. //------- not write to fptr2-------//
  6064. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6065. //clearflag = TRUE;
  6066. }
  6067. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6068. {
  6069. //------- not write to fptr2-------//
  6070. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6071. }
  6072. else if(stackLevelIsNULL == TRUE)
  6073. {
  6074. //Clear Whole File
  6075. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6076. clearflag = TRUE;
  6077. break;
  6078. }
  6079. else
  6080. {
  6081. fprintf(fptr2, sLineWord);//writing data into file
  6082. }
  6083. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6084. }
  6085. if(clearflag == TRUE)
  6086. {
  6087. fclose(fptr1);
  6088. fclose(fptr2);
  6089. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6090. system(str);
  6091. // clear temp file
  6092. sprintf(str,"rm -f %s",temp);
  6093. system(str);
  6094. }
  6095. else
  6096. {
  6097. fclose(fptr1);
  6098. fclose(fptr2);
  6099. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6100. system(str);
  6101. resultRename = rename(temp, chargingProfiles[k]);
  6102. if(resultRename == 0)
  6103. {
  6104. DEBUG_INFO("File ChargingProfile renamed successfully");
  6105. }
  6106. else
  6107. {
  6108. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6109. }
  6110. if(comfirmstr[0]== 0)
  6111. {
  6112. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6113. }
  6114. //Check chargingProfile is empty file
  6115. /*------ Read the file ----------------*/
  6116. fptr1=fopen(chargingProfiles[k],"r");
  6117. ch=fgetc(fptr1);
  6118. rewind(fptr1);
  6119. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6120. if(ch!=EOF)
  6121. {
  6122. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6123. {
  6124. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6125. if(sLineWord[0]=='\0')
  6126. {
  6127. isEmptyFile = TRUE;
  6128. break;
  6129. }
  6130. else
  6131. {
  6132. isEmptyFile = FALSE;
  6133. break;
  6134. }
  6135. }
  6136. }
  6137. fclose(fptr1);
  6138. if(isEmptyFile == TRUE)
  6139. {
  6140. memset(str, 0, ARRAY_SIZE(str));
  6141. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6142. system(str);
  6143. }
  6144. /*------- End of reading ---------------*/
  6145. }
  6146. } // while(int k=0; k < ChargeProfileCount; k++)
  6147. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6148. end:
  6149. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6150. return result;
  6151. }
  6152. void createFirmwareVersionByDataTransfer(void)
  6153. {
  6154. json_object *FirmwareDataTransfer = json_object_new_object();
  6155. // AC & DC model
  6156. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6157. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6158. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6159. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6160. // DC model
  6161. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6162. {
  6163. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6164. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6165. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6166. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6167. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6168. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6169. }
  6170. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6171. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6172. {
  6173. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6174. }
  6175. // 4G model
  6176. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6177. {
  6178. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6179. }
  6180. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6181. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6182. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6183. }
  6184. int handleDataTransferRequest(char *uuid, char *payload)
  6185. {
  6186. mtrace();
  6187. json_object *response = json_object_new_object();
  6188. int result = FAIL;
  6189. char tempvendorId[255]={0};
  6190. char tempmessageId[50]={0};
  6191. char tempdata[50]={0};
  6192. char message[2048]={0};
  6193. DEBUG_INFO("handleDataTransferRequest...\n");
  6194. if((uuid != NULL) && (payload != NULL))
  6195. {
  6196. json_object *DataTransfer;
  6197. DataTransfer = json_tokener_parse(payload);
  6198. if(!is_error(DataTransfer))
  6199. {
  6200. // Required data
  6201. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6202. // Optional data
  6203. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6204. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6205. if(json_object_object_get(DataTransfer, "data") != NULL)
  6206. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6207. result = PASS;
  6208. }
  6209. json_object_put(DataTransfer);
  6210. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6211. {
  6212. // Send all moudle firmware version on EVSE
  6213. system("pkill tmate");
  6214. createFirmwareVersionByDataTransfer();
  6215. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6216. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6217. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6218. }
  6219. else
  6220. {
  6221. // Can not find valid message id
  6222. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6223. }
  6224. }
  6225. else
  6226. {
  6227. // Payload is null
  6228. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6229. }
  6230. LWS_Send(message);
  6231. return result;
  6232. }
  6233. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6234. {
  6235. mtrace();
  6236. int result = FAIL;
  6237. int connectorIdInt, durationInt;
  6238. char chargingRateUnitStr[4]={0};
  6239. char comfirmstr[20];
  6240. int confirmPeriods = 0;
  6241. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6242. json_object *GetCompositeSchedule;
  6243. GetCompositeSchedule = json_tokener_parse(payload);
  6244. if(!is_error(GetCompositeSchedule))
  6245. {
  6246. // Required data
  6247. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6248. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6249. // Optional data
  6250. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6251. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6252. }
  6253. json_object_put(GetCompositeSchedule);
  6254. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6255. if((connectorIdInt == 0) ||
  6256. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6257. {
  6258. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6259. struct StructChargingProfile tmpProfile[1];
  6260. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6261. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6262. {
  6263. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6264. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6265. }
  6266. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6267. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6268. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6269. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6270. {
  6271. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6272. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6273. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6274. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6275. {
  6276. confirmPeriods = idx;
  6277. break;
  6278. }
  6279. }
  6280. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6281. }
  6282. else
  6283. {
  6284. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6285. }
  6286. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6287. return result;
  6288. }
  6289. int handleGetConfigurationRequest(char *uuid, char *payload)
  6290. {
  6291. mtrace();
  6292. int result = FAIL;
  6293. int MaxKeySupported = 0;
  6294. int n_keys = 0;
  6295. char requestKey[43][50]={0};
  6296. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6297. json_object *GetConfiguration;
  6298. GetConfiguration = json_tokener_parse(payload);
  6299. if(!is_error(GetConfiguration))
  6300. {
  6301. // Optional data
  6302. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6303. {
  6304. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6305. {
  6306. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6307. n_keys = idx + 1;
  6308. }
  6309. }
  6310. }
  6311. json_object_put(GetConfiguration);
  6312. UnknownKeynum = 0;
  6313. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6314. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6315. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6316. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6317. if(n_keys != 0)
  6318. {
  6319. for(int i=0;i<n_keys;i++)
  6320. {
  6321. getKeyValue(requestKey[i]);
  6322. }
  6323. }
  6324. else
  6325. {
  6326. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6327. getKeyValue("");
  6328. }
  6329. processUnkownKey();
  6330. sendGetConfigurationConfirmation(uuid);
  6331. return result;
  6332. }
  6333. static char fnamePlusPath[100]={0};
  6334. static char fnamePWithNoPath[60]={0};
  6335. void checkUploadLog(void)
  6336. {
  6337. FILE *fp;
  6338. /* Open the command for reading. */
  6339. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6340. if (fp == NULL) {
  6341. printf("Failed to run command\n" );
  6342. exit(1);
  6343. }
  6344. int ftppathlen = 0;
  6345. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6346. int i = 0;
  6347. /* Read the output a line at a time - output it. */
  6348. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6349. if(i==0)
  6350. {
  6351. ftppathlen = strlen(fnamePlusPath);
  6352. printf("%s\n", fnamePlusPath);
  6353. fnamePlusPath[ftppathlen]='\0';
  6354. break;
  6355. }
  6356. i= i+1;
  6357. }
  6358. /* close */
  6359. pclose(fp);
  6360. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6361. {
  6362. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6363. {
  6364. fnamePlusPath[k]='\0';
  6365. }
  6366. }
  6367. i=1;
  6368. //char fname[60]={0};
  6369. while(i < ftppathlen)
  6370. {
  6371. int len=ftppathlen-i;
  6372. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6373. {
  6374. printf("compare '/' all right\n");
  6375. break;
  6376. }
  6377. i=i+1;
  6378. }
  6379. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6380. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6381. fnamePWithNoPath[i+1] = '\0';
  6382. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6383. {
  6384. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6385. {
  6386. fnamePWithNoPath[j]='\0';
  6387. }
  6388. }
  6389. FILE* fp1 = fopen(fnamePlusPath, "r");
  6390. if (fp1)
  6391. {
  6392. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6393. // file exists
  6394. fclose(fp1);
  6395. }
  6396. else
  6397. {
  6398. // file doesn't exist
  6399. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6400. }
  6401. }
  6402. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6403. {
  6404. mtrace();
  6405. int result = FAIL;
  6406. char cmdBuf[512];
  6407. char fName[258];
  6408. time_t CurrentTime;
  6409. struct tm *tm;
  6410. pthread_t th_Status;
  6411. CurrentTime = time(NULL);
  6412. tm = localtime(&CurrentTime);
  6413. 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);
  6414. sendGetDiagnosticsConfirmation(uuid, fName);
  6415. system("exec /root/logPackTools 'log' 6");
  6416. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6417. system(cmdBuf);
  6418. checkUploadLog();
  6419. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6420. return result;
  6421. }
  6422. void* GetDiagnosticsProcess(void* data)
  6423. {
  6424. pthread_detach(pthread_self());
  6425. mtrace();
  6426. int retriesInt=0, retryIntervalInt=0;
  6427. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6428. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6429. 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};
  6430. int port=0;
  6431. char sstr[260]={ 0 };
  6432. int c = 0;
  6433. char *loc;
  6434. int isSuccess = FALSE;
  6435. char ftpbuf[200]={0};
  6436. char * pch;
  6437. char str[300]={ 0 };
  6438. strcpy(str,(const char*)data);
  6439. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6440. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6441. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6442. //****************location*******************/
  6443. c = 0;
  6444. memset(sstr ,0, ARRAY_SIZE(sstr));
  6445. loc = strstr(str, "location");
  6446. while (loc[3+strlen("location")+c] != '\"')
  6447. {
  6448. sstr[c] = loc[3+strlen("location")+c];
  6449. c++;
  6450. }
  6451. sstr[c] = '\0';
  6452. strcpy(locationstr,sstr);
  6453. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6454. if(strcmp(locationstr,"")==0)
  6455. {
  6456. DEBUG_INFO("location is <Empty>!\n");
  6457. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6458. goto end;
  6459. }
  6460. //****************retries*******************/
  6461. c = 0;
  6462. loc = strstr(str, "retries");
  6463. if(loc == NULL)
  6464. {
  6465. retriesIsNULL = TRUE;
  6466. }
  6467. else
  6468. {
  6469. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6470. {
  6471. sstr[c] = loc[strlen("retries")+2+c];
  6472. c++;
  6473. }
  6474. sstr[c] = '\0';
  6475. retriesInt = atoi(sstr);
  6476. }
  6477. if(retriesIsNULL == TRUE)
  6478. {
  6479. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6480. }
  6481. //****************retryInterval*******************/
  6482. c = 0;
  6483. loc = strstr(str, "retryInterval");
  6484. if(loc == NULL)
  6485. {
  6486. retryIntervalIsNULL = TRUE;
  6487. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6488. }
  6489. else
  6490. {
  6491. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6492. {
  6493. sstr[c] = loc[strlen("retryInterval")+2+c];
  6494. c++;
  6495. }
  6496. sstr[c] = '\0';
  6497. retryIntervalInt = atoi(sstr);
  6498. }
  6499. //****************startTime*******************/
  6500. c = 0;
  6501. memset(sstr ,0, ARRAY_SIZE(sstr));
  6502. loc = strstr(str, "startTime");
  6503. if(loc == NULL)
  6504. {
  6505. startTimeIsNULL = TRUE;
  6506. }
  6507. else
  6508. {
  6509. while (loc[3+strlen("startTime")+c] != '\"')
  6510. {
  6511. sstr[c] = loc[3+strlen("startTime")+c];
  6512. c++;
  6513. }
  6514. sstr[c] = '\0';
  6515. strcpy(startTimestr,sstr);
  6516. }
  6517. //****************stopTime*******************/
  6518. c = 0;
  6519. memset(sstr ,0, ARRAY_SIZE(sstr));
  6520. loc = strstr(str, "stopTime");
  6521. if(loc == NULL)
  6522. {
  6523. stopTimeIsNULL = TRUE;
  6524. }
  6525. else
  6526. {
  6527. while (loc[3+strlen("stopTime")+c] != '\"')
  6528. {
  6529. sstr[c] = loc[3+strlen("stopTime")+c];
  6530. c++;
  6531. }
  6532. sstr[c] = '\0';
  6533. strcpy(stopTimestr,sstr);
  6534. }
  6535. memset(protocol, 0, ARRAY_SIZE(protocol));
  6536. memset(user, 0, ARRAY_SIZE(user) );
  6537. memset(password, 0, ARRAY_SIZE(password));
  6538. memset(host, 0, ARRAY_SIZE(host));
  6539. memset(path, 0, ARRAY_SIZE(path));
  6540. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6541. memset(host1, 0, ARRAY_SIZE(host1));
  6542. memset(path1, 0, ARRAY_SIZE(path1));
  6543. /*location: ftp://user:password@host:port/path*/
  6544. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6545. if((access(fnamePlusPath,F_OK))!=-1)
  6546. {
  6547. DEBUG_INFO("fnamePlusPath exist.\n");
  6548. }
  6549. else
  6550. {
  6551. DEBUG_INFO("fnamePlusPath not exist!\n");
  6552. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6553. goto end;
  6554. }
  6555. pch=strchr(locationstr,'@');
  6556. if(pch==NULL)
  6557. {
  6558. sscanf(locationstr,
  6559. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6560. protocol, host, &port, path);
  6561. strcpy(user,"anonymous");
  6562. strcpy(password,"");
  6563. }
  6564. else
  6565. {
  6566. //DEBUG_INFO("pch=%s\n", pch);
  6567. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6568. protocol, user, password, host, &port, path);
  6569. }
  6570. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6571. {
  6572. DEBUG_INFO("protocol is not ftp/http ! \n");
  6573. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6574. goto end;
  6575. }
  6576. if(strncmp(locationstr,"http", 4) == 0)
  6577. {
  6578. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6579. sprintf(ftppath,"/%s", path);
  6580. do{
  6581. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6582. sleep(retryIntervalInt);
  6583. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6584. if(!isSuccess)
  6585. {
  6586. DEBUG_INFO("Diagnostics fail.\n");
  6587. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6588. }
  6589. else
  6590. {
  6591. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6592. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6593. }
  6594. }
  6595. else
  6596. {
  6597. sscanf(host,"%[^/]%s",host1, path1);
  6598. sprintf(ftppath,"%s", path1);
  6599. int ftppathlen=strlen(ftppath);
  6600. int i=1;
  6601. char filenametemp[50];
  6602. while(i < ftppathlen)
  6603. {
  6604. int len=ftppathlen-i;
  6605. if(ftppath[len]== 47) // '/' ascll code: 47
  6606. {
  6607. DEBUG_INFO("find '/' all right\n");
  6608. break;
  6609. }
  6610. i=i+1;
  6611. }
  6612. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6613. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6614. filenametemp[i+1] = 0;
  6615. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6616. if(port == 0)
  6617. port = 21;
  6618. do{
  6619. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6620. sleep(retryIntervalInt);
  6621. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6622. if(!isSuccess)
  6623. {
  6624. DEBUG_INFO("Diagnostics fail.\n");
  6625. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6626. }
  6627. else
  6628. {
  6629. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6630. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6631. }
  6632. }
  6633. end:
  6634. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6635. pthread_exit(NULL);
  6636. }
  6637. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6638. {
  6639. mtrace();
  6640. int result = FAIL;
  6641. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6642. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6643. {
  6644. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6645. localversion = -1;
  6646. }
  6647. else
  6648. {
  6649. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6650. OCPP_getListVerion();
  6651. }
  6652. //from db.OCPP_getListVerion
  6653. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6654. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6655. sendGetLocalListVersionConfirmation(uuid,"");
  6656. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6657. return result;
  6658. }
  6659. int handleRemoteStartRequest(char *uuid, char *payload)
  6660. {
  6661. mtrace();
  6662. int result = FAIL;
  6663. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6664. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6665. int tempIndex = 0;
  6666. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6667. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6668. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6669. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6670. int chargingSchedulePeriodCount = 0;
  6671. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6672. int c = 0;
  6673. char *loc;
  6674. char comfirmstr[20]={0};
  6675. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6676. if(server_pending == TRUE)
  6677. {
  6678. return 0;
  6679. }
  6680. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6681. strcpy(sstrtemp, stringtrimspace(payload));
  6682. //**********connectorId****************/
  6683. c = 0;
  6684. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6685. loc = strstr(sstrtemp, "connectorId");
  6686. if(loc == NULL)
  6687. {
  6688. connectorIdIsNULL = TRUE;
  6689. }
  6690. else
  6691. {
  6692. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6693. {
  6694. sstr[c] = loc[strlen("connectorId")+2+c];
  6695. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6696. c++;
  6697. }
  6698. sstr[c] = '\0';
  6699. connectorIdInt = atoi(sstr);
  6700. }
  6701. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6702. {
  6703. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6704. goto end;
  6705. }
  6706. //****************idTag*******************/
  6707. c = 0;
  6708. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6709. loc = strstr(sstrtemp, "idTag");
  6710. while (loc[3+strlen("idTag")+c] != '\"')
  6711. {
  6712. sstr[c] = loc[3+strlen("idTag")+c];
  6713. c++;
  6714. }
  6715. sstr[c] = '\0';
  6716. strcpy(idTagstr,sstr);
  6717. //****************chargingProfile*******************/
  6718. c = 0;
  6719. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6720. loc = strstr(sstrtemp, "chargingProfile");
  6721. if(loc == NULL)
  6722. {
  6723. chargingProfileIsNULL = TRUE;
  6724. }
  6725. else
  6726. {
  6727. //****************chargingProfileId*******************/
  6728. c=0;
  6729. loc = strstr(sstrtemp, "chargingProfileId");
  6730. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6731. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6732. {
  6733. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6734. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6735. c++;
  6736. }
  6737. sstr[c] = '\0';
  6738. chargingProfileIdInt = atoi(sstr);
  6739. //****************transactionId*******************/
  6740. loc = strstr(sstrtemp, "transactionId");
  6741. if(loc == NULL)
  6742. {
  6743. transactionIdIsNULL = TRUE;
  6744. }
  6745. else
  6746. {
  6747. c=0;
  6748. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6749. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6750. {
  6751. sstr[c] = loc[strlen("transactionId")+2+c];
  6752. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6753. c++;
  6754. }
  6755. sstr[c] = '\0';
  6756. transactionIdInt = atoi(sstr);
  6757. }
  6758. //****************stackLevel*******************/
  6759. c=0;
  6760. loc = strstr(sstrtemp, "stackLevel");
  6761. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6762. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6763. {
  6764. sstr[c] = loc[strlen("stackLevel")+2+c];
  6765. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6766. c++;
  6767. }
  6768. sstr[c] = '\0';
  6769. stackLevelInt = atoi(sstr);
  6770. //****************chargingProfilePurpose*******************/
  6771. c = 0;
  6772. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6773. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6774. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6775. {
  6776. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6777. c++;
  6778. }
  6779. sstr[c] = '\0';
  6780. strcpy(chargingProfilePurposestr,sstr);
  6781. //****************chargingProfileKind*******************/
  6782. c = 0;
  6783. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6784. loc = strstr(sstrtemp, "chargingProfileKind");
  6785. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6786. {
  6787. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6788. c++;
  6789. }
  6790. sstr[c] = '\0';
  6791. strcpy(chargingProfileKindstr,sstr);
  6792. //****************recurrencyKind*******************/
  6793. loc = strstr(sstrtemp, "recurrencyKind");
  6794. if(loc == NULL)
  6795. {
  6796. recurrencyKindIsNULL = TRUE;
  6797. }
  6798. else
  6799. {
  6800. c = 0;
  6801. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6802. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6803. {
  6804. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6805. c++;
  6806. }
  6807. sstr[c] = '\0';
  6808. strcpy(recurrencyKindstr,sstr);
  6809. }
  6810. //****************validFrom*******************/
  6811. loc = strstr(sstrtemp, "validFrom");
  6812. if(loc == NULL)
  6813. {
  6814. validFromIsNULL = TRUE;
  6815. }
  6816. else
  6817. {
  6818. c = 0;
  6819. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6820. while (loc[3+strlen("validFrom")+c] != '\"')
  6821. {
  6822. sstr[c] = loc[3+strlen("validFrom")+c];
  6823. c++;
  6824. }
  6825. sstr[c] = '\0';
  6826. strcpy(validFromstr,sstr);
  6827. }
  6828. //****************validTo*******************/
  6829. loc = strstr(sstrtemp, "validTo");
  6830. if(loc == NULL)
  6831. {
  6832. validToIsNULL = TRUE;
  6833. }
  6834. else
  6835. {
  6836. c = 0;
  6837. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6838. while (loc[3+strlen("validTo")+c] != '\"')
  6839. {
  6840. sstr[c] = loc[3+strlen("validTo")+c];
  6841. c++;
  6842. }
  6843. sstr[c] = '\0';
  6844. strcpy(validTostr,sstr);
  6845. }
  6846. //****************chargingSchedule*******************/
  6847. loc = strstr(sstrtemp, "chargingSchedule");
  6848. if(loc != NULL)
  6849. {
  6850. //****************duration*******************/
  6851. loc = strstr(sstrtemp, "duration");
  6852. if(loc == NULL)
  6853. {
  6854. durationIsNULL = TRUE;
  6855. }
  6856. else
  6857. {
  6858. c=0;
  6859. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6860. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6861. {
  6862. sstr[c] = loc[strlen("duration")+2+c];
  6863. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6864. c++;
  6865. }
  6866. sstr[c] = '\0';
  6867. durationInt = atoi(sstr);
  6868. }
  6869. //****************startSchedule******************/
  6870. loc = strstr(sstrtemp, "startSchedule");
  6871. if(loc == NULL)
  6872. {
  6873. startScheduleIsNULL = TRUE;
  6874. }
  6875. else
  6876. {
  6877. c = 0;
  6878. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6879. while (loc[3+strlen("startSchedule")+c] != '\"')
  6880. {
  6881. sstr[c] = loc[3+strlen("startSchedule")+c];
  6882. c++;
  6883. }
  6884. sstr[c] = '\0';
  6885. strcpy(startSchedulestr,sstr);
  6886. }
  6887. //****************chargingRateUnit*******************/
  6888. c = 0;
  6889. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6890. loc = strstr(sstrtemp, "chargingRateUnit");
  6891. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6892. {
  6893. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6894. c++;
  6895. }
  6896. sstr[c] = '\0';
  6897. strcpy(chargingRateUnitstr,sstr);
  6898. //****************minChargingRate*******************/
  6899. loc = strstr(sstrtemp, "minChargingRate");
  6900. if(loc == NULL)
  6901. {
  6902. minChargingRateIsNULL = TRUE;
  6903. }
  6904. else
  6905. {
  6906. c=0;
  6907. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6908. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6909. {
  6910. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6911. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6912. c++;
  6913. }
  6914. sstr[c] = '\0';
  6915. minChargingRateflaot = atof(sstr);
  6916. }
  6917. //****************chargingSchedulePeriod count*******************/
  6918. int what_len = strlen("startPeriod");
  6919. char *where = sstrtemp;
  6920. while ((where = strstr(where, "startPeriod"))) {
  6921. where += what_len;
  6922. chargingSchedulePeriodCount++;
  6923. }
  6924. where = sstrtemp;
  6925. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6926. {
  6927. //****************startPeriod*******************/
  6928. c=0;
  6929. loc = strstr(where, "startPeriod");
  6930. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6931. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6932. {
  6933. sstr[c] = loc[strlen("startPeriod")+2+c];
  6934. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6935. c++;
  6936. }
  6937. sstr[c] = '\0';
  6938. startPeriodInt[periodNums] = atoi(sstr);
  6939. //****************limit*******************/
  6940. c=0;
  6941. loc = strstr(where, "limit");
  6942. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6943. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6944. {
  6945. sstr[c] = loc[strlen("limit")+2+c];
  6946. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6947. c++;
  6948. }
  6949. sstr[c] = '\0';
  6950. limitflaot[periodNums] = atof(sstr);
  6951. //****************numberPhases*******************/
  6952. loc = strstr(where, "numberPhases");
  6953. if(loc == NULL)
  6954. {
  6955. numberPhasesIsNULL = TRUE;
  6956. }
  6957. else
  6958. {
  6959. c=0;
  6960. memset(sstr ,0, ARRAY_SIZE(sstr) );
  6961. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6962. {
  6963. sstr[c] = loc[strlen("numberPhases")+2+c];
  6964. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6965. c++;
  6966. }
  6967. sstr[c] = '\0';
  6968. numberPhasesInt[periodNums] = atoi(sstr);
  6969. }
  6970. where = loc;
  6971. } // END FOR chargingSchedulePeriodCount
  6972. }// END IF chargingSchedule
  6973. } // END chargingProfile
  6974. /*
  6975. enum _SYSTEM_STATUS
  6976. {
  6977. S_BOOTING = 0,
  6978. S_IDLE, = 1
  6979. S_AUTHORIZING, =2
  6980. S_REASSIGN_CHECK, =3
  6981. S_REASSIGN, =4
  6982. S_PRECHARGE, =5
  6983. S_PREPARING_FOR_EV, =6
  6984. S_PREPARING_FOR_EVSE, =7
  6985. S_CHARGING, =8
  6986. S_TERMINATING, =9
  6987. S_COMPLETE, =10
  6988. S_ALARM, =11
  6989. S_FAULT =12
  6990. }
  6991. */
  6992. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6993. {
  6994. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6995. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6996. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6997. //check Transaction active
  6998. if(gunType[connectorIdInt -1] == 'J')
  6999. {
  7000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7001. {
  7002. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7003. }
  7004. else
  7005. {
  7006. tempIndex = connectorIdInt -1;
  7007. }
  7008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7009. {
  7010. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7011. {
  7012. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7013. {
  7014. //Reserved
  7015. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7016. }
  7017. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7018. {
  7019. //Reserved
  7020. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7021. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7022. goto end;
  7023. }
  7024. else
  7025. {
  7026. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7027. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7028. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7029. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7030. {
  7031. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7032. goto end;
  7033. }
  7034. }//END FOR ELSE
  7035. }
  7036. }// END FOR CHAdeMO_QUANTITY
  7037. }
  7038. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7039. {
  7040. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7041. {
  7042. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7043. }
  7044. else
  7045. {
  7046. tempIndex = connectorIdInt -1;
  7047. }
  7048. for (int index = 0; index < CCS_QUANTITY; index++)
  7049. {
  7050. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7051. {
  7052. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7053. {
  7054. //Reserved
  7055. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7056. }
  7057. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7058. {
  7059. //Reserved
  7060. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7061. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7062. goto end;
  7063. }
  7064. else
  7065. {
  7066. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7067. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7068. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7069. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7070. {
  7071. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7072. goto end;
  7073. }
  7074. }// END FOR ELSE
  7075. }
  7076. }// END FOR CCS_QUANTITY
  7077. }
  7078. else if(gunType[connectorIdInt -1] == 'G')
  7079. {
  7080. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7081. {
  7082. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7083. }
  7084. else
  7085. {
  7086. tempIndex = connectorIdInt -1;
  7087. }
  7088. for (int index = 0; index < GB_QUANTITY; index++)
  7089. {
  7090. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7091. {
  7092. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7093. {
  7094. //Reserved
  7095. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7096. }
  7097. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7098. {
  7099. //Reserved
  7100. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7101. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7102. goto end;
  7103. }
  7104. else
  7105. {
  7106. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7107. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7108. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7109. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7110. {
  7111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7112. goto end;
  7113. }
  7114. }// END FOR ELSE
  7115. }
  7116. } // END FOR GB_QUANTITY
  7117. }
  7118. else
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7121. {
  7122. tempIndex = 2;
  7123. }
  7124. else
  7125. {
  7126. tempIndex = connectorIdInt -1;
  7127. }
  7128. for (int index = 0; index < AC_QUANTITY; index++)
  7129. {
  7130. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7131. {
  7132. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7133. {
  7134. //Reserved
  7135. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7136. }
  7137. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7138. {
  7139. //Reserved
  7140. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7142. goto end;
  7143. }
  7144. else
  7145. {
  7146. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7147. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7148. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7149. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7150. {
  7151. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7152. goto end;
  7153. }
  7154. }//END FOR ELSE
  7155. }
  7156. }// END FOR AC_QUANTITY
  7157. }
  7158. if(chargingProfileIsNULL == FALSE)
  7159. {
  7160. //ChargingProfile
  7161. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7162. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7163. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7164. if(recurrencyKindIsNULL == FALSE) //OPTION
  7165. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7166. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7167. if(transactionIdIsNULL == FALSE) // OPTION
  7168. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7169. if(validFromIsNULL == FALSE) // OPTION
  7170. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7171. if(validToIsNULL == FALSE) //OPTION
  7172. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7173. //ChargingSchedule
  7174. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7175. if(durationIsNULL == FALSE) //OPTION
  7176. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7177. if(minChargingRateIsNULL == FALSE) //OPTION
  7178. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7179. if(startScheduleIsNULL == FALSE) //OPTION
  7180. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7181. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7182. {
  7183. //ChargingSchedulePeriod
  7184. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7185. if(numberPhasesIsNULL == FALSE)
  7186. {
  7187. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7188. }
  7189. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7190. }
  7191. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7192. {
  7193. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7194. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7195. //memset idTag
  7196. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7197. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7198. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7199. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7200. }
  7201. else
  7202. {
  7203. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7204. }
  7205. }
  7206. else
  7207. {
  7208. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7209. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7210. //memset idTag
  7211. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7212. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7213. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7214. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7215. }
  7216. }
  7217. else
  7218. {
  7219. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7220. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7221. }
  7222. end:
  7223. if(connectorIdIsNULL == FALSE)
  7224. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7225. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7226. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7227. //OCPP send RemoteStartConfirmation by first.
  7228. sendRemoteStartConfirmation(uuid, comfirmstr);
  7229. return result;
  7230. }
  7231. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7232. {
  7233. mtrace();
  7234. int result = FAIL;
  7235. int match = FALSE;
  7236. int GunNO = 0;
  7237. int tempIndex = 0;
  7238. int transactionIdInt=0;
  7239. int transactionIdIsNULL= FALSE;
  7240. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7241. int c = 0;
  7242. char *loc;
  7243. char comfirmstr[20];
  7244. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7245. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7246. if(server_pending == TRUE)
  7247. {
  7248. return 0;
  7249. }
  7250. strcpy(sstrtemp, stringtrimspace(payload));
  7251. c=0;
  7252. loc = strstr(sstrtemp, "transactionId");
  7253. if(loc == NULL)
  7254. {
  7255. transactionIdIsNULL= TRUE;
  7256. }
  7257. else
  7258. {
  7259. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7260. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7261. {
  7262. sstr[c] = loc[strlen("transactionId")+2+c];
  7263. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7264. c++;
  7265. }
  7266. sstr[c] = '\0';
  7267. transactionIdInt = atoi(sstr);
  7268. }
  7269. if(transactionIdIsNULL == FALSE)
  7270. {
  7271. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7272. {
  7273. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7274. {
  7275. //check Transaction active
  7276. if(gunType[gun_index] == 'J')
  7277. {
  7278. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7279. {
  7280. tempIndex = ((gun_index==2) ? 1: 0);
  7281. }
  7282. else
  7283. {
  7284. tempIndex = gun_index;
  7285. }
  7286. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7287. {
  7288. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7289. {
  7290. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7291. {
  7292. match = TRUE;
  7293. GunNO = gun_index;
  7294. }
  7295. }
  7296. }// END FOR CHAdeMO_QUANTITY
  7297. }
  7298. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7299. {
  7300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7301. {
  7302. tempIndex = ((gun_index==2) ? 1: 0);
  7303. }
  7304. else
  7305. {
  7306. tempIndex = gun_index;
  7307. }
  7308. for (int index = 0; index < CCS_QUANTITY; index++)
  7309. {
  7310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7311. {
  7312. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7313. {
  7314. match = TRUE;
  7315. GunNO = gun_index;
  7316. }
  7317. }
  7318. }// END FOR CCS_QUANTITY
  7319. }
  7320. else if(gunType[gun_index] == 'G')
  7321. {
  7322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7323. {
  7324. tempIndex = ((gun_index==2) ? 1: 0);
  7325. }
  7326. else
  7327. {
  7328. tempIndex = gun_index;
  7329. }
  7330. for (int index = 0; index < GB_QUANTITY; index++)
  7331. {
  7332. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7333. {
  7334. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7335. {
  7336. match = TRUE;
  7337. GunNO = gun_index;
  7338. }
  7339. }
  7340. }// END FOR GB_QUANTITY
  7341. }
  7342. else
  7343. {
  7344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7345. {
  7346. tempIndex = 2;
  7347. }
  7348. else
  7349. {
  7350. tempIndex = gun_index;
  7351. }
  7352. for (int index = 0; index < AC_QUANTITY; index++)
  7353. {
  7354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7355. {
  7356. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7357. {
  7358. match = TRUE;
  7359. GunNO = gun_index;
  7360. }
  7361. }
  7362. }// END FOR CHAdeMO_QUANTITY
  7363. } // END FOR AC ELSE
  7364. }// CHECK IF ResponseTransactionId == transactionIdInt
  7365. }//END FOR
  7366. if( match == TRUE)
  7367. {
  7368. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7369. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7370. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7371. }
  7372. else
  7373. {
  7374. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7375. }
  7376. }
  7377. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7378. return result;
  7379. }
  7380. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7381. {
  7382. mtrace();
  7383. int result = FAIL;
  7384. int connectorIdInt=0, reservationIdInt=0;
  7385. int tempIndex = 0;
  7386. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7387. char comfirmstr[20]={0};
  7388. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7389. int c = 0;
  7390. char *loc;
  7391. //char *ptr;
  7392. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7393. strcpy(sstrtemp, stringtrimspace(payload));
  7394. //***(1)connectorId ****/
  7395. c=0;
  7396. loc = strstr(sstrtemp, "connectorId");
  7397. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7398. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7399. {
  7400. sstr[c] = loc[strlen("connectorId")+2+c];
  7401. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7402. c++;
  7403. }
  7404. sstr[c] = '\0';
  7405. connectorIdInt = atoi(sstr);
  7406. //***(2)expiryDate ****/
  7407. loc = strstr(sstrtemp, "expiryDate");
  7408. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7409. c = 0;
  7410. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7411. {
  7412. sstr[c] = loc[3+strlen("expiryDate")+c];
  7413. c++;
  7414. }
  7415. sstr[c] = '\0';
  7416. strcpy(expiryDatestr, sstr);
  7417. //***(3)idTag ****/
  7418. loc = strstr(sstrtemp, "idTag");
  7419. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7420. c = 0;
  7421. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7422. {
  7423. sstr[c] = loc[3+strlen("idTag")+c];
  7424. c++;
  7425. }
  7426. sstr[c] = '\0';
  7427. strcpy(idTagstr, sstr);
  7428. //***(4)parentIdTag ****/
  7429. loc = strstr(sstrtemp, "parentIdTag");
  7430. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7431. c = 0;
  7432. if(loc == NULL)
  7433. {
  7434. strcpy(parentIdTagstr, "");
  7435. }
  7436. else
  7437. {
  7438. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7439. {
  7440. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7441. c++;
  7442. }
  7443. sstr[c] = '\0';
  7444. strcpy(parentIdTagstr, sstr);
  7445. }
  7446. //***(5)reservationId ****/
  7447. c=0;
  7448. loc = strstr(sstrtemp, "reservationId");
  7449. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7450. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7451. {
  7452. sstr[c] = loc[strlen("reservationId")+2+c];
  7453. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7454. c++;
  7455. }
  7456. sstr[c] = '\0';
  7457. reservationIdInt = atoi(sstr);
  7458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7459. /*
  7460. enum SYSTEM_STATUS
  7461. {
  7462. SYS_MODE_BOOTING = 0,
  7463. SYS_MODE_IDLE = 1,
  7464. SYS_MODE_AUTHORIZING = 2,
  7465. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7466. SYS_MODE_REASSIGN = 4,
  7467. SYS_MODE_PREPARING = 5,
  7468. SYS_MODE_PREPARE_FOR_EV = 6,
  7469. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7470. SYS_MODE_CHARGING = 8,
  7471. SYS_MODE_TERMINATING = 9,
  7472. SYS_MODE_COMPLETE = 10,
  7473. SYS_MODE_ALARM = 11,
  7474. SYS_MODE_FAULT = 12,
  7475. SYS_MODE_RESERVATION = 13,
  7476. SYS_MODE_BOOKING = 14,
  7477. SYS_MODE_MAINTAIN = 15,
  7478. SYS_MODE_DEBUG = 16,
  7479. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7480. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7481. SYS_MODE_UPDATE = 19
  7482. };
  7483. */
  7484. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7485. {
  7486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7487. goto end;
  7488. }
  7489. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7490. {
  7491. //check Transaction active
  7492. if(gunType[connectorIdInt -1] == 'J')
  7493. {
  7494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7495. {
  7496. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7497. }
  7498. else
  7499. {
  7500. tempIndex = connectorIdInt -1;
  7501. }
  7502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7503. {
  7504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7505. {
  7506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7507. {
  7508. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7509. {
  7510. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7511. {
  7512. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7513. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7514. }
  7515. 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'))
  7516. {
  7517. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7518. }
  7519. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7520. {
  7521. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7522. }
  7523. else
  7524. {
  7525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7526. }
  7527. }
  7528. 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
  7529. {
  7530. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7531. }
  7532. }
  7533. else
  7534. {
  7535. //replace reservation
  7536. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7538. }
  7539. }
  7540. } // END FOR CHAdeMO_QUANTITY
  7541. }
  7542. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7543. {
  7544. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7545. {
  7546. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7547. }
  7548. else
  7549. {
  7550. tempIndex = connectorIdInt -1;
  7551. }
  7552. for (int index = 0; index < CCS_QUANTITY; index++)
  7553. {
  7554. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7555. {
  7556. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7557. {
  7558. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7559. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7560. {
  7561. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7562. {
  7563. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7564. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7565. }
  7566. 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'))
  7567. {
  7568. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7569. }
  7570. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7571. {
  7572. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7573. }
  7574. else
  7575. {
  7576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7577. }
  7578. }
  7579. 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
  7580. {
  7581. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7582. }
  7583. }
  7584. else
  7585. {
  7586. //replace reservation
  7587. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7589. }
  7590. }
  7591. } // END FOR CCS_QUANTITY
  7592. }
  7593. else if(gunType[connectorIdInt -1] == 'G')
  7594. {
  7595. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7596. {
  7597. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7598. }
  7599. else
  7600. {
  7601. tempIndex = connectorIdInt -1;
  7602. }
  7603. for (int index = 0; index < GB_QUANTITY; index++)
  7604. {
  7605. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7606. {
  7607. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7608. {
  7609. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7610. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7611. {
  7612. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7613. {
  7614. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7616. }
  7617. 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'))
  7618. {
  7619. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7620. }
  7621. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7622. {
  7623. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7624. }
  7625. else
  7626. {
  7627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7628. }
  7629. }
  7630. 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
  7631. {
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7633. }
  7634. }
  7635. else
  7636. {
  7637. //replace reservation
  7638. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7639. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7640. }
  7641. }
  7642. }// END FOR GB_QUANTITY
  7643. }
  7644. else
  7645. {
  7646. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7647. {
  7648. tempIndex = 2;
  7649. }
  7650. else
  7651. {
  7652. tempIndex = (connectorIdInt -1);
  7653. }
  7654. for (int index = 0; index < AC_QUANTITY; index++)
  7655. {
  7656. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7657. {
  7658. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7659. {
  7660. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7661. {
  7662. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7663. {
  7664. 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))
  7665. {
  7666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7667. }
  7668. else
  7669. {
  7670. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7672. }
  7673. }
  7674. 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'))
  7675. {
  7676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7677. }
  7678. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7679. {
  7680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7681. }
  7682. else
  7683. {
  7684. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7685. }
  7686. }
  7687. 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
  7688. {
  7689. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7690. }
  7691. }
  7692. else
  7693. {
  7694. //replace reservation
  7695. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7696. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7697. }
  7698. }
  7699. } // END FOR AC_QUANTITY
  7700. }
  7701. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7702. }
  7703. else if(connectorIdInt == 0)
  7704. {
  7705. //check Transaction active
  7706. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7707. {
  7708. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7709. {
  7710. 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'))
  7711. {
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7713. goto end;
  7714. }
  7715. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7716. {
  7717. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7718. goto end;
  7719. }
  7720. 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
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7723. goto end;
  7724. }
  7725. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7726. {
  7727. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7728. goto end;
  7729. }
  7730. }
  7731. }// END FOR CHAdeMO_QUANTITY
  7732. for (int index = 0; index < CCS_QUANTITY; index++)
  7733. {
  7734. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7735. {
  7736. 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'))
  7737. {
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7739. goto end;
  7740. }
  7741. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7742. {
  7743. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7744. goto end;
  7745. }
  7746. 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
  7747. {
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7749. goto end;
  7750. }
  7751. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7752. {
  7753. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7754. goto end;
  7755. }
  7756. }
  7757. } // END FOR CCS_QUANTITY
  7758. for (int index = 0; index < GB_QUANTITY; index++)
  7759. {
  7760. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7761. {
  7762. 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'))
  7763. {
  7764. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7765. goto end;
  7766. }
  7767. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7770. goto end;
  7771. }
  7772. 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
  7773. {
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7775. goto end;
  7776. }
  7777. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7778. {
  7779. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7780. goto end;
  7781. }
  7782. }
  7783. } // END FOR GB_QUANTITY
  7784. for (int index = 0; index < AC_QUANTITY; index++)
  7785. {
  7786. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7787. {
  7788. 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'))
  7789. {
  7790. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7791. goto end;
  7792. }
  7793. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7794. {
  7795. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7796. goto end;
  7797. }
  7798. 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
  7799. {
  7800. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7801. goto end;
  7802. }
  7803. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7804. {
  7805. 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))
  7806. {
  7807. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7808. goto end;
  7809. }
  7810. }
  7811. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7812. {
  7813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7814. goto end;
  7815. }
  7816. }
  7817. }// END FOR AC_QUANTITY
  7818. //The connectorId is 0
  7819. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7820. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7821. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7822. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7823. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7824. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7825. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7826. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7827. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7828. result = TRUE;
  7829. return result;
  7830. }
  7831. else
  7832. {
  7833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7834. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7835. }
  7836. if(strcmp(comfirmstr,"Accepted") == 0)
  7837. {
  7838. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7839. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7840. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7841. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7842. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7843. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7844. result = TRUE;
  7845. return result;
  7846. }
  7847. end:
  7848. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7849. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7850. return result;
  7851. }
  7852. int handleResetRequest(char *uuid, char *payload)
  7853. {
  7854. mtrace();
  7855. int result = FAIL;
  7856. char sstr[10]={0},sstrtemp[30]={ 0 };
  7857. char typestr[10]={0};
  7858. char comfirmstr[20]={0};
  7859. int c = 0;
  7860. char *loc;
  7861. DEBUG_INFO("handleResetRequest...\n");
  7862. strcpy(sstrtemp, stringtrimspace(payload));
  7863. loc = strstr(sstrtemp, "type");
  7864. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7865. c = 0;
  7866. while (loc[3+strlen("type")+c] != '\"')
  7867. {
  7868. sstr[c] = loc[3+strlen("type")+c];
  7869. c++;
  7870. }
  7871. sstr[c] = '\0';
  7872. strcpy(typestr,sstr);
  7873. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7874. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7875. {
  7876. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7877. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7878. result = TRUE;
  7879. return result;
  7880. }
  7881. else
  7882. {
  7883. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7884. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7885. goto errorend;
  7886. }
  7887. errorend:
  7888. sendResetConfirmation(uuid, comfirmstr);
  7889. return result;
  7890. }
  7891. int handleSendLocalListRequest(char *uuid, char *payload)
  7892. {
  7893. mtrace();
  7894. int result = FAIL;
  7895. int listVersionInt;
  7896. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7897. char listsearch[]="listVersion";
  7898. char updateTypesearch[]="updateType";
  7899. char localAuthorizationListsearch[]="localAuthorizationList";
  7900. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7901. char CardList[500][160]={0};
  7902. char updateTypestr[15]={0};
  7903. char idTagstr[20]={0};
  7904. char parentIdTag[20]={0};
  7905. char expiryDate[30]={0};
  7906. char idTagstatus[16]={0};
  7907. int c = 0;
  7908. int i = 0;
  7909. char *delim1 = "}";
  7910. char * pch;
  7911. char *loc;
  7912. //char *ptr;
  7913. char comfirmstr[20];
  7914. //int n_localAuthorizations = 0;
  7915. int checkState_Faulted = FALSE;
  7916. DEBUG_INFO("handleSendLocalListRequest...\n");
  7917. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7918. {
  7919. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7920. goto end;
  7921. }
  7922. //check Charge Point state
  7923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7924. {
  7925. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7926. {
  7927. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7928. }
  7929. }
  7930. for (int index = 0; index < CCS_QUANTITY; index++)
  7931. {
  7932. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7933. {
  7934. checkState_Faulted = TRUE; //OCPP Status
  7935. }
  7936. }
  7937. for (int index = 0; index < GB_QUANTITY; index++)
  7938. {
  7939. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7940. {
  7941. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7942. }
  7943. }
  7944. //check Charge Point state
  7945. for (int index = 0; index < AC_QUANTITY; index++)
  7946. {
  7947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7948. {
  7949. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7950. }
  7951. }
  7952. if(checkState_Faulted == TRUE)
  7953. {
  7954. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7955. goto end;
  7956. }
  7957. //Filter payload space
  7958. strcpy(sstrtemp, stringtrimspace(payload));
  7959. //listVersion
  7960. c = 0;
  7961. loc = strstr(sstrtemp, listsearch);
  7962. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7963. {
  7964. sstr[c] = loc[strlen("listVersion")+2+c];
  7965. c++;
  7966. }
  7967. sstr[c] = '\0';
  7968. listVersionInt = atoi(sstr);
  7969. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7970. //updateType
  7971. loc = strstr(sstrtemp, updateTypesearch);
  7972. c = 0;
  7973. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7974. {
  7975. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7976. c++;
  7977. }
  7978. sstr[c] = '\0';
  7979. strcpy(updateTypestr, sstr);
  7980. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7981. //localAuthorizationList
  7982. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7983. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7984. if(loc != NULL) // localAuthorizationList is not NULL
  7985. {
  7986. //Check UpdateType
  7987. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7988. {
  7989. //Local list full update
  7990. printf("Local list full update.\n");
  7991. OCPP_getListVerion();
  7992. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7993. {
  7994. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7995. goto end;
  7996. }
  7997. OCPP_cleanLocalList();
  7998. }
  7999. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8000. {
  8001. //Local list different update
  8002. printf("Local list different update.\n");
  8003. OCPP_getListVerion();
  8004. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8005. {
  8006. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8007. goto end;
  8008. }
  8009. }
  8010. else
  8011. {
  8012. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8013. goto end;
  8014. }
  8015. c = 0;
  8016. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8017. {
  8018. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8020. c++;
  8021. }
  8022. sstr[c] = '\0';
  8023. //DEBUG_INFO("sstr=%s\n", sstr);
  8024. //parsing strings to words
  8025. i = 0;
  8026. pch = strtok(sstr,delim1);
  8027. while (pch != NULL)
  8028. {
  8029. strcpy(CardList[i], pch);
  8030. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8031. pch = strtok (NULL, delim1);
  8032. i = i + 1;
  8033. }
  8034. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8035. //local Authorizations List Numbers
  8036. //n_localAuthorizations = i;
  8037. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8038. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8039. c= 0;
  8040. while(c < i) // i is CardList Number
  8041. {
  8042. //Search "IdToken"
  8043. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8044. loc = strstr(CardList[c], "idTag");
  8045. int j = 0;
  8046. while (loc[3+strlen("idTag")+j] != '\"')
  8047. {
  8048. sstr[j] = loc[3+strlen("idTag")+j];
  8049. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8050. j++;
  8051. }
  8052. sstr[j] = '\0';
  8053. strcpy(idTagstr, sstr);
  8054. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8055. //Search "expiryDate"
  8056. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8057. loc = strstr(CardList[c], "expiryDate");
  8058. j = 0;
  8059. if(loc != NULL)
  8060. {
  8061. while (loc[3+strlen("expiryDate")+j] != '\"')
  8062. {
  8063. sstr[j] = loc[3+strlen("expiryDate")+j];
  8064. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8065. j++;
  8066. }
  8067. sstr[j] = '\0';
  8068. strcpy(expiryDate, sstr);
  8069. }
  8070. else
  8071. {
  8072. strcpy(expiryDate, "");
  8073. }
  8074. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8075. //Search "parentIdTag"
  8076. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8077. loc = strstr(CardList[c], "parentIdTag");
  8078. j = 0;
  8079. if(loc != NULL)
  8080. {
  8081. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8082. {
  8083. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8084. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8085. j++;
  8086. }
  8087. sstr[j] = '\0';
  8088. strcpy(parentIdTag, sstr);
  8089. }
  8090. else
  8091. {
  8092. strcpy(parentIdTag, "");
  8093. }
  8094. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8095. //Search "status"
  8096. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8097. loc = strstr(CardList[c], "status");
  8098. j = 0;
  8099. while (loc[3+strlen("status")+j] != '\"')
  8100. {
  8101. sstr[j] = loc[3+strlen("status")+j];
  8102. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8103. j++;
  8104. }
  8105. sstr[j] = '\0';
  8106. strcpy(idTagstatus, sstr);
  8107. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8108. OCPP_getIdTag(idTagstr);
  8109. //OCPP_getIdTag("test"); For Test
  8110. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8111. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8112. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8113. {
  8114. //Local list full update
  8115. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8116. // update list
  8117. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8118. //DEBUG_INFO("Local list full update. 1\n");
  8119. //OCPP_get_TableAuthlocalAllData();
  8120. //DEBUG_INFO("Local list full update. 2\n");
  8121. }
  8122. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8123. {
  8124. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8125. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8126. }
  8127. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8128. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8129. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8130. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8131. c++;
  8132. }
  8133. }
  8134. else
  8135. {
  8136. //Check UpdateType
  8137. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8138. {
  8139. //Local list full update
  8140. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8141. OCPP_cleanLocalList();
  8142. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8143. goto end;
  8144. }
  8145. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8146. {
  8147. //Local list different update
  8148. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8149. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8150. goto end;
  8151. }
  8152. }
  8153. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8154. end:
  8155. sendSendLocalListConfirmation(uuid, comfirmstr);
  8156. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8157. return result;
  8158. }
  8159. #define MAX 200
  8160. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8161. {
  8162. mtrace();
  8163. int result = FAIL;
  8164. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8165. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8166. char chargingProfilePurposeStr[30]={0};
  8167. char chargingProfileKindStr[16]={0};
  8168. char recurrencyKindStr[10]={0};
  8169. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8170. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8171. int chargingSchedulePeriodCount = 0;
  8172. //int updateflag = FALSE;
  8173. char comfirmstr[20]={0};
  8174. int meet= FALSE;
  8175. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8176. int c = 0;
  8177. char *loc;
  8178. FILE *fptr1;//, *fptr2;
  8179. //int lno=0;//, linectr = 0;
  8180. //int modifyflag = FALSE;
  8181. char filename[MAX]={0};
  8182. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8183. //int resultRename=0;
  8184. char rmFileCmd[50]={0};
  8185. char tempchargingProfilePurposeStr[30]={0};
  8186. char word[1600]={0};
  8187. int n_chargingProfile = 0;
  8188. //[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}}}]
  8189. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8190. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8191. //Filter string space
  8192. strcpy(sstrtemp, stringtrimspace(payload));
  8193. //*********************connectorId***************************/
  8194. loc = strstr(sstrtemp, "connectorId");
  8195. c = 0;
  8196. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8197. while (loc[strlen("connectorId")+2+c] != ',')
  8198. {
  8199. sstr[c] = loc[strlen("connectorId")+2+c];
  8200. c++;
  8201. }
  8202. sstr[c] = '\0';
  8203. connectorIdInt = atoi(sstr);
  8204. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8205. {
  8206. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8207. }
  8208. else
  8209. {
  8210. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8211. }
  8212. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8213. //*********************chargingProfileId***************************/
  8214. loc = strstr(sstrtemp, "chargingProfileId");
  8215. c = 0;
  8216. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8217. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8218. {
  8219. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8220. c++;
  8221. }
  8222. sstr[c] = '\0';
  8223. chargingProfileIdInt = atoi(sstr);
  8224. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8225. {
  8226. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8227. }
  8228. else
  8229. {
  8230. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8231. }
  8232. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8233. //*********************transactionId***************************/
  8234. loc = strstr(sstrtemp, "transactionId");
  8235. if(loc != NULL)
  8236. {
  8237. c = 0;
  8238. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8239. while (loc[strlen("transactionId")+2+c] != ',')
  8240. {
  8241. sstr[c] = loc[strlen("transactionId")+2+c];
  8242. c++;
  8243. }
  8244. sstr[c] = '\0';
  8245. transactionIdInt = atoi(sstr);
  8246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8247. {
  8248. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8249. }
  8250. else
  8251. {
  8252. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8253. }
  8254. }
  8255. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8256. //*********************stackLevel***************************/
  8257. loc = strstr(sstrtemp, "stackLevel");
  8258. c = 0;
  8259. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8260. while (loc[strlen("stackLevel")+2+c] != ',')
  8261. {
  8262. sstr[c] = loc[strlen("stackLevel")+2+c];
  8263. c++;
  8264. }
  8265. sstr[c] = '\0';
  8266. stackLevelInt = atoi(sstr);
  8267. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8268. {
  8269. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8270. }
  8271. else
  8272. {
  8273. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8274. }
  8275. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8276. //*********************chargingProfilePurpose***************************/
  8277. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8278. c = 0;
  8279. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8280. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8281. {
  8282. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8283. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8284. c++;
  8285. }
  8286. sstr[c] = '\0';
  8287. strcpy(chargingProfilePurposeStr,sstr);
  8288. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8289. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8290. {
  8291. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8292. }
  8293. else
  8294. {
  8295. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8296. }
  8297. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8298. //*********************chargingProfileKind***************************/
  8299. loc = strstr(sstrtemp, "chargingProfileKind");
  8300. c = 0;
  8301. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8302. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8303. {
  8304. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8305. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8306. c++;
  8307. }
  8308. sstr[c] = '\0';
  8309. strcpy(chargingProfileKindStr,sstr);
  8310. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8311. {
  8312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8313. }
  8314. else
  8315. {
  8316. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8317. }
  8318. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8319. //*********************recurrencyKind***************************/
  8320. loc = strstr(sstrtemp, "recurrencyKind");
  8321. if(loc != NULL)
  8322. {
  8323. c = 0;
  8324. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8325. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8326. {
  8327. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8328. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8329. c++;
  8330. }
  8331. sstr[c] = '\0';
  8332. strcpy(recurrencyKindStr,sstr);
  8333. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8334. {
  8335. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8336. }
  8337. else
  8338. {
  8339. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8340. }
  8341. }
  8342. else
  8343. {
  8344. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8345. {
  8346. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8347. }
  8348. else
  8349. {
  8350. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8351. }
  8352. }
  8353. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8354. //*********************validFrom***************************/
  8355. loc = strstr(sstrtemp, "validFrom");
  8356. if(loc != NULL)
  8357. {
  8358. c = 0;
  8359. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8360. while (loc[3+strlen("validFrom")+c] != '\"')
  8361. {
  8362. sstr[c] = loc[3+strlen("validFrom")+c];
  8363. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8364. c++;
  8365. }
  8366. sstr[c] = '\0';
  8367. strcpy(validFromStr,sstr);
  8368. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8369. {
  8370. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8371. }
  8372. else
  8373. {
  8374. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8375. }
  8376. }
  8377. else
  8378. {
  8379. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8380. {
  8381. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8382. }
  8383. else
  8384. {
  8385. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8386. }
  8387. }
  8388. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8389. //*********************validTo***************************/
  8390. loc = strstr(sstrtemp, "validTo");
  8391. if(loc != NULL)
  8392. {
  8393. c = 0;
  8394. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8395. while (loc[3+strlen("validTo")+c] != '\"')
  8396. {
  8397. sstr[c] = loc[3+strlen("validTo")+c];
  8398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8399. c++;
  8400. }
  8401. sstr[c] = '\0';
  8402. strcpy(validToStr,sstr);
  8403. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8404. {
  8405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8406. }
  8407. else
  8408. {
  8409. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8410. }
  8411. }
  8412. else
  8413. {
  8414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8415. {
  8416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8417. }
  8418. else
  8419. {
  8420. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8421. }
  8422. }
  8423. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8424. //*********************duration***************************/
  8425. loc = strstr(sstrtemp, "duration");
  8426. if(loc != NULL)
  8427. {
  8428. c = 0;
  8429. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8430. while (loc[strlen("duration")+2+c] != ',')
  8431. {
  8432. sstr[c] = loc[strlen("duration")+2+c];
  8433. c++;
  8434. }
  8435. sstr[c] = '\0';
  8436. durationInt = atoi(sstr);
  8437. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8438. {
  8439. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8440. }
  8441. else
  8442. {
  8443. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8444. }
  8445. }
  8446. else
  8447. {
  8448. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8449. {
  8450. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8451. }
  8452. else
  8453. {
  8454. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8455. }
  8456. }
  8457. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8458. //*********************startSchedule***************************/
  8459. loc = strstr(sstrtemp, "startSchedule");
  8460. if(loc != NULL)
  8461. {
  8462. c = 0;
  8463. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8464. while (loc[3+strlen("startSchedule")+c] != '\"')
  8465. {
  8466. sstr[c] = loc[3+strlen("startSchedule")+c];
  8467. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8468. c++;
  8469. }
  8470. sstr[c] = '\0';
  8471. strcpy(startScheduleStr,sstr);
  8472. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8473. {
  8474. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8475. }
  8476. else
  8477. {
  8478. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8479. }
  8480. }
  8481. else
  8482. {
  8483. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8484. {
  8485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8486. }
  8487. else
  8488. {
  8489. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8490. }
  8491. }
  8492. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8493. //*********************chargingRateUnit***************************/
  8494. loc = strstr(sstrtemp, "chargingRateUnit");
  8495. if(loc != NULL)
  8496. {
  8497. c = 0;
  8498. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8499. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8500. {
  8501. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8502. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8503. c++;
  8504. }
  8505. sstr[c] = '\0';
  8506. strcpy(chargingRateUnitStr,sstr);
  8507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8508. {
  8509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8510. }
  8511. else
  8512. {
  8513. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8514. }
  8515. }
  8516. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8517. //****************chargingSchedulePeriod count start*******************/
  8518. int what_len = strlen("startPeriod");
  8519. char tempChargingProfile[1600]={0};
  8520. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8521. char *where = tempChargingProfile;
  8522. if (what_len)
  8523. {
  8524. while ((where = strstr(where, "startPeriod"))) {
  8525. where += what_len;
  8526. chargingSchedulePeriodCount++;
  8527. }
  8528. }
  8529. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8530. {
  8531. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8532. goto end;
  8533. }
  8534. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8535. //where = payload;
  8536. int templength = 0;
  8537. //int searchstart = 0;
  8538. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8539. {
  8540. //****************startPeriod*******************/
  8541. c=0;
  8542. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8543. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8544. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8545. {
  8546. sstr[c] = loc[strlen("startPeriod")+2+c];
  8547. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8548. c++;
  8549. }
  8550. sstr[c] = '\0';
  8551. startPeriodInt[periodNums] = atoi(sstr);
  8552. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8553. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8554. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8555. {
  8556. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8557. }
  8558. else
  8559. {
  8560. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8561. }
  8562. templength = strlen("startPeriod")+2+c;
  8563. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8564. //****************limit*******************/
  8565. c=0;
  8566. loc = strstr(tempChargingProfile + templength, "limit");
  8567. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8568. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8569. {
  8570. sstr[c] = loc[strlen("limit")+2+c];
  8571. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8572. c++;
  8573. }
  8574. sstr[c] = '\0';
  8575. limitflaot[periodNums] = atof(sstr);
  8576. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8577. {
  8578. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8579. }
  8580. else
  8581. {
  8582. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8583. }
  8584. templength = templength + strlen("limit")+2+c;
  8585. //****************numberPhases*******************/
  8586. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8587. if(loc != NULL)
  8588. {
  8589. c=0;
  8590. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8591. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8592. {
  8593. sstr[c] = loc[strlen("numberPhases")+2+c];
  8594. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8595. c++;
  8596. }
  8597. sstr[c] = '\0';
  8598. numberPhasesInt[periodNums] = atoi(sstr);
  8599. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8600. {
  8601. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8602. }
  8603. else
  8604. {
  8605. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8606. }
  8607. templength = templength + strlen("numberPhases")+2+c;
  8608. }
  8609. //where = loc;
  8610. }
  8611. //****************chargingSchedulePeriod count end*******************/
  8612. //*********************minChargingRate***************************/
  8613. loc = strstr(sstrtemp, "minChargingRate");
  8614. if(loc != NULL)
  8615. {
  8616. c = 0;
  8617. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8618. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8619. {
  8620. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8621. c++;
  8622. }
  8623. sstr[c] = '\0';
  8624. minChargingRateFloat = atof(sstr);
  8625. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8626. {
  8627. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8628. }
  8629. else
  8630. {
  8631. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8632. }
  8633. }
  8634. else
  8635. {
  8636. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8637. {
  8638. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8639. }
  8640. else
  8641. {
  8642. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8643. }
  8644. }
  8645. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8646. {
  8647. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8648. if(connectorIdInt != 0)
  8649. {
  8650. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8651. goto end;
  8652. }
  8653. strcpy(filename, ChargePointMaxProfile_JSON );
  8654. fptr1 = fopen(filename, "r");
  8655. if (!fptr1)
  8656. {
  8657. //file not exist
  8658. DEBUG_INFO("Unable to open the input file!!\n");
  8659. fptr1 = fopen(filename, "w+");
  8660. }
  8661. else
  8662. {
  8663. //Check Charging Profile Count
  8664. while(fscanf(fptr1, "%s", word) != EOF)
  8665. {
  8666. //DEBUG_INFO("word=%s\n",word);
  8667. if(strstr(word, "chargingProfileId")!= NULL)
  8668. {
  8669. //DEBUG_INFO("test chargingProfileId \n");
  8670. n_chargingProfile = n_chargingProfile + 1;
  8671. //DEBUG_INFO("chargingProfileId Found\n");
  8672. }
  8673. }
  8674. }
  8675. fclose(fptr1);
  8676. }
  8677. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8678. {
  8679. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8680. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8681. {
  8682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8683. goto end;
  8684. }
  8685. memset(filename, 0, ARRAY_SIZE(filename));
  8686. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8687. fptr1 = fopen(filename, "r");
  8688. if (!fptr1)
  8689. {
  8690. //file not exist
  8691. //DEBUG_INFO("Unable to open the input file!!\n");
  8692. fptr1 = fopen(filename, "w+");
  8693. }
  8694. else
  8695. {
  8696. //Check Charging Profile Count
  8697. while(fscanf(fptr1, "%s", word) != EOF)
  8698. {
  8699. //DEBUG_INFO("word=%s\n",word);
  8700. if(strstr(word, "chargingProfileId")!= NULL)
  8701. {
  8702. //DEBUG_INFO("test chargingProfileId \n");
  8703. n_chargingProfile = n_chargingProfile + 1;
  8704. //DEBUG_INFO("chargingProfileId Found\n");
  8705. }
  8706. }
  8707. }
  8708. fclose(fptr1);
  8709. }
  8710. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8711. {
  8712. //printf("set chargingProfile 1-4\n");
  8713. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8714. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8715. if(connectorIdInt == 0)
  8716. {
  8717. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8718. goto end;
  8719. }
  8720. int tempIndex = 0;
  8721. //check Transaction active
  8722. if(gunType[connectorIdInt -1] == 'J')
  8723. {
  8724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8725. {
  8726. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8727. }
  8728. else
  8729. {
  8730. tempIndex = connectorIdInt -1;
  8731. }
  8732. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8733. {
  8734. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8735. {
  8736. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8737. {
  8738. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8739. {
  8740. meet = TRUE;
  8741. break;
  8742. }
  8743. }
  8744. }
  8745. }
  8746. }
  8747. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8748. {
  8749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8750. {
  8751. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8752. }
  8753. else
  8754. {
  8755. tempIndex = connectorIdInt -1;
  8756. }
  8757. for (int index = 0; index < CCS_QUANTITY; index++)
  8758. {
  8759. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8760. {
  8761. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8762. {
  8763. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8764. {
  8765. meet = TRUE;
  8766. break;
  8767. }
  8768. }
  8769. }
  8770. }
  8771. }
  8772. else if(gunType[connectorIdInt -1] == 'G')
  8773. {
  8774. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8775. {
  8776. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8777. }
  8778. else
  8779. {
  8780. tempIndex = connectorIdInt -1;
  8781. }
  8782. for (int index = 0; index < GB_QUANTITY; index++)
  8783. {
  8784. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8785. {
  8786. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8787. {
  8788. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8789. {
  8790. meet = TRUE;
  8791. break;
  8792. }
  8793. }
  8794. }
  8795. }
  8796. }
  8797. else
  8798. {
  8799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8800. {
  8801. tempIndex = 2;
  8802. }
  8803. else
  8804. {
  8805. tempIndex = (connectorIdInt -1);
  8806. }
  8807. for (int index = 0; index < AC_QUANTITY; index++)
  8808. {
  8809. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8810. {
  8811. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8812. {
  8813. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8814. {
  8815. meet = TRUE;
  8816. break;
  8817. }
  8818. }
  8819. }
  8820. }
  8821. }
  8822. //check Transaction active
  8823. if(meet == FALSE)
  8824. {
  8825. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8826. goto end;
  8827. }
  8828. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8829. {
  8830. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8831. goto end;
  8832. }
  8833. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8834. fptr1 = fopen(filename, "r");
  8835. if (!fptr1)
  8836. {
  8837. //file not exist
  8838. DEBUG_INFO("Unable to open the input file!!\n");
  8839. fptr1 = fopen(filename, "w+");
  8840. }
  8841. else
  8842. {
  8843. //Check Charging Profile Count
  8844. while(fscanf(fptr1, "%s", word) != EOF)
  8845. {
  8846. //DEBUG_INFO("word=%s\n",word);
  8847. if(strstr(word, "chargingProfileId")!= NULL)
  8848. {
  8849. //DEBUG_INFO("test chargingProfileId \n");
  8850. n_chargingProfile = n_chargingProfile + 1;
  8851. //DEBUG_INFO("chargingProfileId Found\n");
  8852. }
  8853. }
  8854. }
  8855. fclose(fptr1);
  8856. }
  8857. // Check ChargeProfileMaxStackLevel
  8858. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8859. {
  8860. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8861. goto end;
  8862. }
  8863. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8864. {
  8865. int i = 0;
  8866. char fnametemp[200]={0};
  8867. n_chargingProfile = 0;
  8868. //Check ChargePointMaxProfile.json exit
  8869. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8870. {
  8871. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8872. //Check Charging Profile Count
  8873. while(fscanf(fptr1, "%s", word) != EOF)
  8874. {
  8875. //DEBUG_INFO("word=%s\n",word);
  8876. if(strstr(word, "chargingProfileId")!= NULL)
  8877. {
  8878. //DEBUG_INFO("test chargingProfileId \n");
  8879. n_chargingProfile = n_chargingProfile + 1;
  8880. i = i + 1;
  8881. //DEBUG_INFO("chargingProfileId Found\n");
  8882. }
  8883. memset(word, 0, ARRAY_SIZE(word));
  8884. }
  8885. fclose(fptr1);
  8886. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8887. }
  8888. //Check TxDefaultProfile_0.json exit
  8889. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8890. {
  8891. i = 0;
  8892. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8893. //Check Charging Profile Count
  8894. while(fscanf(fptr1, "%s", word) != EOF)
  8895. {
  8896. //DEBUG_INFO("word=%s\n",word);
  8897. if(strstr(word, "chargingProfileId")!= NULL)
  8898. {
  8899. //DEBUG_INFO("test chargingProfileId \n");
  8900. n_chargingProfile = n_chargingProfile + 1;
  8901. i = i + 1;
  8902. //DEBUG_INFO("chargingProfileId Found\n");
  8903. }
  8904. memset(word, 0, ARRAY_SIZE(word));
  8905. }
  8906. fclose(fptr1);
  8907. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8908. }
  8909. //Check TxDefaultProfile_%d.json
  8910. for(int j=1; j <= gunTotalNumber; j++)
  8911. {
  8912. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8913. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8914. if((access(fnametemp,F_OK))!=-1)
  8915. {
  8916. i = 0;
  8917. fptr1 = fopen(fnametemp, "r");
  8918. //Check Charging Profile Count
  8919. while(fscanf(fptr1, "%s", word) != EOF)
  8920. {
  8921. //DEBUG_INFO("word=%s\n",word);
  8922. if(strstr(word, "chargingProfileId")!= NULL)
  8923. {
  8924. //DEBUG_INFO("test chargingProfileId \n");
  8925. n_chargingProfile = n_chargingProfile + 1;
  8926. i = i + 1;
  8927. //DEBUG_INFO("chargingProfileId Found\n");
  8928. }
  8929. memset(word, 0, ARRAY_SIZE(word));
  8930. }
  8931. fclose(fptr1);
  8932. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8933. }
  8934. }
  8935. //Check TxProfile_%d.json
  8936. for(int j=1; j <= gunTotalNumber; j++)
  8937. {
  8938. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8939. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8940. if((access(fnametemp,F_OK))!=-1)
  8941. {
  8942. i = 0;
  8943. fptr1 = fopen(fnametemp, "r");
  8944. //Check Charging Profile Count
  8945. while(fscanf(fptr1, "%s", word) != EOF)
  8946. {
  8947. //DEBUG_INFO("word=%s\n",word);
  8948. if(strstr(word, "chargingProfileId")!= NULL)
  8949. {
  8950. //DEBUG_INFO("test chargingProfileId \n");
  8951. n_chargingProfile = n_chargingProfile + 1;
  8952. i = i + 1;
  8953. //DEBUG_INFO("chargingProfileId Found\n");
  8954. }
  8955. memset(word, 0, ARRAY_SIZE(word));
  8956. }
  8957. fclose(fptr1);
  8958. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8959. }
  8960. }
  8961. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8962. {
  8963. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8964. goto end;
  8965. }
  8966. }
  8967. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8968. //**********************************Write to File********************************************************/
  8969. FILE *infile;
  8970. FILE *outfile;
  8971. // open file for writing
  8972. infile = fopen (filename, "r");
  8973. outfile = fopen (tempfile, "w");
  8974. int d =0;
  8975. d = fgetc(infile);
  8976. //DEBUG_INFO("d:%d\n",d);
  8977. rewind(infile);
  8978. //*璉 瘚 辣蝏     1嚗   0 */
  8979. if(d == EOF)
  8980. {
  8981. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8982. fprintf(outfile,"%s\n",payload);
  8983. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8984. fclose(infile);
  8985. fclose(outfile);
  8986. sprintf(rmFileCmd,"rm -f %s",filename);
  8987. system(rmFileCmd);
  8988. rename(tempfile, filename);
  8989. sleep(1);
  8990. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8991. //system(rmFileCmd);
  8992. }
  8993. else
  8994. {
  8995. char buf[1000]={0};
  8996. int ChargingProfileAdded = FALSE;
  8997. while (fgets(buf, sizeof(buf), infile) != NULL)
  8998. {
  8999. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9000. //*************************tempconnectorIdInt*********************************/
  9001. loc = strstr(buf, "connectorId");
  9002. c = 0;
  9003. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9004. while (loc[strlen("connectorId")+2+c] != ',')
  9005. {
  9006. sstr[c] = loc[strlen("connectorId")+2+c];
  9007. c++;
  9008. }
  9009. sstr[c] = '\0';
  9010. tempconnectorIdInt = atoi(sstr);
  9011. //*************************tempchargingProfileIdInt*********************************/
  9012. loc = strstr(buf, "chargingProfileId");
  9013. c = 0;
  9014. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9015. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9016. {
  9017. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9018. c++;
  9019. }
  9020. sstr[c] = '\0';
  9021. tempchargingProfileIdInt = atoi(sstr);
  9022. //*************************tempstackLevelInt*********************************/
  9023. loc = strstr(buf, "stackLevel");
  9024. c = 0;
  9025. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9026. while (loc[strlen("stackLevel")+2+c] != ',')
  9027. {
  9028. sstr[c] = loc[strlen("stackLevel")+2+c];
  9029. c++;
  9030. }
  9031. sstr[c] = '\0';
  9032. tempstackLevelInt = atoi(sstr);
  9033. //*************************tempchargingProfilePurposeStr*********************************/
  9034. loc = strstr(payload, "chargingProfilePurpose");
  9035. c = 0;
  9036. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9037. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9038. {
  9039. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9040. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9041. c++;
  9042. }
  9043. sstr[c] = '\0';
  9044. strcpy(tempchargingProfilePurposeStr,sstr);
  9045. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9046. {
  9047. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9048. {
  9049. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9050. if(ChargingProfileAdded == FALSE)
  9051. {
  9052. fprintf(outfile,"%s\n",payload);
  9053. ChargingProfileAdded = TRUE;
  9054. }
  9055. }
  9056. else
  9057. {
  9058. if(tempstackLevelInt < stackLevelInt)
  9059. {
  9060. if(ChargingProfileAdded == FALSE)
  9061. {
  9062. fprintf(outfile,"%s\n",payload);
  9063. ChargingProfileAdded = TRUE;
  9064. fprintf(outfile,"%s\n",buf);
  9065. }
  9066. else
  9067. {
  9068. fprintf(outfile,"%s\n",buf);
  9069. }
  9070. }
  9071. else
  9072. {
  9073. if(ChargingProfileAdded == FALSE)
  9074. {
  9075. fprintf(outfile,"%s\n",buf);
  9076. fprintf(outfile,"%s\n",payload);
  9077. ChargingProfileAdded = TRUE;
  9078. }
  9079. else
  9080. {
  9081. fprintf(outfile,"%s\n",buf);
  9082. }
  9083. }
  9084. }
  9085. }
  9086. else
  9087. {
  9088. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9089. {
  9090. if(ChargingProfileAdded == FALSE)
  9091. {
  9092. fprintf(outfile,"%s\n",payload);
  9093. ChargingProfileAdded = TRUE;
  9094. fprintf(outfile,"%s\n",buf);
  9095. }
  9096. else
  9097. {
  9098. fprintf(outfile,"%s\n",buf);
  9099. }
  9100. }
  9101. else if(tempstackLevelInt < stackLevelInt)
  9102. {
  9103. if(ChargingProfileAdded == FALSE)
  9104. {
  9105. fprintf(outfile,"%s\n",payload);
  9106. ChargingProfileAdded = TRUE;
  9107. fprintf(outfile,"%s\n",buf);
  9108. }
  9109. else
  9110. {
  9111. fprintf(outfile,"%s\n",buf);
  9112. }
  9113. }
  9114. else
  9115. {
  9116. if(ChargingProfileAdded == FALSE)
  9117. {
  9118. fprintf(outfile,"%s\n",buf);
  9119. fprintf(outfile,"%s\n",payload);
  9120. ChargingProfileAdded = TRUE;
  9121. }
  9122. else
  9123. {
  9124. fprintf(outfile,"%s\n",buf);
  9125. }
  9126. }
  9127. }
  9128. } // end of while loop
  9129. fclose(infile);
  9130. fclose(outfile);
  9131. sprintf(rmFileCmd,"rm -f %s",filename);
  9132. system(rmFileCmd);
  9133. rename(tempfile, filename);
  9134. sleep(1);
  9135. result = TRUE;
  9136. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9137. }
  9138. end:
  9139. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9140. return result;
  9141. return result;
  9142. }
  9143. int handleTriggerMessageRequest(char *uuid, char *payload)
  9144. {
  9145. mtrace();
  9146. int result = FAIL;
  9147. int connectorIdIsNULL = FALSE;
  9148. int connectorIdInt =0;
  9149. char sstr[40]={0},sstrtemp[100]={ 0 };
  9150. char requestedMessagestr[40]={0};
  9151. char comfirmstr[20]={0};
  9152. int c = 0;
  9153. char *loc;
  9154. DEBUG_INFO("handleTriggerMessageRequest\n");
  9155. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9156. strcpy(sstrtemp, stringtrimspace(payload));
  9157. c = 0;
  9158. loc = strstr(sstrtemp, "requestedMessage");
  9159. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9160. {
  9161. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9162. c++;
  9163. }
  9164. sstr[c] = '\0';
  9165. strcpy(requestedMessagestr, sstr);
  9166. c = 0;
  9167. loc = strstr(sstrtemp, "connectorId");
  9168. if(loc == NULL)
  9169. {
  9170. connectorIdIsNULL = TRUE;
  9171. }
  9172. else
  9173. {
  9174. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9175. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9176. {
  9177. sstr[c] = loc[strlen("connectorId")+2+c];
  9178. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9179. c++;
  9180. }
  9181. sstr[c] = '\0';
  9182. connectorIdInt = atoi(sstr);
  9183. }
  9184. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9185. {
  9186. //connectorIdInt = json_object_get_int(connectorId);
  9187. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9188. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9189. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9190. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9191. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9192. }
  9193. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9194. {
  9195. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9196. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9197. return TRUE;
  9198. }
  9199. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9200. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9201. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9202. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9203. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9204. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9205. {
  9206. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9207. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9208. return TRUE;
  9209. }
  9210. else
  9211. {
  9212. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9213. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9214. }
  9215. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9216. {
  9217. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9218. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9219. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9220. {
  9221. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9222. }
  9223. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9224. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9225. }
  9226. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9227. {
  9228. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9229. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9230. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9231. }
  9232. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9233. {
  9234. sendBootNotificationRequest();
  9235. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9236. }
  9237. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9238. {
  9239. sendHeartbeatRequest(connectorIdInt);
  9240. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9241. }
  9242. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9243. {
  9244. if(connectorIdIsNULL == FALSE)
  9245. {
  9246. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9247. {
  9248. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9249. sendMeterValuesRequest(connectorIdInt -1);
  9250. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9251. }
  9252. }
  9253. else
  9254. {
  9255. for(int idx=0;idx< gunTotalNumber;idx++)
  9256. {
  9257. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9258. sendMeterValuesRequest(idx);
  9259. }
  9260. }
  9261. }
  9262. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9263. {
  9264. if(connectorIdIsNULL == FALSE)
  9265. {
  9266. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9267. {
  9268. sendStatusNotificationRequest(connectorIdInt -1);
  9269. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9270. }
  9271. }
  9272. else
  9273. {
  9274. for(int idx=0;idx< gunTotalNumber;idx++)
  9275. sendStatusNotificationRequest(idx);
  9276. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9277. }
  9278. }
  9279. return result;
  9280. }
  9281. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9282. {
  9283. mtrace();
  9284. int result = FAIL;
  9285. char sstr[6]={0},sstrtemp[50]={ 0 };
  9286. int connectorIdInt =0;
  9287. char comfirmstr[20]={0};
  9288. int c = 0;
  9289. int tempIndex = 0;
  9290. char *loc;
  9291. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9292. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9293. strcpy(sstrtemp, stringtrimspace(payload));
  9294. c = 0;
  9295. loc = strstr(sstrtemp, "connectorId");
  9296. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9297. while (loc[strlen("connectorId")+2+c] != '}')
  9298. {
  9299. sstr[c] = loc[strlen("connectorId")+2+c];
  9300. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9301. c++;
  9302. }
  9303. sstr[c] = '\0';
  9304. connectorIdInt = atoi(sstr);
  9305. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9306. if(gunTotalNumber == 0)
  9307. {
  9308. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9309. goto end;
  9310. }
  9311. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9312. {
  9313. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9314. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9315. goto end;
  9316. }
  9317. else
  9318. {
  9319. //check Transaction active
  9320. if(gunType[connectorIdInt-1] == 'J')
  9321. {
  9322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9323. {
  9324. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9325. }
  9326. else
  9327. {
  9328. tempIndex = connectorIdInt -1;
  9329. }
  9330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9331. {
  9332. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9333. {
  9334. //stop Transaction
  9335. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9336. }
  9337. }
  9338. }
  9339. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9340. {
  9341. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9342. {
  9343. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9344. }
  9345. else
  9346. {
  9347. tempIndex = connectorIdInt -1;
  9348. }
  9349. for (int index = 0; index < CCS_QUANTITY; index++)
  9350. {
  9351. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9352. {
  9353. //stop Transaction
  9354. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9355. }
  9356. }
  9357. }
  9358. else if(gunType[connectorIdInt-1] == 'G')
  9359. {
  9360. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9361. {
  9362. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9363. }
  9364. else
  9365. {
  9366. tempIndex = connectorIdInt -1;
  9367. }
  9368. for (int index = 0; index < GB_QUANTITY; index++)
  9369. {
  9370. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9371. {
  9372. //stop Transaction
  9373. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9374. }
  9375. }
  9376. }
  9377. else
  9378. {
  9379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9380. {
  9381. tempIndex = 2;
  9382. }
  9383. else
  9384. {
  9385. tempIndex = connectorIdInt-1;
  9386. }
  9387. for (int index = 0; index < AC_QUANTITY; index++)
  9388. {
  9389. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9390. {
  9391. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9392. }
  9393. }
  9394. }
  9395. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9396. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9397. result = TRUE;
  9398. return result;
  9399. }
  9400. end:
  9401. //json_object_put(obj); --- remove temporally
  9402. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9403. return result;
  9404. }
  9405. static char UpdateFirmwarepayloadData[300]={0};
  9406. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9407. {
  9408. mtrace();
  9409. int result = FAIL;
  9410. pthread_t t;
  9411. sendUpdateFirmwareConfirmation(uuid);
  9412. memset(UpdateFirmwarepayloadData, 0, 300);
  9413. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9414. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9415. ////pthread_join(t, NULL); //
  9416. //pthread_detach(t);
  9417. //sendUpdateFirmwareConfirmation(uuid);
  9418. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9419. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9420. return result;
  9421. }
  9422. void *UpdateFirmwareProcess(void *data)
  9423. {
  9424. pthread_detach(pthread_self());
  9425. mtrace();
  9426. int retriesInt =0, retryIntervalInt=0;
  9427. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9428. int port=0;
  9429. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9430. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9431. //char comfirmstr[20];
  9432. int isSuccess = 0;
  9433. char ftpbuf[200];
  9434. char temp[100];
  9435. char * pch;
  9436. int retriesISNULL=FALSE;
  9437. int retryInterval=FALSE;
  9438. int c = 0;
  9439. //int i = 0;
  9440. char *loc;
  9441. char sstr[300]={ 0 };
  9442. char str[300]={ 0 };
  9443. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9444. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9445. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9446. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9447. //***************location **************/
  9448. loc = strstr(str, "location");
  9449. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9450. c = 0;
  9451. while (loc[3+strlen("location")+c] != '\"')
  9452. {
  9453. sstr[c] = loc[3+strlen("location")+c];
  9454. c++;
  9455. }
  9456. sstr[c] = '\0';
  9457. strcpy(locationstr, sstr);
  9458. //***************retries**************/
  9459. c = 0;
  9460. loc = strstr(str, "retries");
  9461. if(loc == NULL)
  9462. {
  9463. retriesISNULL=TRUE;
  9464. }
  9465. else
  9466. {
  9467. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9468. while (loc[strlen("retries")+2+c] != ',')
  9469. {
  9470. sstr[c] = loc[strlen("retries")+2+c];
  9471. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9472. c++;
  9473. }
  9474. sstr[c] = '\0';
  9475. }
  9476. if(retriesISNULL == FALSE)
  9477. {
  9478. retriesInt = atoi(sstr);
  9479. }
  9480. //***************retrieveDate **************/
  9481. loc = strstr(str, "retrieveDate");
  9482. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9483. c = 0;
  9484. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9485. {
  9486. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9487. c++;
  9488. }
  9489. sstr[c] = '\0';
  9490. strcpy(retrieveDatestr, sstr);
  9491. //***************retryInterval **************/
  9492. c = 0;
  9493. loc = strstr(str, "retryInterval");
  9494. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9495. if(loc == NULL)
  9496. {
  9497. retryInterval=TRUE;
  9498. }
  9499. else
  9500. {
  9501. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9502. {
  9503. sstr[c] = loc[strlen("retryInterval")+2+c];
  9504. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9505. c++;
  9506. }
  9507. sstr[c] = '\0';
  9508. }
  9509. if(retryInterval==FALSE)
  9510. {
  9511. retryIntervalInt = atoi(sstr);
  9512. }
  9513. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9514. memset(path, 0, ARRAY_SIZE(path));
  9515. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9516. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9517. if(strncmp(locationstr,"http", 4) == 0)
  9518. {
  9519. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9520. protocol, host, path);
  9521. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9522. // protocol, user, password, host, path);
  9523. sprintf(ftppath,"/%s", path);
  9524. //DEBUG_INFO("protocol =%s\n",protocol);
  9525. //DEBUG_INFO("host =%s\n",host);
  9526. //DEBUG_INFO("path =%s\n",path);
  9527. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9528. int ftppathlen=strlen(ftppath);
  9529. int i=1;
  9530. char filenametemp[50];
  9531. while(i < ftppathlen)
  9532. {
  9533. int len=ftppathlen-i;
  9534. if(ftppath[len]== 47) // '/' ascll code: 47
  9535. {
  9536. DEBUG_INFO("compare '/' all right\n");
  9537. break;
  9538. }
  9539. i=i+1;
  9540. }
  9541. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9542. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9543. filenametemp[i+1] = 0;
  9544. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9545. do{
  9546. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9547. sleep(retryIntervalInt);
  9548. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9549. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9550. if(!isSuccess)
  9551. {
  9552. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9553. }
  9554. else
  9555. {
  9556. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9557. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9558. //isUpdateRequest = TRUE;
  9559. }
  9560. }
  9561. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9562. {
  9563. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9564. memset(temp, 0, ARRAY_SIZE(temp));
  9565. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9566. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9567. int ftppathlen=strlen(ftpbuf);
  9568. int i=1;
  9569. char filenametemp[50];
  9570. while(i < ftppathlen)
  9571. {
  9572. int len=ftppathlen-i;
  9573. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9574. {
  9575. DEBUG_INFO(" compare '/' all right\n");
  9576. break;
  9577. }
  9578. i=i+1;
  9579. }
  9580. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9581. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9582. filenametemp[i+1] = 0;
  9583. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9584. pch=strchr(temp,'@');
  9585. if(pch==NULL)
  9586. {
  9587. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9588. protocol, host, &port, path);
  9589. strcpy(user,"anonymous");
  9590. strcpy(password,"");
  9591. }
  9592. else
  9593. {
  9594. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9595. protocol, user, password, host, &port, path);
  9596. }
  9597. sscanf(host,"%[^/]%s",host1, path1);
  9598. sprintf(ftppath,"%s", path1);
  9599. //DEBUG_INFO("protocol =%s\n",protocol);
  9600. //DEBUG_INFO("user =%s\n",user);
  9601. //DEBUG_INFO("password =%s\n",password);
  9602. //DEBUG_INFO("host1 =%s\n",host1);
  9603. //DEBUG_INFO("port =%d\n",port);
  9604. //DEBUG_INFO("path1 =%s\n",path1);
  9605. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9606. //ftpFile(host, user, password, port, ftppath, fname);
  9607. //download firmware pthred
  9608. if(port == 0)
  9609. {
  9610. port = 21;
  9611. }
  9612. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9613. do{
  9614. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9615. sleep(retryIntervalInt);
  9616. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9617. if(!isSuccess)
  9618. {
  9619. //BulldogUtil.sleepMs(interval*1000);
  9620. DEBUG_INFO("Update firmware request and download file fail.\n");
  9621. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9622. }
  9623. else
  9624. {
  9625. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9626. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9627. //isUpdateRequest = TRUE;
  9628. }
  9629. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9630. }
  9631. else
  9632. {
  9633. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9634. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9635. }
  9636. pthread_exit(NULL);
  9637. }
  9638. //==========================================
  9639. // Handle server response routine
  9640. //==========================================
  9641. void handleAuthorizeResponse(char *payload, int gun_index)
  9642. {
  9643. mtrace();
  9644. char expiryDatestr[30]={0};
  9645. char parentIdTagstr[20]={0};
  9646. char statusstr[20]={0};
  9647. char expiryDatestrtemp[30]={0};
  9648. char parentIdTagstrtemp[20]={0};
  9649. char IdTagstrtemp[20]={0};
  9650. char statusstrtemp[20]={0};
  9651. int expiryDateISNULL=FALSE;
  9652. int parentIdTagISNULL=FALSE;
  9653. char sstr[160]={0};
  9654. char* filename = AuthorizationCache_JSON;
  9655. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9656. char *loc;
  9657. int resultRename=0;
  9658. int responseIdTagInfoAsZero= 0;
  9659. char rmFileCmd[50]={0};
  9660. DEBUG_INFO("handleAuthorizeResponse...\n");
  9661. json_object *Authorize;
  9662. Authorize = json_tokener_parse(payload);
  9663. if(!is_error(Authorize))
  9664. {
  9665. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9666. {
  9667. // Required data
  9668. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9669. // Optional data
  9670. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9671. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9672. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9673. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9674. }
  9675. }
  9676. json_object_put(Authorize);
  9677. if(expiryDateISNULL == FALSE)
  9678. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9679. if(parentIdTagISNULL == FALSE)
  9680. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9681. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9682. //Update idTag information to authorization cache if supproted
  9683. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9684. {
  9685. if((access(filename,F_OK))!=-1)
  9686. {
  9687. printf("AuthorizationCache exist.\n");
  9688. }
  9689. else
  9690. {
  9691. printf("AuthorizationCache not exist\n");
  9692. FILE *log = fopen(filename, "w+");
  9693. if(log == NULL)
  9694. {
  9695. printf("log is NULL\n");
  9696. goto out;
  9697. }
  9698. else
  9699. {
  9700. fclose(log);
  9701. }
  9702. }
  9703. FILE *infile;
  9704. FILE *outfile;
  9705. // open file for writing
  9706. infile = fopen (filename, "r");
  9707. outfile = fopen (tempfile, "w");
  9708. int c;
  9709. c = fgetc(infile);
  9710. //DEBUG_INFO("c:%d\n",c);
  9711. rewind(infile);
  9712. if(c == EOF)
  9713. {
  9714. DEBUG_INFO("Orignal File is NULL\n");
  9715. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9716. {
  9717. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9718. }
  9719. else
  9720. {
  9721. strcpy(expiryDatestrtemp, "");
  9722. }
  9723. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9724. {
  9725. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9726. }
  9727. else
  9728. {
  9729. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9730. }
  9731. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9732. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9733. fclose(infile);
  9734. fclose(outfile);
  9735. sprintf(rmFileCmd,"rm -f %s",filename);
  9736. system(rmFileCmd);
  9737. resultRename = rename(tempfile, filename);
  9738. if(resultRename == 0)
  9739. {
  9740. printf("File renamed successfully");
  9741. }
  9742. else
  9743. {
  9744. printf("Error: unable to rename the file");
  9745. }
  9746. }
  9747. else
  9748. {
  9749. char buf[160]={0};
  9750. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9751. {
  9752. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9753. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9754. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9755. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9756. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9757. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9758. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9759. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9760. //------------------IdTag-----------------------
  9761. loc = strstr(buf, "idTag");
  9762. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9763. c = 0;
  9764. while (loc[3+strlen("idTag")+c] != '\"')
  9765. {
  9766. sstr[c] = loc[3+strlen("idTag")+c];
  9767. c++;
  9768. }
  9769. sstr[c] = '\0';
  9770. strcpy(IdTagstrtemp,sstr);
  9771. //*********************expiryDate***************/
  9772. loc = strstr(buf, "expiryDate");
  9773. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9774. c = 0;
  9775. while (loc[3+strlen("expiryDate")+c] != '\"')
  9776. {
  9777. sstr[c] = loc[3+strlen("expiryDate")+c];
  9778. c++;
  9779. }
  9780. sstr[c] = '\0';
  9781. strcpy(expiryDatestr,sstr);
  9782. //*********************parentIdTag***************/
  9783. loc = strstr(buf, "parentIdTag");
  9784. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9785. c = 0;
  9786. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9787. {
  9788. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9789. c++;
  9790. }
  9791. sstr[c] = '\0';
  9792. strcpy(parentIdTagstr,sstr);
  9793. //*********************status***************/
  9794. loc = strstr(buf, "status");
  9795. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9796. c = 0;
  9797. while (loc[3+strlen("status")+c] != '\"')
  9798. {
  9799. sstr[c] = loc[3+strlen("status")+c];
  9800. c++;
  9801. }
  9802. sstr[c] = '\0';
  9803. strcpy(statusstr,sstr);
  9804. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9805. {
  9806. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9807. responseIdTagInfoAsZero = 1;
  9808. }
  9809. else
  9810. {
  9811. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9812. }
  9813. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9814. {
  9815. //modify item
  9816. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9817. {
  9818. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9819. }
  9820. else
  9821. {
  9822. strcpy(expiryDatestrtemp, "");
  9823. }
  9824. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9825. {
  9826. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9827. }
  9828. else
  9829. {
  9830. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9831. }
  9832. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9833. }
  9834. else
  9835. {
  9836. //wrie original item
  9837. strcpy(expiryDatestrtemp, expiryDatestr);
  9838. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9839. strcpy(statusstrtemp, statusstr);
  9840. }
  9841. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9842. }
  9843. fclose(infile);
  9844. fclose(outfile);
  9845. sprintf(rmFileCmd,"rm -f %s",filename);
  9846. system(rmFileCmd);
  9847. resultRename = rename(tempfile, filename);
  9848. if(resultRename == 0)
  9849. {
  9850. DEBUG_INFO("File renamed successfully");
  9851. }
  9852. else
  9853. {
  9854. DEBUG_INFO("Error: unable to rename the file");
  9855. }
  9856. }
  9857. }
  9858. out:
  9859. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9860. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9861. authorizeRetryTimes = 0;
  9862. }
  9863. char * strtrimc( char * s )
  9864. {
  9865. char * p1 = s;
  9866. char * p2 = s;
  9867. while(*p1 != '\0')
  9868. {
  9869. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9870. {
  9871. if(*p1 != ',')
  9872. {
  9873. p1 ++;
  9874. }
  9875. else
  9876. {
  9877. break;
  9878. }
  9879. }
  9880. if(*p1 != ',')
  9881. {
  9882. * p2 ++ = *p1 ++;
  9883. //printf("p2=%s\n",p2);
  9884. }
  9885. else
  9886. {
  9887. break;
  9888. }
  9889. }
  9890. *p2 = '\0';
  9891. return (s);
  9892. }
  9893. void handleBootNotificationResponse(char *payload, int gun_index)
  9894. {
  9895. mtrace();
  9896. char statusStr[12]={0};
  9897. char currentTimeStr[30]={0};
  9898. int intervalInt = 0;
  9899. struct tm tp;
  9900. char buf[28]={0};
  9901. char timebuf[50]={0};
  9902. DEBUG_INFO("handleBootNotificationResponse...\n");
  9903. json_object *BootNotification;
  9904. BootNotification = json_tokener_parse(payload);
  9905. if(!is_error(BootNotification))
  9906. {
  9907. // Required data
  9908. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9909. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9910. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9911. }
  9912. json_object_put(BootNotification);
  9913. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9914. BootNotificationInterval = intervalInt;
  9915. HeartBeatWaitTime = intervalInt;
  9916. //write back to ShmOCPP16Data->BootNotification
  9917. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9918. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9919. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9920. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9921. {
  9922. server_sign = TRUE;
  9923. server_pending =FALSE;
  9924. }
  9925. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9926. {
  9927. server_pending = TRUE;
  9928. }
  9929. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9930. tp.tm_isdst = -1;
  9931. //time_t utc = mktime(&tp);
  9932. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9933. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9934. sprintf(timebuf,"date -s '%s'",buf);
  9935. system(timebuf);
  9936. srand(time(NULL));
  9937. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9938. //==============================================
  9939. // RTC sync
  9940. //==============================================
  9941. system("/sbin/hwclock -w --systohc");
  9942. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9943. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9944. }
  9945. void handleDataTransferResponse(char *payload, int gun_index)
  9946. {
  9947. char sstr[160]={0};//sstr[200]={ 0 };
  9948. int c = 0;
  9949. char *loc;
  9950. DEBUG_INFO("handleDataTransferResponse ...\n");
  9951. loc = strstr(payload, "status");
  9952. printf("loc=%s\n",loc);
  9953. c = 0;
  9954. while (loc[3+strlen("status")+c] != '\"')
  9955. {
  9956. sstr[c] = loc[3+strlen("status")+c];
  9957. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9958. c++;
  9959. }
  9960. sstr[c] = '\0';
  9961. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9962. }
  9963. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9964. {
  9965. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9966. //struct json_object *obj;
  9967. // obj = json_tokener_parse(payload);
  9968. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9969. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9970. //No fields are defined.
  9971. }
  9972. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9973. {
  9974. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9975. //struct json_object *obj;
  9976. // obj = json_tokener_parse(payload);
  9977. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9978. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9979. //No fields are defined.
  9980. }
  9981. void handleHeartbeatResponse(char *payload, int gun_index)
  9982. {
  9983. mtrace();
  9984. struct tm tp;
  9985. char buf[28]={0};
  9986. char timebuf[50]={0};
  9987. DEBUG_INFO("handleHeartbeatResponse...\n");
  9988. json_object *Heartbeat;
  9989. Heartbeat = json_tokener_parse(payload);
  9990. if(!is_error(Heartbeat))
  9991. {
  9992. // Required data
  9993. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9994. }
  9995. json_object_put(BootNotification);
  9996. if(FirstHeartBeat == 0)
  9997. {
  9998. FirstHeartBeat = 1;
  9999. DEBUG_INFO("FirstHeartBeat \n");
  10000. }
  10001. HeartBeatWithNOResponse = 0;
  10002. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10003. tp.tm_isdst = -1;
  10004. //time_t utc = mktime(&tp);
  10005. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  10006. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  10007. sprintf(timebuf,"date -s '%s'",buf);
  10008. system(timebuf);
  10009. //==============================================
  10010. // RTC sync
  10011. //==============================================
  10012. system("/sbin/hwclock -w --systohc");
  10013. //===============================================
  10014. //Print Out HeartBeat log
  10015. //===============================================
  10016. {
  10017. double diff_t;
  10018. struct tm tp,tp1;
  10019. // BootNotification Receive Time
  10020. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  10021. tp.tm_isdst = -1;
  10022. time_t BootNotificationReceiveTime = mktime(&tp);
  10023. //HeartBeat Receive Time
  10024. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  10025. tp1.tm_isdst = -1;
  10026. time_t HeartBeatReceiveTime = mktime(&tp1);
  10027. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  10028. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  10029. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  10030. {
  10031. HeartBeatCountPerHour = (int)diff_t / 3600;
  10032. DEBUG_INFO("handleHeartbeatResponse ...\n");
  10033. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  10034. }
  10035. }
  10036. }
  10037. void handleMeterValuesResponse(char *payload, int gun_index)
  10038. {
  10039. mtrace();
  10040. DEBUG_INFO("handleMeterValuesResponse...\n");
  10041. }
  10042. void handleStartTransactionResponse(char *payload, int gun_index)
  10043. {
  10044. mtrace();
  10045. //int transactionIdInt = 0;
  10046. FILE *outfile;
  10047. char data[100]={0};
  10048. DEBUG_INFO("handleStartTransactionResponse...\n");
  10049. json_object *StartTransaction;
  10050. StartTransaction = json_tokener_parse(payload);
  10051. if(!is_error(StartTransaction))
  10052. {
  10053. // Required data
  10054. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  10055. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  10056. // Optional data
  10057. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  10058. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  10059. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10060. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  10061. }
  10062. json_object_put(StartTransaction);
  10063. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  10064. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  10065. //-----------Start : write to the Queue TransactionId file -----------------//
  10066. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  10067. {}
  10068. else
  10069. {
  10070. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  10071. if(log == NULL)
  10072. {
  10073. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10074. return ;
  10075. }
  10076. else
  10077. {
  10078. fclose(log);
  10079. }
  10080. }
  10081. // open file for writing
  10082. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10083. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10084. {
  10085. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10086. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10087. fputs(data, outfile);
  10088. fclose (outfile);
  10089. }
  10090. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10091. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10092. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10093. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10094. }
  10095. void handleStatusNotificationResponse(char *payload, int gun_index)
  10096. {
  10097. mtrace();
  10098. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10099. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10100. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10101. }
  10102. void handleStopTransactionnResponse(char *payload, int gun_index)
  10103. {
  10104. mtrace();
  10105. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10106. json_object *StopTransaction;
  10107. StopTransaction = json_tokener_parse(payload);
  10108. if(!is_error(StopTransaction))
  10109. {
  10110. // Optional data
  10111. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10112. {
  10113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10114. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10115. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10116. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10117. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10118. }
  10119. }
  10120. json_object_put(StopTransaction);
  10121. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10122. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10123. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10124. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10125. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10126. }
  10127. //==========================================
  10128. // Handle Error routine
  10129. //==========================================
  10130. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10131. {
  10132. mtrace();
  10133. #ifdef SystemLogMessage
  10134. DEBUG_INFO("errorCode: %s\n", errorCode);
  10135. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10136. DEBUG_INFO("errorDetails: %s\n", payload);
  10137. #endif
  10138. }
  10139. //===============================================
  10140. // Common routine
  10141. //===============================================
  10142. int initialConfigurationTable(void)
  10143. {
  10144. //clock_t start_t, end_t, total_t;
  10145. FILE *fp;
  10146. FILE *outfile;
  10147. char str[200]={0};
  10148. char sstr[100]={0};
  10149. int c = 0;
  10150. char *loc;
  10151. DEBUG_INFO("initialConfigurationTable...\n");
  10152. //start_t = clock();
  10153. //printf("Starting of the program, start_t = %ld\n", start_t);
  10154. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10155. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10156. {
  10157. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10158. if(outfile == NULL)
  10159. {
  10160. DEBUG_INFO("Error opening file\n");
  10161. return FALSE;
  10162. }
  10163. /*Core Profile*/
  10164. //AllowOfflineTxForUnknownId
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10166. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10170. //AuthorizationCacheEnabled
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10174. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10175. //AuthorizeRemoteTxRequests
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10177. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10179. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10180. //BlinkRepeat
  10181. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10182. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10183. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10184. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10185. //ClockAlignedDataInterval
  10186. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10187. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10188. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10189. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10190. //ConnectionTimeOut
  10191. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10192. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10193. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10194. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10195. //GetConfigurationMaxKeys
  10196. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10197. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10199. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10200. // HeartbeatInterval
  10201. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10202. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10204. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10205. // LightIntensity
  10206. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10207. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10209. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10210. // LocalAuthorizeOffline
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10212. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10214. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10215. // LocalPreAuthorize
  10216. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10217. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10219. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10220. // MaxEnergyOnInvalidId
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10222. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10224. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10226. // MeterValuesAlignedData
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10231. // MeterValuesAlignedDataMaxLength
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "6");
  10236. // MeterValuesSampledData
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10239. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10240. 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");
  10241. // MeterValuesSampledDataMaxLength
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10243. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10244. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10245. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10246. // MeterValueSampleInterval
  10247. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10248. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10249. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10250. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10251. // MinimumStatusDuration
  10252. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10253. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10254. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10255. server_cycle_Status = 120; //StatusNotification cycle
  10256. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10257. // NumberOfConnectors
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10259. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10260. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10261. {
  10262. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10263. }
  10264. else
  10265. {
  10266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10267. }
  10268. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10269. // ResetRetries
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10271. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10273. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10274. // ConnectorPhaseRotation
  10275. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10276. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10278. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10279. // ConnectorPhaseRotationMaxLength
  10280. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10281. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10283. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10284. // StopTransactionOnEVSideDisconnect
  10285. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10288. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10289. // StopTransactionOnInvalidId
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10294. // StopTxnAlignedData
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10296. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10298. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10299. // StopTxnAlignedDataMaxLength
  10300. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10301. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10303. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10304. // StopTxnSampledData
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10306. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10308. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10309. // StopTxnSampledDataMaxLength
  10310. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10311. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10313. {
  10314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10315. }
  10316. else
  10317. {
  10318. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10319. }
  10320. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10321. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10322. // SupportedFeatureProfiles
  10323. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10325. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10326. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10327. // SupportedFeatureProfilesMaxLength
  10328. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10330. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10331. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10332. // TransactionMessageAttempts
  10333. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10335. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10336. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10337. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10338. // TransactionMessageRetryInterval
  10339. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10340. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10341. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10342. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10343. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10344. // UnlockConnectorOnEVSideDisconnect
  10345. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10346. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10348. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10349. // WebSocketPingInterval
  10350. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10353. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10354. //* Local Auth List Management Profile*/
  10355. #if 0
  10356. //For OCTT Test Case
  10357. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10360. #endif
  10361. #if 1
  10362. //LocalAuthListEnabled
  10363. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10364. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10366. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10367. #endif
  10368. //LocalAuthListMaxLength
  10369. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10370. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10371. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10372. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10373. //SendLocalListMaxLength
  10374. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10375. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10376. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10377. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10378. //ReserveConnectorZeroSupported
  10379. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10381. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10383. //* Smart Charging Profile */
  10384. //ChargeProfileMaxStackLevel
  10385. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10388. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10389. // ChargingScheduleAllowedChargingRateUnit
  10390. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10391. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10393. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10394. // ChargingScheduleMaxPeriods
  10395. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10396. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10397. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10398. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10399. // ConnectorSwitch3to1PhaseSupported
  10400. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10402. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10404. // MaxChargingProfilesInstalled
  10405. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10406. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10408. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10409. fclose(outfile);
  10410. }
  10411. else
  10412. {
  10413. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10414. char keystr[60]={0};
  10415. char readonlystr[10]={0};
  10416. char valuestr[100]={0};
  10417. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10418. if(fp == NULL) {
  10419. DEBUG_INFO("Error opening file");
  10420. return FALSE;
  10421. }
  10422. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10423. {
  10424. //DEBUG_INFO("Get Configuration \n");
  10425. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10426. //*************************key*********************************/
  10427. loc = strstr(str, "key");
  10428. c = 0;
  10429. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10430. while (loc[strlen("key")+3+c] != '\"')
  10431. {
  10432. sstr[c] = loc[strlen("key")+3+c];
  10433. c++;
  10434. }
  10435. sstr[c] = '\0';
  10436. strcpy(keystr,sstr);
  10437. //*************************readonly*********************************/
  10438. loc = strstr(str, "readonly");
  10439. c = 0;
  10440. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10441. while (loc[strlen("readonly")+2+c] != ',')
  10442. {
  10443. sstr[c] = loc[strlen("readonly")+2+c];
  10444. c++;
  10445. }
  10446. sstr[c] = '\0';
  10447. strcpy(readonlystr,sstr);
  10448. //*************************value*********************************/
  10449. loc = strstr(str, "value");
  10450. c = 0;
  10451. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10452. while (loc[strlen("value")+3+c] != '\"')
  10453. {
  10454. sstr[c] = loc[strlen("value")+3+c];
  10455. c++;
  10456. }
  10457. sstr[c] = '\0';
  10458. strcpy(valuestr,sstr);
  10459. // DEBUG_INFO("keystr=%s\n",keystr);
  10460. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10461. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10462. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10463. {
  10464. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10465. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10466. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10467. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10468. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10469. }
  10470. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10471. {
  10472. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10475. }
  10476. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10480. }
  10481. if(strcmp(keystr, "BlinkRepeat") == 0)
  10482. {
  10483. //Charger.BlinkRepeat = Integer.parseInt(value);
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10486. }
  10487. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10491. }
  10492. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10496. }
  10497. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10501. }
  10502. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10506. HeartBeatWaitTime = atoi(valuestr);
  10507. }
  10508. if(strcmp(keystr, "LightIntensity") == 0)
  10509. {
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10512. }
  10513. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10514. {
  10515. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10516. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10517. }
  10518. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10519. {
  10520. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10521. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10522. }
  10523. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10524. {
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10527. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10528. }
  10529. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10530. {
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10532. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10533. }
  10534. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10535. {
  10536. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10537. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10538. }
  10539. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10540. {
  10541. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10542. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10543. }
  10544. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10545. {
  10546. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10547. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10548. }
  10549. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10550. {
  10551. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10552. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10553. }
  10554. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10555. {
  10556. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10558. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10559. }
  10560. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10561. {
  10562. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10564. }
  10565. if(strcmp(keystr, "ResetRetries") == 0)
  10566. {
  10567. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10568. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10569. }
  10570. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10571. {
  10572. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10573. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10574. }
  10575. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10576. {
  10577. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10578. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10579. }
  10580. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10581. {
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10583. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10584. }
  10585. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10586. {
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10588. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10589. }
  10590. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10591. {
  10592. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10593. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10594. }
  10595. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10596. {
  10597. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10598. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10599. }
  10600. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10601. {
  10602. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10603. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10604. }
  10605. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10606. {
  10607. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10609. }
  10610. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10611. {
  10612. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10613. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10614. }
  10615. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10616. {
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10619. }
  10620. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10621. {
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10624. TransactionMessageAttemptsValue = atoi(valuestr);
  10625. }
  10626. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10627. {
  10628. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10630. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10631. }
  10632. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10633. {
  10634. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10635. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10636. }
  10637. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10638. {
  10639. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10640. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10641. }
  10642. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10643. {
  10644. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10646. }
  10647. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10648. {
  10649. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10651. }
  10652. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10653. {
  10654. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10655. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10656. }
  10657. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10658. {
  10659. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10660. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10661. }
  10662. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10663. {
  10664. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10665. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10666. }
  10667. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10668. {
  10669. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10671. }
  10672. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10673. {
  10674. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10676. }
  10677. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10678. {
  10679. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10680. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10681. }
  10682. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10683. {
  10684. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10685. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10686. }
  10687. }
  10688. fclose(fp);
  10689. }
  10690. return 0;
  10691. }
  10692. void StoreConfigurationTable(void)
  10693. {
  10694. FILE *outfile;
  10695. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10696. if(outfile == NULL)
  10697. {
  10698. DEBUG_INFO("Error opening file");
  10699. return ;
  10700. }
  10701. /*Core Profile*/
  10702. //AllowOfflineTxForUnknownId
  10703. /*
  10704. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10705. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10706. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10707. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10708. */
  10709. //DEBUG_INFO("data=%s\n",data);
  10710. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10711. //AuthorizationCacheEnabled
  10712. /*
  10713. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10714. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10715. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10716. */
  10717. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10718. //AuthorizeRemoteTxRequests
  10719. /*
  10720. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10721. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10722. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10723. */
  10724. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10725. //BlinkRepeat
  10726. /*
  10727. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10728. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10729. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10730. */
  10731. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10732. //ClockAlignedDataInterval
  10733. /*
  10734. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10735. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10736. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10737. */
  10738. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10739. //ConnectionTimeOut
  10740. /*
  10741. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10744. */
  10745. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10746. //GetConfigurationMaxKeys
  10747. /*
  10748. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10749. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10750. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10751. */
  10752. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10753. // HeartbeatInterval
  10754. /*
  10755. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10756. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10758. */
  10759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10760. // LightIntensity
  10761. /*
  10762. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10764. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10765. */
  10766. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10767. // LocalAuthorizeOffline
  10768. /*
  10769. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10770. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10771. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10772. */
  10773. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10774. // LocalPreAuthorize
  10775. /*
  10776. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10779. */
  10780. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10781. // MaxEnergyOnInvalidId
  10782. /*
  10783. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10786. */
  10787. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10788. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10789. // MeterValuesAlignedData
  10790. /*
  10791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10794. */
  10795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10796. // MeterValuesAlignedDataMaxLength
  10797. /*
  10798. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10801. */
  10802. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10803. // MeterValuesSampledData
  10804. /*
  10805. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10807. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10808. */
  10809. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10810. // MeterValuesSampledDataMaxLength
  10811. /*
  10812. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10813. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10815. */
  10816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10817. // MeterValueSampleInterval
  10818. /*
  10819. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10821. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10822. */
  10823. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10824. // MinimumStatusDuration
  10825. /*
  10826. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10827. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10828. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10829. */
  10830. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10831. // NumberOfConnectors
  10832. /*
  10833. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10835. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10836. {
  10837. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10838. }
  10839. else
  10840. {
  10841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10842. }
  10843. */
  10844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10845. // ResetRetries
  10846. /*
  10847. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10849. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10850. */
  10851. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10852. // ConnectorPhaseRotation
  10853. /*
  10854. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10855. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10857. */
  10858. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10859. // ConnectorPhaseRotationMaxLength
  10860. /*
  10861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10864. */
  10865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10866. // StopTransactionOnEVSideDisconnect
  10867. /*
  10868. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10870. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10871. */
  10872. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10873. // StopTransactionOnInvalidId
  10874. /*
  10875. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10876. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10878. */
  10879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10880. // StopTxnAlignedData
  10881. /*
  10882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10885. */
  10886. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10887. // StopTxnAlignedDataMaxLength
  10888. /*
  10889. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10892. */
  10893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10894. // StopTxnSampledData
  10895. /*
  10896. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10899. */
  10900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10901. // StopTxnSampledDataMaxLength
  10902. /*
  10903. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10904. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10906. */
  10907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10908. // SupportedFeatureProfiles
  10909. /*
  10910. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10913. */
  10914. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10915. // SupportedFeatureProfilesMaxLength
  10916. /*
  10917. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10920. */
  10921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10922. // TransactionMessageAttempts
  10923. /*
  10924. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10927. */
  10928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10929. // TransactionMessageRetryInterval
  10930. /*
  10931. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10933. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10934. */
  10935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10936. // UnlockConnectorOnEVSideDisconnect
  10937. /*
  10938. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10941. */
  10942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10943. // WebSocketPingInterval
  10944. /*
  10945. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10948. */
  10949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10950. //* Local Auth List Management Profile*/
  10951. //LocalAuthListEnabled
  10952. /*
  10953. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10954. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10956. */
  10957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10958. //LocalAuthListMaxLength
  10959. /*
  10960. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10963. */
  10964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10965. //SendLocalListMaxLength
  10966. /*
  10967. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10970. */
  10971. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10972. //ReserveConnectorZeroSupported
  10973. /*
  10974. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10975. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10976. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10977. */
  10978. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10979. //* Smart Charging Profile */
  10980. //ChargeProfileMaxStackLevel
  10981. /*
  10982. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10985. */
  10986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10987. // ChargingScheduleAllowedChargingRateUnit
  10988. /*
  10989. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10992. */
  10993. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10994. // ChargingScheduleMaxPeriods
  10995. /*
  10996. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10999. */
  11000. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11001. // ConnectorSwitch3to1PhaseSupported
  11002. /*
  11003. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11004. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11006. */
  11007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11008. // MaxChargingProfilesInstalled
  11009. /*
  11010. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11012. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  11013. */
  11014. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11015. fclose(outfile);
  11016. }
  11017. void getKeyValue(char *keyReq)
  11018. {
  11019. int isEmpty = FALSE;
  11020. int isKnowKey = FALSE;
  11021. DEBUG_INFO("keyReq = %s\n", keyReq);
  11022. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11023. isEmpty = TRUE;
  11024. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11025. {
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11027. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11029. {
  11030. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11031. }
  11032. else
  11033. {
  11034. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11035. }
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11037. isKnowKey = TRUE;
  11038. }
  11039. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11040. {
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11042. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11043. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11044. {
  11045. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11046. }
  11047. else
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11050. }
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11052. isKnowKey = TRUE;
  11053. }
  11054. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11055. {
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11059. {
  11060. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11061. }
  11062. else
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11065. }
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11067. isKnowKey = TRUE;
  11068. }
  11069. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11070. {
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11074. {
  11075. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11076. }
  11077. else
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11080. }
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11082. isKnowKey = TRUE;
  11083. }
  11084. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11085. {
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11088. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11089. {
  11090. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11091. }
  11092. else
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11095. }
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11097. isKnowKey = TRUE;
  11098. }
  11099. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11100. {
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11103. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11104. {
  11105. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11106. }
  11107. else
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11110. }
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11112. isKnowKey = TRUE;
  11113. }
  11114. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11115. {
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11118. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11119. {
  11120. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11121. }
  11122. else
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11125. }
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11127. isKnowKey = TRUE;
  11128. }
  11129. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11130. {
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11133. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11134. {
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11136. }
  11137. else
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11140. }
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11142. isKnowKey = TRUE;
  11143. }
  11144. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11145. {
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11148. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11149. {
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11151. }
  11152. else
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11155. }
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11157. isKnowKey = TRUE;
  11158. }
  11159. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11160. {
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11163. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11164. {
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11166. }
  11167. else
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11170. }
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11172. isKnowKey = TRUE;
  11173. }
  11174. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11175. {
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11178. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11179. {
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11181. }
  11182. else
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11185. }
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11187. isKnowKey = TRUE;
  11188. }
  11189. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11190. {
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11193. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11194. {
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11196. }
  11197. else
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11200. }
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11202. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11203. isKnowKey = TRUE;
  11204. }
  11205. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11209. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11212. }
  11213. else
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11216. }
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11218. isKnowKey = TRUE;
  11219. }
  11220. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11227. }
  11228. else
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11231. }
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11233. isKnowKey = TRUE;
  11234. }
  11235. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11236. {
  11237. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11239. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11242. }
  11243. else
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11246. }
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11248. isKnowKey = TRUE;
  11249. }
  11250. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11251. {
  11252. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11254. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11255. {
  11256. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11257. }
  11258. else
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11261. }
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11263. isKnowKey = TRUE;
  11264. }
  11265. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11266. {
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11269. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11270. {
  11271. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11272. }
  11273. else
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11276. }
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11278. isKnowKey = TRUE;
  11279. }
  11280. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11281. {
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11285. {
  11286. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11287. }
  11288. else
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11291. }
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11293. isKnowKey = TRUE;
  11294. }
  11295. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11296. {
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11299. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11300. {
  11301. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11302. }
  11303. else
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11306. }
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11308. isKnowKey = TRUE;
  11309. }
  11310. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11311. {
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11314. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11315. {
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11317. }
  11318. else
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11321. }
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11323. isKnowKey = TRUE;
  11324. }
  11325. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11326. {
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11329. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11332. }
  11333. else
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11336. }
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11338. isKnowKey = TRUE;
  11339. }
  11340. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11341. {
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11344. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11347. }
  11348. else
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11351. }
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11353. isKnowKey = TRUE;
  11354. }
  11355. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11359. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11362. }
  11363. else
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11366. }
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11368. isKnowKey = TRUE;
  11369. }
  11370. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11371. {
  11372. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11374. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11377. }
  11378. else
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11381. }
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11383. isKnowKey = TRUE;
  11384. }
  11385. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11386. {
  11387. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11389. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11392. }
  11393. else
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11396. }
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11398. isKnowKey = TRUE;
  11399. }
  11400. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11401. {
  11402. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11404. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11407. }
  11408. else
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11411. }
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11413. isKnowKey = TRUE;
  11414. }
  11415. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11416. {
  11417. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11419. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11422. }
  11423. else
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11426. }
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11428. isKnowKey = TRUE;
  11429. }
  11430. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11431. {
  11432. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11434. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11437. }
  11438. else
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11441. }
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11443. isKnowKey = TRUE;
  11444. }
  11445. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11446. {
  11447. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11449. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11452. }
  11453. else
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11456. }
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11458. isKnowKey = TRUE;
  11459. }
  11460. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11461. {
  11462. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11464. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11467. }
  11468. else
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11471. }
  11472. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11473. isKnowKey = TRUE;
  11474. }
  11475. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11476. {
  11477. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11479. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11482. }
  11483. else
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11486. }
  11487. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11488. isKnowKey = TRUE;
  11489. }
  11490. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11491. {
  11492. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11494. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11497. }
  11498. else
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11501. }
  11502. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11503. isKnowKey = TRUE;
  11504. }
  11505. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11506. {
  11507. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11509. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11512. }
  11513. else
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11516. }
  11517. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11518. isKnowKey = TRUE;
  11519. }
  11520. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11521. {
  11522. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11524. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11527. }
  11528. else
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11531. }
  11532. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11533. isKnowKey = TRUE;
  11534. }
  11535. #if 1
  11536. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11539. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11540. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11541. {
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11543. }
  11544. else
  11545. {
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11547. }
  11548. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11549. isKnowKey = TRUE;
  11550. }
  11551. #endif
  11552. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11553. {
  11554. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11556. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11557. {
  11558. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11559. }
  11560. else
  11561. {
  11562. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11563. }
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11565. isKnowKey = TRUE;
  11566. }
  11567. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11568. {
  11569. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11571. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11572. {
  11573. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11574. }
  11575. else
  11576. {
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11578. }
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11580. isKnowKey = TRUE;
  11581. }
  11582. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11585. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11586. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11587. {
  11588. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11589. }
  11590. else
  11591. {
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11593. }
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11595. isKnowKey = TRUE;
  11596. }
  11597. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11600. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11601. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11602. {
  11603. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11604. }
  11605. else
  11606. {
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11608. }
  11609. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11610. isKnowKey = TRUE;
  11611. }
  11612. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11615. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11616. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11617. {
  11618. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11619. }
  11620. else
  11621. {
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11623. }
  11624. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11625. isKnowKey = TRUE;
  11626. }
  11627. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11630. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11631. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11632. {
  11633. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11634. }
  11635. else
  11636. {
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11638. }
  11639. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11640. isKnowKey = TRUE;
  11641. }
  11642. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11645. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11646. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11647. {
  11648. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11649. }
  11650. else
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11653. }
  11654. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11655. isKnowKey = TRUE;
  11656. }
  11657. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11658. {
  11659. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11661. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11662. {
  11663. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11664. }
  11665. else
  11666. {
  11667. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11668. }
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11670. isKnowKey = TRUE;
  11671. }
  11672. //=========================================================
  11673. if(!isEmpty && !isKnowKey)
  11674. {
  11675. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11676. strcpy(unknownkey[UnknownKeynum], keyReq);
  11677. UnknownKeynum = UnknownKeynum + 1;
  11678. }
  11679. }
  11680. void processUnkownKey(void)
  11681. {
  11682. DEBUG_INFO("processUnkownKey...\n");
  11683. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11684. for(int index=0; index < UnknownKeynum; index++)
  11685. {
  11686. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11687. {
  11688. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11689. }
  11690. }
  11691. }
  11692. int setKeyValue(char *key, char *value)
  11693. {
  11694. int isSuccess = NotSupported;
  11695. int check_ascii=0;
  11696. char str[10]={0};
  11697. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11698. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11699. {
  11700. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11702. {
  11703. strcpy(str, (const char*)value);
  11704. for(int i = 0; str[i]; i++){
  11705. str[i] = tolower(str[i]);
  11706. }
  11707. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11708. isSuccess = ConfigurationStatus_Accepted;
  11709. }
  11710. else
  11711. {
  11712. isSuccess = ConfigurationStatus_Rejected;
  11713. }
  11714. }
  11715. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11716. {
  11717. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11718. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11719. {
  11720. strcpy(str, (const char*)value);
  11721. for(int i = 0; str[i]; i++){
  11722. str[i] = tolower(str[i]);
  11723. }
  11724. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11725. isSuccess = ConfigurationStatus_Accepted;
  11726. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11727. }
  11728. else
  11729. {
  11730. isSuccess = ConfigurationStatus_Rejected;
  11731. }
  11732. }
  11733. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11734. {
  11735. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11736. {
  11737. strcpy(str, (const char*)value);
  11738. for(int i = 0; str[i]; i++)
  11739. {
  11740. str[i] = tolower(str[i]);
  11741. }
  11742. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11744. isSuccess = ConfigurationStatus_Accepted;
  11745. }
  11746. else
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. if(strcmp(key, "BlinkRepeat") == 0)
  11752. {
  11753. //Charger.BlinkRepeat = Integer.parseInt(value);
  11754. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11755. {
  11756. check_ascii = value[0];
  11757. if( (check_ascii < 48) || (check_ascii > 57) )
  11758. {
  11759. isSuccess = ConfigurationStatus_Rejected;
  11760. }
  11761. else
  11762. {
  11763. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11764. isSuccess = ConfigurationStatus_Accepted;
  11765. }
  11766. }
  11767. else
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. }
  11772. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11773. {
  11774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11775. {
  11776. check_ascii = value[0];
  11777. if( (check_ascii < 48) || (check_ascii > 57) )
  11778. {
  11779. isSuccess = ConfigurationStatus_Rejected;
  11780. }
  11781. else
  11782. {
  11783. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11784. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11785. isSuccess = ConfigurationStatus_Accepted;
  11786. }
  11787. }
  11788. else
  11789. {
  11790. isSuccess = ConfigurationStatus_Rejected;
  11791. }
  11792. }
  11793. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11794. {
  11795. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11796. {
  11797. check_ascii = value[0];
  11798. if( (check_ascii < 48) || (check_ascii > 57) )
  11799. {
  11800. isSuccess = ConfigurationStatus_Rejected;
  11801. }
  11802. else
  11803. {
  11804. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11805. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11806. isSuccess = ConfigurationStatus_Accepted;
  11807. }
  11808. }
  11809. else
  11810. {
  11811. isSuccess = ConfigurationStatus_Rejected;
  11812. }
  11813. }
  11814. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11815. {
  11816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11817. {
  11818. check_ascii = value[0];
  11819. if( (check_ascii < 48) || (check_ascii > 57) )
  11820. {
  11821. isSuccess = ConfigurationStatus_Rejected;
  11822. }
  11823. else
  11824. {
  11825. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11827. isSuccess = ConfigurationStatus_Accepted;
  11828. }
  11829. }
  11830. else
  11831. {
  11832. isSuccess = ConfigurationStatus_Rejected;
  11833. }
  11834. }
  11835. if(strcmp(key, "HeartbeatInterval") == 0)
  11836. {
  11837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11838. {
  11839. check_ascii = value[0];
  11840. if( (check_ascii < 48) || (check_ascii > 57) )
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. else
  11845. {
  11846. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11847. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11848. HeartBeatWaitTime = atoi(value);
  11849. isSuccess = ConfigurationStatus_Accepted;
  11850. }
  11851. }
  11852. else
  11853. {
  11854. isSuccess = ConfigurationStatus_Rejected;
  11855. }
  11856. }
  11857. if(strcmp(key, "LightIntensity") == 0)
  11858. {
  11859. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11860. {
  11861. check_ascii = value[0];
  11862. if( (check_ascii < 48) || (check_ascii > 57) )
  11863. {
  11864. isSuccess = ConfigurationStatus_Rejected;
  11865. }
  11866. else
  11867. {
  11868. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11869. isSuccess = ConfigurationStatus_Accepted;
  11870. }
  11871. }
  11872. else
  11873. {
  11874. isSuccess = ConfigurationStatus_Rejected;
  11875. }
  11876. }
  11877. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11878. {
  11879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11880. {
  11881. strcpy(str, (const char*)value);
  11882. for(int i = 0; str[i]; i++)
  11883. {
  11884. str[i] = tolower(str[i]);
  11885. }
  11886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11887. isSuccess = ConfigurationStatus_Accepted;
  11888. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11889. }
  11890. else
  11891. {
  11892. isSuccess = ConfigurationStatus_Rejected;
  11893. }
  11894. }
  11895. if(strcmp(key, "LocalPreAuthorize") == 0)
  11896. {
  11897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11898. {
  11899. strcpy(str, (const char*)value);
  11900. for(int i = 0; str[i]; i++)
  11901. {
  11902. str[i] = tolower(str[i]);
  11903. }
  11904. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11905. isSuccess = ConfigurationStatus_Accepted;
  11906. }
  11907. else
  11908. {
  11909. isSuccess = ConfigurationStatus_Rejected;
  11910. }
  11911. }
  11912. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11913. {
  11914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11915. {
  11916. check_ascii = value[0];
  11917. if( (check_ascii < 48) || (check_ascii > 57) )
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. else
  11922. {
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11924. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11925. isSuccess = ConfigurationStatus_Accepted;
  11926. }
  11927. }
  11928. else
  11929. {
  11930. isSuccess = ConfigurationStatus_Rejected;
  11931. }
  11932. }
  11933. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11934. {
  11935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11936. {
  11937. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11938. isSuccess = ConfigurationStatus_Accepted;
  11939. }
  11940. else
  11941. {
  11942. isSuccess = ConfigurationStatus_Rejected;
  11943. }
  11944. }
  11945. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11946. {
  11947. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11948. {
  11949. check_ascii = value[0];
  11950. if( (check_ascii < 48) || (check_ascii > 57) )
  11951. {
  11952. isSuccess = ConfigurationStatus_Rejected;
  11953. }
  11954. else
  11955. {
  11956. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11958. isSuccess = ConfigurationStatus_Accepted;
  11959. }
  11960. }
  11961. else
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. }
  11966. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11967. {
  11968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11969. {
  11970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11971. isSuccess = ConfigurationStatus_Accepted;
  11972. }
  11973. else
  11974. {
  11975. isSuccess = ConfigurationStatus_Rejected;
  11976. }
  11977. }
  11978. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11979. {
  11980. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].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.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11990. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11991. isSuccess = ConfigurationStatus_Accepted;
  11992. }
  11993. }
  11994. else
  11995. {
  11996. isSuccess = ConfigurationStatus_Rejected;
  11997. }
  11998. }
  11999. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12000. {
  12001. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].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.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12011. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12012. isSuccess = ConfigurationStatus_Accepted;
  12013. }
  12014. }
  12015. else
  12016. {
  12017. isSuccess = ConfigurationStatus_Rejected;
  12018. }
  12019. }
  12020. if(strcmp(key, "MinimumStatusDuration") == 0)
  12021. {
  12022. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12023. {
  12024. check_ascii = value[0];
  12025. if( (check_ascii < 48) || (check_ascii > 57) )
  12026. {
  12027. isSuccess = ConfigurationStatus_Rejected;
  12028. }
  12029. else
  12030. {
  12031. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12032. {
  12033. isSuccess = ConfigurationStatus_Rejected;
  12034. }
  12035. else
  12036. {
  12037. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12039. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12040. isSuccess = ConfigurationStatus_Accepted;
  12041. }
  12042. }
  12043. }
  12044. else
  12045. {
  12046. isSuccess = ConfigurationStatus_Rejected;
  12047. }
  12048. }
  12049. if(strcmp(key, "NumberOfConnectors") == 0)
  12050. {
  12051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12052. {
  12053. check_ascii = value[0];
  12054. if( (check_ascii < 48) || (check_ascii > 57) )
  12055. {
  12056. isSuccess = ConfigurationStatus_Rejected;
  12057. }
  12058. else
  12059. {
  12060. //Charger.ResetRetries = Integer.parseInt(value);
  12061. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12062. isSuccess = ConfigurationStatus_Accepted;
  12063. }
  12064. }
  12065. else
  12066. {
  12067. isSuccess = ConfigurationStatus_Rejected;
  12068. }
  12069. }
  12070. if(strcmp(key, "ResetRetries") == 0)
  12071. {
  12072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12073. {
  12074. check_ascii = value[0];
  12075. if( (check_ascii < 48) || (check_ascii > 57) )
  12076. {
  12077. isSuccess = ConfigurationStatus_Rejected;
  12078. }
  12079. else
  12080. {
  12081. //Charger.ResetRetries = Integer.parseInt(value);
  12082. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12083. isSuccess = ConfigurationStatus_Accepted;
  12084. }
  12085. }
  12086. else
  12087. {
  12088. isSuccess = ConfigurationStatus_Rejected;
  12089. }
  12090. }
  12091. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12092. {
  12093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12094. {
  12095. strcpy(str, (const char*)value);
  12096. for(int i = 0; str[i]; i++)
  12097. {
  12098. str[i] = tolower(str[i]);
  12099. }
  12100. if(strcmp(str, "notapplicable")== 0)
  12101. {
  12102. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12103. isSuccess = ConfigurationStatus_Accepted;
  12104. }
  12105. else if(strcmp(str, "unknown")== 0)
  12106. {
  12107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. else if(strcmp(str, "rst")== 0)
  12111. {
  12112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12113. isSuccess = ConfigurationStatus_Accepted;
  12114. }
  12115. else if(strcmp(str, "rts")== 0)
  12116. {
  12117. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12118. isSuccess = ConfigurationStatus_Accepted;
  12119. }
  12120. else if(strcmp(str, "srt")== 0)
  12121. {
  12122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12123. isSuccess = ConfigurationStatus_Accepted;
  12124. }
  12125. else if(strcmp(str, "str")== 0)
  12126. {
  12127. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12128. isSuccess = ConfigurationStatus_Accepted;
  12129. }
  12130. else if(strcmp(str, "trs")== 0)
  12131. {
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12133. isSuccess = ConfigurationStatus_Accepted;
  12134. }
  12135. else if(strcmp(str, "tsr")== 0)
  12136. {
  12137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12138. isSuccess = ConfigurationStatus_Accepted;
  12139. }
  12140. else
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. }
  12145. else
  12146. {
  12147. isSuccess = ConfigurationStatus_Rejected;
  12148. }
  12149. }
  12150. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12151. {
  12152. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12153. {
  12154. check_ascii = value[0];
  12155. if( (check_ascii < 48) || (check_ascii > 57) )
  12156. {
  12157. isSuccess = ConfigurationStatus_Rejected;
  12158. }
  12159. else
  12160. {
  12161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12162. isSuccess = ConfigurationStatus_Accepted;
  12163. }
  12164. }
  12165. else
  12166. {
  12167. isSuccess = ConfigurationStatus_Rejected;
  12168. }
  12169. }
  12170. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12171. {
  12172. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12173. {
  12174. strcpy(str, (const char*)value);
  12175. for(int i = 0; str[i]; i++)
  12176. {
  12177. str[i] = tolower(str[i]);
  12178. }
  12179. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12180. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12181. isSuccess = ConfigurationStatus_Accepted;
  12182. }
  12183. else
  12184. {
  12185. isSuccess = ConfigurationStatus_Rejected;
  12186. }
  12187. }
  12188. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12189. {
  12190. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12191. {
  12192. strcpy(str, (const char*)value);
  12193. for(int i = 0; str[i]; i++)
  12194. {
  12195. str[i] = tolower(str[i]);
  12196. }
  12197. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12199. isSuccess = ConfigurationStatus_Accepted;
  12200. }
  12201. else
  12202. {
  12203. isSuccess = ConfigurationStatus_Rejected;
  12204. }
  12205. }
  12206. if(strcmp(key, "StopTxnAlignedData") == 0)
  12207. {
  12208. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12209. {
  12210. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12211. isSuccess = ConfigurationStatus_Accepted;
  12212. }
  12213. else
  12214. {
  12215. isSuccess = ConfigurationStatus_Rejected;
  12216. }
  12217. }
  12218. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12219. {
  12220. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12221. {
  12222. check_ascii = value[0];
  12223. if( (check_ascii < 48) || (check_ascii > 57) )
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. else
  12228. {
  12229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12230. isSuccess = ConfigurationStatus_Accepted;
  12231. }
  12232. }
  12233. else
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. }
  12238. if(strcmp(key, "StopTxnSampledData") == 0)
  12239. {
  12240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12241. {
  12242. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. else
  12246. {
  12247. isSuccess = ConfigurationStatus_Rejected;
  12248. }
  12249. }
  12250. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12251. {
  12252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12253. {
  12254. check_ascii = value[0];
  12255. if( (check_ascii < 48) || (check_ascii > 57) )
  12256. {
  12257. isSuccess = ConfigurationStatus_Rejected;
  12258. }
  12259. else
  12260. {
  12261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12262. isSuccess = ConfigurationStatus_Accepted;
  12263. }
  12264. }
  12265. else
  12266. {
  12267. isSuccess = ConfigurationStatus_Rejected;
  12268. }
  12269. }
  12270. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12271. {
  12272. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12273. {
  12274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12275. isSuccess = ConfigurationStatus_Accepted;
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12283. {
  12284. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12285. {
  12286. check_ascii = value[0];
  12287. if( (check_ascii < 48) || (check_ascii > 57) )
  12288. {
  12289. isSuccess = ConfigurationStatus_Rejected;
  12290. }
  12291. else
  12292. {
  12293. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12294. isSuccess = ConfigurationStatus_Accepted;
  12295. }
  12296. }
  12297. else
  12298. {
  12299. isSuccess = ConfigurationStatus_Rejected;
  12300. }
  12301. }
  12302. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12303. {
  12304. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12305. {
  12306. check_ascii = value[0];
  12307. if( (check_ascii < 48) || (check_ascii > 57) )
  12308. {
  12309. isSuccess = ConfigurationStatus_Rejected;
  12310. }
  12311. else
  12312. {
  12313. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12315. TransactionMessageAttemptsValue = atoi(value);
  12316. isSuccess = ConfigurationStatus_Accepted;
  12317. }
  12318. }
  12319. else
  12320. {
  12321. isSuccess = ConfigurationStatus_Rejected;
  12322. }
  12323. }
  12324. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12325. {
  12326. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12327. {
  12328. check_ascii = value[0];
  12329. if( (check_ascii < 48) || (check_ascii > 57) )
  12330. {
  12331. isSuccess = ConfigurationStatus_Rejected;
  12332. }
  12333. else
  12334. {
  12335. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12337. TransactionMessageRetryIntervalValue = atoi(value);
  12338. isSuccess = ConfigurationStatus_Accepted;
  12339. }
  12340. }
  12341. else
  12342. {
  12343. isSuccess = ConfigurationStatus_Rejected;
  12344. }
  12345. }
  12346. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12347. {
  12348. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12349. {
  12350. strcpy(str, (const char*)value);
  12351. for(int i = 0; str[i]; i++)
  12352. {
  12353. str[i] = tolower(str[i]);
  12354. }
  12355. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12357. isSuccess = ConfigurationStatus_Accepted;
  12358. }
  12359. else
  12360. {
  12361. isSuccess = ConfigurationStatus_Rejected;
  12362. }
  12363. }
  12364. if(strcmp(key, "WebSocketPingInterval") == 0)
  12365. {
  12366. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12367. {
  12368. check_ascii = value[0];
  12369. if( (check_ascii < 48) || (check_ascii > 57) )
  12370. {
  12371. isSuccess = ConfigurationStatus_Rejected;
  12372. }
  12373. else
  12374. {
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. }
  12379. else
  12380. {
  12381. isSuccess = ConfigurationStatus_Rejected;
  12382. }
  12383. }
  12384. #if 0
  12385. //For OCPP Test Case
  12386. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12387. {
  12388. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12389. {
  12390. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12391. isSuccess = ConfigurationStatus_Accepted;
  12392. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12393. }
  12394. else
  12395. {
  12396. isSuccess = ConfigurationStatus_Rejected;
  12397. }
  12398. }
  12399. #endif
  12400. #if 1
  12401. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12402. {
  12403. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12404. {
  12405. strcpy(str, (const char*)value);
  12406. for(int i = 0; str[i]; i++)
  12407. {
  12408. str[i] = tolower(str[i]);
  12409. }
  12410. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12411. isSuccess = ConfigurationStatus_Accepted;
  12412. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12413. }
  12414. else
  12415. {
  12416. isSuccess = ConfigurationStatus_Rejected;
  12417. }
  12418. }
  12419. #endif
  12420. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12421. {
  12422. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12423. {
  12424. check_ascii = value[0];
  12425. if( (check_ascii < 48) || (check_ascii > 57) )
  12426. {
  12427. isSuccess = ConfigurationStatus_Rejected;
  12428. }
  12429. else
  12430. {
  12431. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12432. isSuccess = ConfigurationStatus_Accepted;
  12433. }
  12434. }
  12435. else
  12436. {
  12437. isSuccess = ConfigurationStatus_Rejected;
  12438. }
  12439. }
  12440. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12441. {
  12442. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12443. {
  12444. check_ascii = value[0];
  12445. if( (check_ascii < 48) || (check_ascii > 57) )
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. else
  12450. {
  12451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12452. isSuccess = ConfigurationStatus_Accepted;
  12453. }
  12454. }
  12455. else
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. }
  12460. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12461. {
  12462. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12463. {
  12464. strcpy(str, (const char*)value);
  12465. for(int i = 0; str[i]; i++)
  12466. {
  12467. str[i] = tolower(str[i]);
  12468. }
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12470. isSuccess = ConfigurationStatus_Accepted;
  12471. }
  12472. else
  12473. {
  12474. isSuccess = ConfigurationStatus_Rejected;
  12475. }
  12476. }
  12477. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12478. {
  12479. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12480. {
  12481. check_ascii = value[0];
  12482. if( (check_ascii < 48) || (check_ascii > 57) )
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. else
  12487. {
  12488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12489. isSuccess = ConfigurationStatus_Accepted;
  12490. }
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12500. {
  12501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12502. isSuccess = ConfigurationStatus_Accepted;
  12503. }
  12504. else
  12505. {
  12506. isSuccess = ConfigurationStatus_Rejected;
  12507. }
  12508. }
  12509. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12510. {
  12511. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12512. {
  12513. check_ascii = value[0];
  12514. if( (check_ascii < 48) || (check_ascii > 57) )
  12515. {
  12516. isSuccess = ConfigurationStatus_Rejected;
  12517. }
  12518. else
  12519. {
  12520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12521. isSuccess = ConfigurationStatus_Accepted;
  12522. }
  12523. }
  12524. else
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. }
  12529. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12530. {
  12531. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12532. {
  12533. strcpy(str, (const char*)value);
  12534. for(int i = 0; str[i]; i++)
  12535. {
  12536. str[i] = tolower(str[i]);
  12537. }
  12538. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12539. isSuccess = ConfigurationStatus_Accepted;
  12540. }
  12541. else
  12542. {
  12543. isSuccess = ConfigurationStatus_Rejected;
  12544. }
  12545. }
  12546. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12547. {
  12548. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12549. {
  12550. check_ascii = value[0];
  12551. if( (check_ascii < 48) || (check_ascii > 57) )
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. else
  12556. {
  12557. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12558. isSuccess = ConfigurationStatus_Accepted;
  12559. }
  12560. }
  12561. else
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. }
  12566. return isSuccess;
  12567. }
  12568. int TransactionMessageAttemptsGet(void)
  12569. {
  12570. return TransactionMessageAttemptsValue;
  12571. }
  12572. int FirstHeartBeatResponse(void)
  12573. {
  12574. return FirstHeartBeat;
  12575. }
  12576. int TransactionMessageRetryIntervalGet(void)
  12577. {
  12578. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12579. }
  12580. int ReadHttpStatus(int sock)
  12581. {
  12582. //char c;
  12583. char buff[1024]="",*ptr=buff+1;
  12584. int bytes_received, status;
  12585. DEBUG_INFO("Begin Response ..\n");
  12586. while((bytes_received = recv(sock, ptr, 1, 0))){
  12587. if(bytes_received==-1){
  12588. perror("ReadHttpStatus");
  12589. exit(1);
  12590. }
  12591. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12592. ptr++;
  12593. }
  12594. *ptr=0;
  12595. ptr=buff+1;
  12596. sscanf(ptr,"%*s %d ", &status);
  12597. DEBUG_INFO("%s\n",ptr);
  12598. DEBUG_INFO("status=%d\n",status);
  12599. DEBUG_INFO("End Response ..\n");
  12600. return (bytes_received>0)?status:0;
  12601. }
  12602. //the only filed that it parsed is 'Content-Length'
  12603. int ParseHeader(int sock)
  12604. {
  12605. //char c;
  12606. char buff[1024]="",*ptr=buff+4;
  12607. int bytes_received;
  12608. DEBUG_INFO("Begin HEADER ..\n");
  12609. while((bytes_received = recv(sock, ptr, 1, 0))){
  12610. if(bytes_received==-1){
  12611. perror("Parse Header");
  12612. exit(1);
  12613. }
  12614. if(
  12615. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12616. (ptr[-1]=='\r') && (*ptr=='\n' )
  12617. ) break;
  12618. ptr++;
  12619. }
  12620. *ptr=0;
  12621. ptr=buff+4;
  12622. //printf("%s",ptr);
  12623. if(bytes_received){
  12624. ptr=strstr(ptr,"Content-Length:");
  12625. if(ptr){
  12626. sscanf(ptr,"%*s %d",&bytes_received);
  12627. }else
  12628. bytes_received=-1; //unknown size
  12629. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12630. }
  12631. DEBUG_INFO("End HEADER ..\n");
  12632. return bytes_received ;
  12633. }
  12634. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12635. {
  12636. char rmFileCmd[100]={0};
  12637. char FilePath[100]={0};
  12638. char ftpbuf[200];
  12639. int systemresult;
  12640. //DEBUG_INFO("filename=%s\n",filename);
  12641. //DEBUG_INFO("url=%s\n",url);
  12642. sprintf(FilePath,"/mnt/%s",filename);
  12643. if((access(FilePath,F_OK))!=-1)
  12644. {
  12645. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12646. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12647. system(rmFileCmd);
  12648. }
  12649. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12650. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12651. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12652. systemresult = system(ftpbuf);
  12653. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12654. if(systemresult != 0)
  12655. {
  12656. DEBUG_INFO("http DownLoad error!\n");
  12657. return FALSE;
  12658. }
  12659. return TRUE;
  12660. }
  12661. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12662. {
  12663. char rmFileCmd[100]={0};
  12664. char FilePath[100]={0};
  12665. char ftpbuf[200];
  12666. int systemresult;
  12667. //char temp[100];
  12668. sprintf(FilePath,"/mnt/%s",filename);
  12669. if((access(FilePath,F_OK))!=-1)
  12670. {
  12671. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12672. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12673. system(rmFileCmd);
  12674. }
  12675. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12676. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12677. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12678. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12679. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12680. systemresult = system(ftpbuf);
  12681. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12682. if(systemresult != 0)
  12683. {
  12684. printf("wget error!\n");
  12685. return FALSE;
  12686. }
  12687. return TRUE;
  12688. }
  12689. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12690. {
  12691. char rmFileCmd[100]={0};
  12692. char FilePath[100]={0};
  12693. char ftpbuf[200];
  12694. int systemresult;
  12695. //DEBUG_INFO("filename=%s\n",filename);
  12696. //DEBUG_INFO("url=%s\n",url);
  12697. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12698. if((access(FilePath,F_OK))!=-1)
  12699. {
  12700. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12701. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12702. system(rmFileCmd);
  12703. }
  12704. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12705. if(fp == NULL)
  12706. {
  12707. DEBUG_INFO("log is NULL\n");
  12708. return FALSE;
  12709. }
  12710. else
  12711. {
  12712. fprintf(fp, "%s\n", url);
  12713. fprintf(fp, "%s\n", filename);
  12714. fclose(fp);
  12715. }
  12716. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12717. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12718. systemresult = system(ftpbuf);
  12719. DEBUG_INFO("systemresult = %d\n",systemresult);
  12720. if(systemresult != 0)
  12721. {
  12722. DEBUG_INFO("http upload error!\n");
  12723. return FALSE;
  12724. }
  12725. return TRUE;
  12726. }
  12727. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12728. {
  12729. struct hostent* server;
  12730. char *IPbuffer;
  12731. char ftpbuf[200];
  12732. int systemresult;
  12733. // To retrieve host information
  12734. server = gethostbyname(location);
  12735. // To convert an Internet network
  12736. // address into ASCII string
  12737. IPbuffer = inet_ntoa(*((struct in_addr*)
  12738. server->h_addr_list[0]));
  12739. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12740. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12741. /* format : ftpput -u username -p passwd IP target source*/
  12742. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12743. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12744. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12745. systemresult = system(ftpbuf);
  12746. DEBUG_INFO("systemresult=%d\n",systemresult);
  12747. if(systemresult != 0)
  12748. {
  12749. DEBUG_INFO("ftpput error!\n");
  12750. return FALSE;
  12751. }
  12752. return TRUE;
  12753. }
  12754. /**
  12755. * Place the contents of the specified file into a memory buffer
  12756. *
  12757. * @param[in] filename The path and name of the file to read
  12758. * @param[out] filebuffer A pointer to the contents in memory
  12759. * @return status 0 success, 1 on failure
  12760. */
  12761. int get_file_contents(const char* filename, char** outbuffer) {
  12762. FILE* file = NULL;
  12763. long filesize;
  12764. const int blocksize = 1;
  12765. size_t readsize;
  12766. char* filebuffer;
  12767. // Open the file
  12768. file = fopen(filename, "r");
  12769. if (NULL == file)
  12770. {
  12771. printf("'%s' not opened\n", filename);
  12772. exit(EXIT_FAILURE);
  12773. }
  12774. // Determine the file size
  12775. fseek(file, 0, SEEK_END);
  12776. filesize = ftell(file);
  12777. rewind (file);
  12778. // Allocate memory for the file contents
  12779. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12780. *outbuffer = filebuffer;
  12781. if (filebuffer == NULL)
  12782. {
  12783. fputs ("malloc out-of-memory", stderr);
  12784. exit(EXIT_FAILURE);
  12785. }
  12786. // Read in the file
  12787. readsize = fread(filebuffer, blocksize, filesize, file);
  12788. if (readsize != filesize)
  12789. {
  12790. fputs ("didn't read file completely",stderr);
  12791. exit(EXIT_FAILURE);
  12792. }
  12793. // Clean exit
  12794. fclose(file);
  12795. return EXIT_SUCCESS;
  12796. }
  12797. static int selectSqlCount = 0;
  12798. static int callback(void *data, int argc, char **argv, char **azColName){
  12799. int i;
  12800. //printf("%s: ", (const char*)data);
  12801. selectSqlCount = argc;
  12802. for(i = 0; i<argc; i++){
  12803. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12804. }
  12805. //printf("\n");
  12806. return 0;
  12807. }
  12808. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12809. //int i;
  12810. //printf("%s:\n", (const char*)data);
  12811. localversion = argv[5] ? atoi(argv[5]) : 0;
  12812. //printf("localversion=%d\n", localversion);
  12813. return 0;
  12814. }
  12815. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12816. //int i;
  12817. //printf("%s:\n", (const char*)data);
  12818. //idTag
  12819. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12820. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12821. //parentIdTag
  12822. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12823. //expir_date
  12824. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12825. //status
  12826. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12827. //version
  12828. idTagQuery.listVersionInt = atoi(argv[5]);
  12829. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12830. return 0;
  12831. }
  12832. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12833. {
  12834. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12835. // printf("localversion=%d\n", localversion);
  12836. return 0;
  12837. }
  12838. //=========================================
  12839. // Sqlite3 related function
  12840. //=========================================
  12841. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12842. {
  12843. for (int i = 0; i < n_columns; i++)
  12844. {
  12845. DEBUG_INFO("%s/t", col_values[i]);
  12846. }
  12847. DEBUG_INFO("/n");
  12848. return 0;
  12849. }
  12850. void OCPP_getListVerion()
  12851. {
  12852. int rc = 0;
  12853. // const char* data = "Callback function called";
  12854. char sql[100];
  12855. char zErrMsg[100];
  12856. memset(sql, 0, 100);
  12857. memset(zErrMsg, 0, 100);
  12858. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12859. /* Execute SQL statement */
  12860. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12861. if( rc != SQLITE_OK )
  12862. {
  12863. DEBUG_INFO("SQL error: %s", zErrMsg);
  12864. }
  12865. }
  12866. void OCPP_getIdTag(char idTag[])
  12867. {
  12868. int rc = 0;
  12869. // const char* data = "Callback function called";
  12870. char sql[100];
  12871. char zErrMsg[100];
  12872. memset(sql, 0, 100);
  12873. memset(zErrMsg, 0, 100);
  12874. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12875. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12876. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12877. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12878. /* Execute SQL statement */
  12879. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12880. if( rc != SQLITE_OK )
  12881. {
  12882. DEBUG_INFO("SQL error: %s", zErrMsg);
  12883. }
  12884. //return ver;
  12885. }
  12886. void OCPP_get_TableAuthlocalAllData(void)
  12887. {
  12888. int rc = 0;
  12889. char sql[100];
  12890. char zErrMsg[100];
  12891. memset(sql, 0, 100);
  12892. memset(zErrMsg, 0, 100);
  12893. sprintf(sql,"select * from ocpp_auth_local ");
  12894. /* Execute SQL statement */
  12895. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12896. if( rc != SQLITE_OK )
  12897. {
  12898. DEBUG_INFO("SQL error: %s", zErrMsg);
  12899. }
  12900. //return ver;
  12901. }
  12902. int OCPP_cleanLocalList()
  12903. {
  12904. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12905. char *errMsg = 0;
  12906. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12907. if (SQLITE_OK != rc)
  12908. {
  12909. DEBUG_INFO("%s\n",errMsg);
  12910. return FALSE;
  12911. }
  12912. return TRUE;
  12913. }
  12914. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12915. {
  12916. int isSuccess = FALSE;
  12917. int ret = 0;
  12918. //const char* data = "Callback function called";
  12919. char sql[300];
  12920. char zErrMsg[200];
  12921. memset(sql, 0, 300);
  12922. memset(zErrMsg, 0, 200);
  12923. 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);
  12924. //* Execute SQL statement */
  12925. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12926. if( ret != SQLITE_OK )
  12927. {
  12928. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12929. return isSuccess;
  12930. }
  12931. memset(sql, 0, 300);
  12932. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12933. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12934. if( ret != SQLITE_OK )
  12935. {
  12936. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12937. return isSuccess;
  12938. }
  12939. isSuccess = TRUE;
  12940. return isSuccess;
  12941. }
  12942. void OCPP_deleteIdTag(char idTag[])
  12943. {
  12944. //int ver = 0;
  12945. //int isSuccess = FALSE;
  12946. int rc = 0;
  12947. char sql[100];
  12948. char zErrMsg[100];
  12949. memset(sql, 0, 100);
  12950. memset(zErrMsg, 0, 100);
  12951. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12952. //* Execute SQL statement */
  12953. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12954. if( rc != SQLITE_OK )
  12955. {
  12956. DEBUG_INFO("SQL error: %s", zErrMsg);
  12957. }
  12958. }
  12959. int GetOcppServerURL()
  12960. {
  12961. int result = FALSE;
  12962. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12963. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12964. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12965. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12966. {
  12967. #if 1
  12968. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12969. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12970. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12971. #endif
  12972. result = TRUE;
  12973. goto End;
  12974. }
  12975. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12976. {
  12977. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12978. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12979. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12980. result = TRUE;
  12981. goto End;
  12982. }
  12983. else
  12984. {
  12985. strcpy(OcppHost,"");
  12986. }
  12987. End:
  12988. return result;
  12989. }
  12990. int GetOcppPath()
  12991. {
  12992. int result = FALSE;
  12993. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12994. {
  12995. if(OcppTempPath == NULL)
  12996. {
  12997. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12998. }
  12999. else
  13000. {
  13001. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13002. }
  13003. result = TRUE;
  13004. goto End;
  13005. }
  13006. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13007. {
  13008. if(OcppTempPath == NULL)
  13009. {
  13010. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13011. }
  13012. else
  13013. {
  13014. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13015. }
  13016. result = TRUE;
  13017. goto End;
  13018. }
  13019. else
  13020. {
  13021. strcpy(OcppPath,"");
  13022. }
  13023. End:
  13024. return result;
  13025. }
  13026. int GetOcppPort()
  13027. {
  13028. return OcppPort;
  13029. }
  13030. int GetOcppConnStatus(void)
  13031. {
  13032. return ShmOCPP16Data->OcppConnStatus;
  13033. }
  13034. void SetOcppConnStatus(uint8_t status)
  13035. {
  13036. ShmOCPP16Data->OcppConnStatus = status;
  13037. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13038. }
  13039. int GetHeartBeatWithNOResponse(void)
  13040. {
  13041. return HeartBeatWithNOResponse;
  13042. }
  13043. void SetHeartBeatWithNOResponse(void)
  13044. {
  13045. HeartBeatWithNOResponse = 0;
  13046. }
  13047. void GetStartTransactionIdTag(int gun_index)
  13048. {
  13049. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13050. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13051. }
  13052. int GetTransactionId(int gunindex, unsigned char idTag[])
  13053. {
  13054. char ch;
  13055. FILE *fptr1;
  13056. int temptransactionId;
  13057. char str[100]={0};
  13058. temptransactionId = 0;
  13059. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13060. {
  13061. DEBUG_INFO("IdTag is empty.\n");
  13062. return temptransactionId;
  13063. }
  13064. /*------ Read the file ----------------*/
  13065. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13066. if (!fptr1)
  13067. {
  13068. DEBUG_INFO("QueueTransactionId file open error.\n");
  13069. //printf(" File not found or unable to open the input file!!\n");
  13070. return temptransactionId;
  13071. }
  13072. ch=fgetc(fptr1);
  13073. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13074. rewind(fptr1);
  13075. if(ch!=EOF)
  13076. {
  13077. // printf("%c",ch);
  13078. while (fgets(str, 100, fptr1) != NULL)
  13079. {
  13080. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13081. if(str[0]=='\0')
  13082. {
  13083. break;
  13084. }
  13085. char *revbuf[8] = {0}; //存放分割後的子字串
  13086. int num = 0;//分割後子字串的個數
  13087. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13088. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13089. {
  13090. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13091. {
  13092. temptransactionId = atoi(revbuf[2]);
  13093. break;
  13094. }
  13095. }
  13096. }
  13097. }
  13098. fclose(fptr1);
  13099. /*------- End of reading ---------------*/
  13100. return temptransactionId;
  13101. }
  13102. void SetTransactionIdZero(int transactionId)
  13103. {
  13104. char ch;
  13105. FILE *fptr1, *fptr2;
  13106. int temptransactionId = 0;
  13107. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13108. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13109. if (!fptr1)
  13110. {
  13111. //printf(" File not found or unable to open the input file!!\n");
  13112. return ;
  13113. }
  13114. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13115. if (!fptr2)
  13116. {
  13117. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13118. fclose(fptr1);
  13119. return ;
  13120. }
  13121. ch=fgetc(fptr1);
  13122. rewind(fptr1);
  13123. if(ch!=EOF)
  13124. {
  13125. // copy all contents to the temporary file except the specific line
  13126. while (fgets(str, 100, fptr1) != NULL)
  13127. {
  13128. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13129. if(str[0]=='\0')
  13130. {
  13131. break;
  13132. }
  13133. char *revbuf[8] = {0};
  13134. int num = 0;
  13135. strcpy(strtemp, str);
  13136. splitstring(str,",",revbuf,&num);
  13137. if(revbuf[2][0] != '\0')
  13138. {
  13139. temptransactionId = atoi(revbuf[2]);
  13140. if(transactionId != temptransactionId)
  13141. {
  13142. fprintf(fptr2, "%s\n", strtemp);
  13143. }
  13144. }
  13145. }
  13146. }
  13147. fclose(fptr1);
  13148. fclose(fptr2);
  13149. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13150. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13151. /*------ Read the file ----------------*/
  13152. }
  13153. int InternetDisconnect(void)
  13154. {
  13155. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13156. }
  13157. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13158. void storeTempStopTransaction(int gun_index)
  13159. {
  13160. char guid[37]={0};
  13161. int tempIndex = 0;
  13162. DEBUG_INFO("storeTempStopTransaction...\n");
  13163. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13164. //ENERGY_ACTIVE_IMPORT_REGISTER
  13165. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13166. if(gunType[gun_index] == 'J')
  13167. {
  13168. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13169. {
  13170. tempIndex = ((gun_index==2) ? 1: 0);
  13171. }
  13172. else
  13173. {
  13174. tempIndex = gun_index;
  13175. }
  13176. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13177. {
  13178. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13179. {
  13180. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13181. }
  13182. }// END OF CHAdeMO_QUANTITY
  13183. }
  13184. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13185. {
  13186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13187. {
  13188. tempIndex = ((gun_index==2) ? 1: 0);
  13189. }
  13190. else
  13191. {
  13192. tempIndex = gun_index;
  13193. }
  13194. for (int index = 0; index < CCS_QUANTITY; index++)
  13195. {
  13196. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13197. {
  13198. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13199. }
  13200. }// END OF CCS_QUANTITY
  13201. }
  13202. else if(gunType[gun_index] == 'G')
  13203. {
  13204. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13205. {
  13206. tempIndex = ((gun_index==2) ? 1: 0);
  13207. }
  13208. else
  13209. {
  13210. tempIndex = gun_index;
  13211. }
  13212. for (int index = 0; index < GB_QUANTITY; index++)
  13213. {
  13214. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13215. {
  13216. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13217. }
  13218. }// END OF GB_QUANTITY
  13219. }
  13220. else
  13221. {
  13222. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13223. {
  13224. tempIndex = 2;
  13225. }
  13226. else
  13227. {
  13228. tempIndex = gun_index;
  13229. }
  13230. for (int index = 0; index < AC_QUANTITY; index++)
  13231. {
  13232. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13233. {
  13234. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13235. }
  13236. }// END OF AC_QUANTITY
  13237. }
  13238. //Stop Transaction Time
  13239. struct timeval tmnow;
  13240. struct tm *tm;
  13241. char buf[28];//, usec_buf[6];
  13242. gettimeofday(&tmnow, NULL);
  13243. time_t t;
  13244. t = time(NULL);
  13245. /*UTC time and date*/
  13246. tm = gmtime(&t);
  13247. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13248. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13249. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13250. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13251. random_uuid(guid);
  13252. /***********************************transactionData******************************************************/
  13253. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13254. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13255. //=================================
  13256. //1. Transaction_Begin
  13257. //=================================
  13258. // Energy.Active.Export.Interval
  13259. //idx_sample=0;
  13260. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13261. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13262. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13263. 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*/]);
  13264. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13265. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13266. {
  13267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13268. }
  13269. else
  13270. {
  13271. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13272. }
  13273. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13274. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13275. //=================================
  13276. //2. Transaction_End
  13277. //=================================
  13278. //2.1 Current.Export
  13279. //idx_sample=1;
  13280. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13281. if(gunType[gun_index] == 'J')
  13282. {
  13283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13284. {
  13285. tempIndex = ((gun_index==2) ? 1: 0);
  13286. }
  13287. else
  13288. {
  13289. tempIndex = gun_index;
  13290. }
  13291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13292. {
  13293. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13294. {
  13295. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13296. }
  13297. }// End of for CHAdeMO_QUANTITY
  13298. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13299. }
  13300. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13301. {
  13302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13303. {
  13304. tempIndex = ((gun_index==2) ? 1: 0);
  13305. }
  13306. else
  13307. {
  13308. tempIndex = gun_index;
  13309. }
  13310. for (int index = 0; index < CCS_QUANTITY; index++)
  13311. {
  13312. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13313. {
  13314. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13315. }
  13316. }// End of for CCS_QUANTITY
  13317. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13318. }
  13319. else if(gunType[gun_index] == 'G')
  13320. {
  13321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13322. {
  13323. tempIndex = ((gun_index==2) ? 1: 0);
  13324. }
  13325. else
  13326. {
  13327. tempIndex = gun_index;
  13328. }
  13329. for (int index = 0; index < GB_QUANTITY; index++)
  13330. {
  13331. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13332. {
  13333. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13334. }
  13335. }// End of for GB_QUANTITY
  13336. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13337. }
  13338. else
  13339. {
  13340. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13341. {
  13342. tempIndex = 2;
  13343. }
  13344. else
  13345. {
  13346. tempIndex = gun_index;
  13347. }
  13348. for (int index = 0; index < AC_QUANTITY; index++)
  13349. {
  13350. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13351. {
  13352. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13353. }
  13354. }// End of for AC_QUANTITY
  13355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13356. }
  13357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13359. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13360. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13361. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13362. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13363. //2.2 Energy.Active.Export.Interval
  13364. //idx_sample=2;
  13365. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13366. if(gunType[gun_index] == 'J')
  13367. {
  13368. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13369. {
  13370. tempIndex = ((gun_index==2) ? 1: 0);
  13371. }
  13372. else
  13373. {
  13374. tempIndex = gun_index;
  13375. }
  13376. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13377. {
  13378. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13379. {
  13380. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13381. }
  13382. }// END OF CHAdeMO_QUANTITY
  13383. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13384. }
  13385. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13386. {
  13387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13388. {
  13389. tempIndex = ((gun_index==2) ? 1: 0);
  13390. }
  13391. else
  13392. {
  13393. tempIndex = gun_index;
  13394. }
  13395. for (int index = 0; index < CCS_QUANTITY; index++)
  13396. {
  13397. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13398. {
  13399. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13400. }
  13401. }// END OF CCS_QUANTITY
  13402. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13403. }
  13404. else if(gunType[gun_index] == 'G')
  13405. {
  13406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13407. {
  13408. tempIndex = ((gun_index==2) ? 1: 0);
  13409. }
  13410. else
  13411. {
  13412. tempIndex = gun_index;
  13413. }
  13414. for (int index = 0; index < GB_QUANTITY; index++)
  13415. {
  13416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13417. {
  13418. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13419. }
  13420. }// END OF GB_QUANTITY
  13421. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13422. }
  13423. else
  13424. {
  13425. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13426. {
  13427. tempIndex = 2;
  13428. }
  13429. else
  13430. {
  13431. tempIndex = gun_index;
  13432. }
  13433. for (int index = 0; index < AC_QUANTITY; index++)
  13434. {
  13435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13436. {
  13437. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13438. }
  13439. }// END OF AC_QUANTITY
  13440. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13441. }
  13442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13445. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13446. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13447. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13448. //2.3 Power.Active.Export
  13449. //idx_sample=3;
  13450. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13451. if(gunType[gun_index] == 'J')
  13452. {
  13453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13454. {
  13455. tempIndex = ((gun_index==2) ? 1: 0);
  13456. }
  13457. else
  13458. {
  13459. tempIndex = gun_index;
  13460. }
  13461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13462. {
  13463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13464. {
  13465. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13466. }
  13467. } // End for CHAdeMO_QUANTITY
  13468. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13469. }
  13470. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13471. {
  13472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13473. {
  13474. tempIndex = ((gun_index==2) ? 1: 0);
  13475. }
  13476. else
  13477. {
  13478. tempIndex = gun_index;
  13479. }
  13480. for (int index = 0; index < CCS_QUANTITY; index++)
  13481. {
  13482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13483. {
  13484. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13485. }
  13486. } // END for CCS_QUANTITY
  13487. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13488. }
  13489. else if(gunType[gun_index] == 'G')
  13490. {
  13491. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13492. {
  13493. tempIndex = ((gun_index==2) ? 1: 0);
  13494. }
  13495. else
  13496. {
  13497. tempIndex = gun_index;
  13498. }
  13499. for (int index = 0; index < GB_QUANTITY; index++)
  13500. {
  13501. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13502. {
  13503. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13504. }
  13505. }// END for GB_QUANTITY
  13506. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13507. }
  13508. else
  13509. {
  13510. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13511. {
  13512. tempIndex = 2;
  13513. }
  13514. else
  13515. {
  13516. tempIndex = gun_index;
  13517. }
  13518. for (int index = 0; index < AC_QUANTITY; index++)
  13519. {
  13520. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13521. {
  13522. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13523. }
  13524. } // END for AC_QUANTITY
  13525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13526. }
  13527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13530. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13533. //2.4 Voltage
  13534. //idx_sample=4;
  13535. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13536. if(gunType[gun_index] == 'J')
  13537. {
  13538. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13539. {
  13540. tempIndex = ((gun_index==2) ? 1: 0);
  13541. }
  13542. else
  13543. {
  13544. tempIndex = gun_index;
  13545. }
  13546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13547. {
  13548. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13549. {
  13550. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13551. }
  13552. } // END OF FOR CHAdeMO_QUANTITY
  13553. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13554. }
  13555. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13556. {
  13557. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13558. {
  13559. tempIndex = ((gun_index==2) ? 1: 0);
  13560. }
  13561. else
  13562. {
  13563. tempIndex = gun_index;
  13564. }
  13565. for (int index = 0; index < CCS_QUANTITY; index++)
  13566. {
  13567. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13568. {
  13569. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13570. }
  13571. } // END OF FOR CCS_QUANTITY
  13572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13573. }
  13574. else if(gunType[gun_index] == 'G')
  13575. {
  13576. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13577. {
  13578. tempIndex = ((gun_index==2) ? 1: 0);
  13579. }
  13580. else
  13581. {
  13582. tempIndex = gun_index;
  13583. }
  13584. for (int index = 0; index < GB_QUANTITY; index++)
  13585. {
  13586. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13587. {
  13588. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13589. }
  13590. } // END OF FOR GB_QUANTITY
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13592. }
  13593. else
  13594. {
  13595. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13596. {
  13597. tempIndex = 2;
  13598. }
  13599. else
  13600. {
  13601. tempIndex = gun_index;
  13602. }
  13603. for (int index = 0; index < AC_QUANTITY; index++)
  13604. {
  13605. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13606. {
  13607. 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
  13608. }
  13609. } // END OF FOR AC_QUANTITY
  13610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13611. }
  13612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13615. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13618. //2.5 SoC
  13619. //idx_sample=5;
  13620. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13621. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13622. {
  13623. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13624. {
  13625. tempIndex = ((gun_index==2) ? 1: 0);
  13626. }
  13627. else
  13628. {
  13629. tempIndex = gun_index;
  13630. }
  13631. if(gunType[gun_index] == 'J')
  13632. {
  13633. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13634. {
  13635. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13636. {
  13637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13638. }
  13639. }
  13640. }
  13641. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13642. {
  13643. for (int index = 0; index < CCS_QUANTITY; index++)
  13644. {
  13645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13646. {
  13647. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13648. }
  13649. }
  13650. }
  13651. else if(gunType[gun_index] == 'G')
  13652. {
  13653. for (int index = 0; index < GB_QUANTITY; index++)
  13654. {
  13655. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13656. {
  13657. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13658. }
  13659. }
  13660. }
  13661. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13662. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13663. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13665. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13667. } // END FOR DC CASE
  13668. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13669. {
  13670. 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\"}]}]}]"
  13671. ,gun_index+1
  13672. ,MESSAGE_TYPE_CALL
  13673. ,guid
  13674. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13675. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13676. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13678. ,"PowerLoss"
  13679. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13699. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13700. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13701. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13702. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13703. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13704. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13705. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13706. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13707. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13708. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13709. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13711. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13712. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13722. );
  13723. }
  13724. else
  13725. {
  13726. 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\"}]}]}]"
  13727. ,gun_index+1
  13728. ,MESSAGE_TYPE_CALL
  13729. ,guid
  13730. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13731. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13732. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13734. ,"PowerLoss"
  13735. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13771. );
  13772. }
  13773. // Check File "TempStopTransaction" Exist
  13774. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13775. {
  13776. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13777. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13778. }
  13779. else
  13780. {
  13781. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13782. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13783. if(log == NULL)
  13784. {
  13785. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13786. return ;
  13787. }
  13788. else
  13789. {
  13790. fclose(log);
  13791. }
  13792. }
  13793. //Add TempStopTransaction | Update TempStopTransaction
  13794. // open file for writing
  13795. FILE *outfile;
  13796. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13797. //DEBUG_INFO("data = %s\n", queuedata);
  13798. fputs(queuedata, outfile);
  13799. fputs("\n", outfile);
  13800. fclose (outfile);
  13801. }
  13802. void checkTempStopTransaction(int gun_index)
  13803. {
  13804. FILE *fptr1;
  13805. char ch;
  13806. char str[1200]={0};
  13807. char guid[37]={0};
  13808. char tempdata[65]={0};
  13809. char connectorStr[2]={0};
  13810. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13811. //TempStopTransaction格式: 槍號,StopTransaction封包
  13812. if (!fptr1)
  13813. {
  13814. //printf(" File not found or unable to open the input file!!\n");
  13815. return ;
  13816. }
  13817. ch=fgetc(fptr1);
  13818. //printf(" Now the content of the file %s is : \n",fname);
  13819. rewind(fptr1);
  13820. if(ch!=EOF)
  13821. {
  13822. // copy all contents to the temporary file except the specific line
  13823. while (fgets(str, 1200, fptr1) != NULL)
  13824. {
  13825. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13826. if(str[0]=='\0')
  13827. {
  13828. break;
  13829. }
  13830. //TempStopTransaction格式: 槍號,StopTransaction封包
  13831. strncpy(connectorStr, str, 1);
  13832. if(atoi(connectorStr) != (gun_index+1))
  13833. {
  13834. DEBUG_INFO("atoi(connectorStr) = %d\n", atoi(connectorStr));
  13835. return ;
  13836. }
  13837. //random_uuid(guid);
  13838. strncpy(guid, str+6, 36); //copy guid
  13839. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13840. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13841. {
  13842. DEBUG_INFO("StopTransaction mapitem pass\n");
  13843. }
  13844. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13845. memset(str,0,ARRAY_SIZE(str));
  13846. }
  13847. }
  13848. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13849. fclose(fptr1);
  13850. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13851. }
  13852. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13853. {
  13854. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13855. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13856. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13857. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13858. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13859. }
  13860. int GetWebSocketPingInterval(void)
  13861. {
  13862. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13863. }
  13864. int GetServerSign(void)
  13865. {
  13866. return server_sign;
  13867. }
  13868. void SetServerSign(int value)
  13869. {
  13870. server_sign = value;
  13871. }
  13872. int GetBootNotificationInterval(void)
  13873. {
  13874. return BootNotificationInterval;
  13875. }
  13876. int GetInternetConn(void)
  13877. {
  13878. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13879. }
  13880. void InitialSystemValue(void)
  13881. {
  13882. int connectorIndex = 0;
  13883. //int valueASCII = 0;
  13884. server_cycle_Status = 120;
  13885. gunTotalNumber=0;
  13886. SystemInitial = 0;
  13887. localversion=0;
  13888. BootNotificationInterval = 0;
  13889. authorizeRetryTimes = 0;
  13890. GunStatusInterval = 10;
  13891. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13892. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13893. //Hear Beat
  13894. HeartBeatWithNOResponse = 0;
  13895. HeartBeatCountPerHour = 0;
  13896. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13897. FirstHeartBeat = 0;
  13898. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13899. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13900. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  13901. memset(statusModeChage, 0, sizeof(statusModeChage));
  13902. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13903. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13904. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13905. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13906. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13907. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13908. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13909. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13910. memset(gunType, 0, sizeof(gunType));
  13911. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13912. {
  13913. //check connector / socket type (index: 8, 9, 10)
  13914. for(int index=7; index <10 ; index++)
  13915. {
  13916. if(index != 8)
  13917. {
  13918. // DC Connector
  13919. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13920. {
  13921. SystemInitial = SystemInitial + 1;
  13922. gunTotalNumber = gunTotalNumber + 1;
  13923. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13924. connectorIndex = connectorIndex + 1;
  13925. }
  13926. }
  13927. else
  13928. {
  13929. // AC Connector
  13930. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13931. {
  13932. SystemInitial = SystemInitial + 1;
  13933. gunTotalNumber = gunTotalNumber + 1;
  13934. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13935. connectorIndex = connectorIndex + 1;
  13936. }
  13937. }
  13938. }
  13939. //DEBUG_INFO("DC ...\n");
  13940. }
  13941. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13942. {
  13943. //check connector / socket type (index: 8, 9, 10)
  13944. for(int index=7; index <10 ; index++)
  13945. {
  13946. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13947. {
  13948. SystemInitial = SystemInitial + 1;
  13949. gunTotalNumber = gunTotalNumber + 1;
  13950. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13951. connectorIndex = connectorIndex + 1;
  13952. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13953. }
  13954. }
  13955. }
  13956. //Status && ConnectorPlugIn Setting
  13957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13958. {
  13959. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13960. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13961. }
  13962. for (int index = 0; index < CCS_QUANTITY; index++)
  13963. {
  13964. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13965. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13966. }
  13967. for (int index = 0; index < GB_QUANTITY; index++)
  13968. {
  13969. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13970. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13971. }
  13972. for (int index = 0; index < AC_QUANTITY; index++)
  13973. {
  13974. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13975. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13976. }
  13977. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13978. {
  13979. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13980. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13981. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13982. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13983. }
  13984. // Charger PRE_SYS_MODE
  13985. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13986. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13987. clientTime.Heartbeat=time((time_t*)NULL);
  13988. sleep(1);
  13989. }
  13990. void LWS_Send(char * str)
  13991. {
  13992. //=====================================================
  13993. // Check InternetConn 0: disconnected, 1: connected
  13994. //====================================================
  13995. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13996. {
  13997. DEBUG_INFO("offline now !!!\n");
  13998. return;
  13999. }
  14000. pthread_mutex_lock(&lock_send);
  14001. memset(SendBuffer, 0, SendBufLen);
  14002. sprintf((char *)SendBuffer, "%s", str);
  14003. pthread_mutex_unlock(&lock_send);
  14004. lws_callback_on_writable(wsi_client);
  14005. lws_service(context, 0);
  14006. //sleep(1);
  14007. }