MessageHandler.c 596 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. //===================================
  18. // Define CP State constant
  19. //===================================
  20. #define CP_STATE_UNKNOWN 0
  21. #define CP_STATE_A 1
  22. #define CP_STATE_B 2
  23. #define CP_STATE_C 3
  24. #define CP_STATE_D 4
  25. #define CP_STATE_E 5
  26. #define CP_STATE_F 6
  27. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  28. struct StatusCodeData *ShmStatusCodeData;
  29. struct PsuData *ShmPsuData ;
  30. struct OCPP16Data *ShmOCPP16Data;
  31. #define MACROSTR(k) #k
  32. //ConfigurationMaxKeys
  33. #define GetConfigurationMaxKeysNUM 43
  34. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  35. char queuedata[2600] = {0};
  36. //=================================
  37. // StatusNotification cycle
  38. //=================================
  39. static int server_cycle_Status = 120;
  40. //===============================
  41. // Configuration: unknownkey
  42. //===============================
  43. static char unknownkey[10][20] = {0};
  44. static int UnknownKeynum = 0;
  45. //===============================
  46. // Gun Total Numbers
  47. //===============================
  48. static int gunTotalNumber = 0;
  49. static unsigned char gunType[4] = {0};
  50. //===============================
  51. // Local List Version
  52. //===============================
  53. static int localversion=0;
  54. static char idTagAuthorization[32] = {0};
  55. //===============================
  56. // OCPP sign variable
  57. //===============================
  58. static int server_sign = FALSE;
  59. int server_pending = FALSE;
  60. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  61. static int BootNotificationInterval = 0;
  62. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  63. //===============================
  64. // OCPP auth variable
  65. //===============================
  66. static int authorizeRetryTimes = 0; //number of Retry times
  67. //===============================
  68. // OCPP other variables
  69. //===============================
  70. //int isUpdateRequest = FALSE;
  71. static int HeartBeatWaitTime = 10;
  72. static int FirstHeartBeat = 0;
  73. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  74. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  75. static char CurrentChargingProfileScheduleStr[30] = {0};
  76. //========================================
  77. // OCPP status/previous related variables
  78. //========================================
  79. static int GunStatusInterval = 10;
  80. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  81. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  82. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  83. static int GbPreviousSystemStatus[GB_QUANTITY];
  84. static int AcPreviousSystemStatus[AC_QUANTITY];
  85. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  86. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  87. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  88. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  89. static int TransactionMessageAttemptsValue = 0;
  90. static int TransactionMessageRetryIntervalValue = 0;
  91. static int TempMeterValueInterval = 0;
  92. static struct OCPPAuthLocalElemet
  93. {
  94. int listVersionInt;
  95. char idTagstr[20];
  96. char parentIdTag[20];
  97. char expiryDate[30];
  98. char idTagstatus[16];
  99. }idTagQuery;
  100. //=============================================
  101. // OCPP HeartBeat Response Not Receive Counts
  102. //============================================
  103. static int HeartBeatWithNOResponse = 0;
  104. static int HeartBeatCountPerHour = 0;
  105. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  106. extern int GetTransactionQueueNum(void);
  107. extern pthread_mutex_t mutex1;
  108. extern struct Charger_Info Charger;
  109. extern sqlite3 *db;
  110. int TransactionMessageAttemptsGet(void);
  111. int TransactionMessageRetryIntervalGet(void);
  112. int GetOcppConnStatus(void);
  113. void SetOcppConnStatus(uint8_t status);
  114. int setKeyValue(char *key, char *value);
  115. void OCPP_get_TableAuthlocalAllData(void);
  116. void processUnkownKey(void);
  117. struct StructOCPPMeterValue
  118. {
  119. unsigned char TimeStamp[28];
  120. struct StructSampledValue SampledValue[10];
  121. };
  122. struct ClientTime
  123. {
  124. unsigned int Heartbeat;
  125. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  126. unsigned int StartTransaction;
  127. unsigned int StopTransaction;
  128. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  129. }clientTime;
  130. typedef union
  131. {
  132. //Operations Initiated by Central System
  133. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  134. struct
  135. {
  136. //CsMsgValue[0]
  137. unsigned char StatusNotificationReq :1; //bit 0,
  138. unsigned char StatusNotificationConf :1; //bit 0,
  139. unsigned char :6; //bit 2~7
  140. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  141. }CpinitiateMsg;
  142. CpinitiateMsg cpinitateMsg;
  143. //==========================================
  144. // Init all Enumeration & Mapping String
  145. //==========================================
  146. /*ChargePointErrorCode*/
  147. typedef enum {
  148. ConnectorLockFailure,
  149. EVCommunicationError,
  150. GroundFailure,
  151. HighTemperature,
  152. InternalError,
  153. LocalListConflict,
  154. NoError,
  155. OtherError,
  156. OverCurrentFailure,
  157. OverVoltage,
  158. PowerMeterFailure,
  159. PowerSwitchFailure,
  160. ReaderFailure,
  161. ResetFailure,
  162. UnderVoltage,
  163. WeakSignal
  164. } ChargePointErrorCode;
  165. #if 0
  166. static char *ChargePointErrorCodeStr[] = {
  167. MACROSTR(ConnectorLockFailure),
  168. MACROSTR(EVCommunicationError),
  169. MACROSTR(GroundFailure),
  170. MACROSTR(HighTemperature),
  171. MACROSTR(InternalError),
  172. MACROSTR(LocalListConflict),
  173. MACROSTR(NoError),
  174. MACROSTR(OtherError),
  175. MACROSTR(OverCurrentFailure),
  176. MACROSTR(OverVoltage),
  177. MACROSTR(PowerMeterFailure),
  178. MACROSTR(PowerSwitchFailure),
  179. MACROSTR(ReaderFailure),
  180. MACROSTR(ResetFailure),
  181. MACROSTR(UnderVoltage),
  182. MACROSTR(WeakSignal)
  183. };
  184. #endif
  185. /*ChargePointStatus*/
  186. typedef enum {
  187. Available =0,
  188. Preparing,
  189. Charging,
  190. SuspendedEVSE,
  191. SuspendedEV,
  192. Finishing,
  193. Reserved,
  194. Unavailable,
  195. Faulted
  196. } ChargePointStatus;
  197. static char * ChargePointStatusStr[] = {
  198. MACROSTR(Available),
  199. MACROSTR(Preparing),
  200. MACROSTR(Charging),
  201. MACROSTR(SuspendedEVSE),
  202. MACROSTR(SuspendedEV),
  203. MACROSTR(Finishing),
  204. MACROSTR(Reserved),
  205. MACROSTR(Unavailable),
  206. MACROSTR(Faulted)
  207. };
  208. /*AvailabilityType*/
  209. typedef enum {
  210. RegistrationStatus_Accepted,
  211. RegistrationStatus_Pending,
  212. RegistrationStatus_Rejected
  213. } RegistrationStatus;
  214. static char *RegistrationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Pending),
  217. MACROSTR(Rejected)
  218. };
  219. /*AvailabilityType*/
  220. typedef enum {
  221. Inoperative,
  222. Operative
  223. } AvailabilityType;
  224. static char *AvailabilityTypeStr[] = {
  225. MACROSTR(Inoperative),
  226. MACROSTR(Operative)
  227. };
  228. /*AvailabilityStatus*/
  229. typedef enum {
  230. Accepted,
  231. Rejected,
  232. Scheduled
  233. } AvailabilityStatus;
  234. static char *AvailabilityStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(Scheduled)
  238. };
  239. /*ConfigurationStatus*/
  240. typedef enum {
  241. ConfigurationStatus_Accepted,
  242. ConfigurationStatus_Rejected,
  243. RebootRequired,
  244. NotSupported
  245. } ConfigurationStatus;
  246. static char *ConfigurationStatusStr[] = {
  247. MACROSTR(Accepted),
  248. MACROSTR(Rejected),
  249. MACROSTR(RebootRequired),
  250. MACROSTR(NotSupported)
  251. };
  252. /*ClearCacheStatus*/
  253. typedef enum {
  254. ClearCacheStatus_Accepted,
  255. ClearCacheStatus_Rejected
  256. } ClearCacheStatus;
  257. static char *ClearCacheStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected)
  260. };
  261. /*ChargingProfilePurposeType*/
  262. typedef enum {
  263. ChargePointMaxProfile,
  264. TxDefaultProfile,
  265. TxProfile
  266. } ChargingProfilePurposeType;
  267. static char *ChargingProfilePurposeTypeStr[] = {
  268. MACROSTR(ChargePointMaxProfile),
  269. MACROSTR(TxDefaultProfile),
  270. MACROSTR(TxProfile)
  271. };
  272. /*ChargingProfileStatus*/
  273. typedef enum {
  274. ChargingProfileStatus_Accepted,
  275. ChargingProfileStatus_Rejected,
  276. ChargingProfileStatus_NotSupported
  277. } ChargingProfileStatus;
  278. static char *ChargingProfileStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Rejected),
  281. MACROSTR(NotSupported)
  282. };
  283. /*ClearChargingProfileStatus*/
  284. typedef enum {
  285. ClearChargingProfileStatus_Accepted,
  286. ClearChargingProfileStatus_Unknown
  287. } ClearChargingProfileStatus;
  288. static char *ClearChargingProfileStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Unknown)
  291. };
  292. /*GetCompositeScheduleStatus*/
  293. typedef enum {
  294. GetCompositeScheduleStatus_Accepted,
  295. GetCompositeScheduleStatus_Rejected
  296. } GetCompositeScheduleStatus;
  297. static char *GetCompositeScheduleStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected)
  300. };
  301. /*ChargingRateUnitType*/
  302. typedef enum {
  303. ChargingRateUnitType_W,
  304. ChargingRateUnitType_A
  305. } ChargingRateUnitType;
  306. /*AuthorizationStatus*/
  307. typedef enum {
  308. AuthorizationStatus_Accepted ,
  309. AuthorizationStatus_Blocked ,
  310. AuthorizationStatus_Expired ,
  311. AuthorizationStatus_Invalid ,
  312. AuthorizationStatus_ConcurrentTx
  313. } AuthorizationStatus;
  314. /*UpdateType*/
  315. typedef enum {
  316. Differential ,
  317. Full
  318. } UpdateType;
  319. static char *UpdateTypeStr[] = {
  320. MACROSTR(Differential),
  321. MACROSTR(Full)
  322. };
  323. /*UpdateStatus*/
  324. typedef enum {
  325. UpdateStatus_Accepted ,
  326. UpdateStatus_Failed ,
  327. UpdateStatus_NotSupported ,
  328. UpdateStatus_VersionMismatch
  329. } UpdateStatus;
  330. static char *UpdateStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Failed),
  333. MACROSTR(NotSupported),
  334. MACROSTR(VersionMismatch)
  335. };
  336. /*RemoteStartStopStatus*/
  337. typedef enum {
  338. RemoteStartStopStatus_Accepted,
  339. RemoteStartStopStatus_Rejected
  340. } RemoteStartStopStatus;
  341. static char *RemoteStartStopStatusStr[] = {
  342. MACROSTR(Accepted),
  343. MACROSTR(Rejected)
  344. };
  345. /*ReservationStatus*/
  346. typedef enum {
  347. ReservationStatus_Accepted,
  348. ReservationStatus_Faulted,
  349. ReservationStatus_Occupied,
  350. ReservationStatus_Rejected,
  351. ReservationStatus_Unavailable
  352. } ReservationStatus;
  353. static char *ReservationStatusStr[] = {
  354. MACROSTR(Accepted),
  355. MACROSTR(Faulted),
  356. MACROSTR(Occupied),
  357. MACROSTR(Rejected),
  358. MACROSTR(Unavailable)
  359. };
  360. /*ResetType*/
  361. typedef enum {
  362. Hard,
  363. Soft
  364. } ResetType;
  365. static char *ResetTypeStr[] = {
  366. MACROSTR(Hard),
  367. MACROSTR(Soft)
  368. };
  369. /*ResetStatus*/
  370. typedef enum {
  371. ResetStatus_Accepted,
  372. ResetStatus_Rejected
  373. } ResetStatus;
  374. static char *ResetStatusStr[] = {
  375. MACROSTR(Accepted),
  376. MACROSTR(Rejected)
  377. };
  378. /*DiagnosticsStatus*/
  379. typedef enum {
  380. DiagnosticsStatus_Idle,
  381. DiagnosticsStatus_Uploaded,
  382. DiagnosticsStatus_UploadFailed,
  383. DiagnosticsStatus_Uploading
  384. } DiagnosticsStatus;
  385. static char * DiagnosticsStatusStr[] = {
  386. MACROSTR(Idle),
  387. MACROSTR(Uploaded),
  388. MACROSTR(UploadFailed),
  389. MACROSTR(Uploading)
  390. };
  391. /*FirmwareStatus*/
  392. typedef enum {
  393. FirmwareStatus_Downloaded,
  394. FirmwareStatus_DownloadFailed,
  395. FirmwareStatus_Downloading,
  396. FirmwareStatus_Idle,
  397. FirmwareStatus_InstallationFailed,
  398. FirmwareStatus_Installing,
  399. FirmwareStatus_Installed
  400. } FirmwareStatus;
  401. static char * FirmwareStatusStr[] = {
  402. MACROSTR(Downloaded),
  403. MACROSTR(DownloadFailed),
  404. MACROSTR(Downloading),
  405. MACROSTR(Idle),
  406. MACROSTR(InstallationFailed),
  407. MACROSTR(Installing),
  408. MACROSTR(Installed)
  409. };
  410. /*MessageTrigger*/
  411. typedef enum {
  412. BootNotification,
  413. DiagnosticsStatusNotification,
  414. FirmwareStatusNotification,
  415. Heartbeat,
  416. MeterValues,
  417. StatusNotification
  418. } MessageTrigger;
  419. static char * MessageTriggerStr[] = {
  420. MACROSTR(BootNotification),
  421. MACROSTR(DiagnosticsStatusNotification),
  422. MACROSTR(FirmwareStatusNotification),
  423. MACROSTR(Heartbeat),
  424. MACROSTR(MeterValues),
  425. MACROSTR(StatusNotification)
  426. };
  427. /*TriggerMessageStatus*/
  428. typedef enum {
  429. TriggerMessageStatus_Accepted ,
  430. TriggerMessageStatus_Rejected ,
  431. TriggerMessageStatus_NotImplemented
  432. } TriggerMessageStatus;
  433. static char * TriggerMessageStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected),
  436. MACROSTR(NotImplemented)
  437. };
  438. /*UnlockStatus*/
  439. typedef enum {
  440. Unlocked,
  441. UnlockFailed,
  442. UnlockStatus_NotSupported
  443. } UnlockStatus;
  444. static char * UnlockStatusStr[] = {
  445. MACROSTR(Unlocked),
  446. MACROSTR(UnlockFailed),
  447. MACROSTR(NotSupported)
  448. };
  449. /*StopTransactionReason*/
  450. typedef enum {
  451. EmergencyStop,
  452. EVDisconnected,
  453. HardReset,
  454. Local,
  455. Other,
  456. PowerLoss,
  457. Reboot,
  458. Remote,
  459. SoftReset,
  460. UnlockCommand,
  461. DeAuthorized
  462. } StopTransactionReason;
  463. #if 0
  464. static char * StopTransactionReasonStr[] = {
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EVDisconnected),
  467. MACROSTR(HardReset),
  468. MACROSTR(Local),
  469. MACROSTR(Other),
  470. MACROSTR(PowerLoss),
  471. MACROSTR(Reboot),
  472. MACROSTR(Remote),
  473. MACROSTR(SoftReset),
  474. MACROSTR(UnlockCommand),
  475. MACROSTR(DeAuthorized)
  476. };
  477. #endif
  478. /*CancelReservationStatus*/
  479. typedef enum {
  480. CancelReservationStatus_Accepted,
  481. CancelReservationStatus_Rejected
  482. } CancelReservationStatus;
  483. static char * CancelReservationStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected)
  486. };
  487. /*ReadingContext*/
  488. typedef enum {
  489. ReadingContext_Interruption_Begin,
  490. ReadingContext_Interruption_End,
  491. ReadingContext_Other,
  492. ReadingContext_Sample_Clock,
  493. ReadingContext_Sample_Periodic ,
  494. ReadingContext_Transaction_Begin ,
  495. ReadingContext_Transaction_End,
  496. ReadingContext_Trigger
  497. } ReadingContext;
  498. static char * ReadingContextStr[] = {
  499. MACROSTR(Interruption.Begin),
  500. MACROSTR(Interruption.End),
  501. MACROSTR(Other),
  502. MACROSTR(Sample.Clock),
  503. MACROSTR(Sample.Periodic),
  504. MACROSTR(Transaction.Begin),
  505. MACROSTR(Transaction.End),
  506. MACROSTR(Trigger)
  507. };
  508. /*ValueFormat*/
  509. typedef enum {
  510. Raw,
  511. SignedData
  512. } ValueFormat;
  513. static char * ValueFormatStr[] = {
  514. MACROSTR(Raw),
  515. MACROSTR(SignedData)
  516. };
  517. /*Measurand*/
  518. typedef enum {
  519. Current_Export ,
  520. Current_Import,
  521. Current_Offered,
  522. Energy_Active_Export_Register,
  523. Energy_Active_Import_Register,
  524. Energy_Reactive_Export_Register,
  525. Energy_Reactive_Import_Register,
  526. Energy_Active_Export_Interval,
  527. Energy_Active_Import_Interval,
  528. Energy_Reactive_Export_Interval,
  529. Energy_Reactive_Import_Interval,
  530. Frequency,
  531. Power_Active_Export ,
  532. Power_Active_Import,
  533. Power_Factor,
  534. Power_Offered,
  535. Power_Reactive_Export,
  536. Power_Reactive_Import,
  537. RPM,
  538. SoC,
  539. Temperature ,
  540. Voltage
  541. } Measurand;
  542. static char * MeasurandStr[] = {
  543. MACROSTR(Current.Export),
  544. MACROSTR(Current.Import),
  545. MACROSTR(Current.Offered),
  546. MACROSTR(Energy.Active.Export.Register),
  547. MACROSTR(Energy.Active.Import.Register),
  548. MACROSTR(Energy.Reactive.Export.Register),
  549. MACROSTR(Energy.Reactive.Import.Register),
  550. MACROSTR(Energy.Active.Export.Interval),
  551. MACROSTR(Energy.Active.Import.Interval),
  552. MACROSTR(Energy.Reactive.Export.Interval),
  553. MACROSTR(Energy.Reactive.Import.Interval),
  554. MACROSTR(Frequency),
  555. MACROSTR(Power.Active.Export),
  556. MACROSTR(Power.Active.Import),
  557. MACROSTR(Power.Factor),
  558. MACROSTR(Power.Offered),
  559. MACROSTR(Power.Reactive.ExportMACROSTR),
  560. MACROSTR(Power.Reactive.Import),
  561. MACROSTR(RPM),
  562. MACROSTR(SoC),
  563. MACROSTR(Temperature),
  564. MACROSTR(Voltage)
  565. };
  566. /*Location*/
  567. typedef enum {
  568. Location_Body,
  569. Location_Cable,
  570. Location_EV,
  571. Location_Inlet ,
  572. Location_Outlet
  573. } Location;
  574. static char * LocationStr[] = {
  575. MACROSTR(Body),
  576. MACROSTR(Cable),
  577. MACROSTR(EV),
  578. MACROSTR(Inlet),
  579. MACROSTR(Outlet)
  580. };
  581. /*Phase*/
  582. typedef enum {
  583. L1,
  584. L2,
  585. L3,
  586. N,
  587. L1_N,
  588. L2_N,
  589. L3_N,
  590. L1_L2,
  591. L2_L3,
  592. L3_L1
  593. } Phase;
  594. static char * PhaseStr[] = {
  595. MACROSTR(L1),
  596. MACROSTR(L2),
  597. MACROSTR(L3),
  598. MACROSTR(N),
  599. MACROSTR(L1-N),
  600. MACROSTR(L2-N),
  601. MACROSTR(L3-N),
  602. MACROSTR(L1-L2),
  603. MACROSTR(L2-L3),
  604. MACROSTR(L3-L1)
  605. };
  606. /*UnitOfMeasure*/
  607. typedef enum {
  608. UnitOfMeasure_Wh,
  609. UnitOfMeasure_kWh ,
  610. UnitOfMeasure_varh ,
  611. UnitOfMeasure_kvarh ,
  612. UnitOfMeasure_W ,
  613. UnitOfMeasure_kW ,
  614. UnitOfMeasure_VA ,
  615. UnitOfMeasure_kVA ,
  616. UnitOfMeasure_var ,
  617. UnitOfMeasure_kvar ,
  618. UnitOfMeasure_A ,
  619. UnitOfMeasure_V ,
  620. UnitOfMeasure_Celsius ,
  621. UnitOfMeasure_Fahrenheit ,
  622. UnitOfMeasure_K ,
  623. UnitOfMeasure_Percent
  624. } UnitOfMeasure;
  625. static char * UnitOfMeasureStr[] = {
  626. MACROSTR(Wh),
  627. MACROSTR(kWh),
  628. MACROSTR(varh),
  629. MACROSTR(kvarh),
  630. MACROSTR(W),
  631. MACROSTR(kW),
  632. MACROSTR(VA),
  633. MACROSTR(kVA),
  634. MACROSTR(var),
  635. MACROSTR(kvar),
  636. MACROSTR(A),
  637. MACROSTR(V),
  638. MACROSTR(Celsius),
  639. MACROSTR(Fahrenheit),
  640. MACROSTR(K),
  641. MACROSTR(Percent)
  642. };
  643. enum LocalAuthListManagementProfile{
  644. LocalAuthListEnabled=0,
  645. LocalAuthListMaxLength,
  646. SendLocalListMaxLength,
  647. _LocalAuthListManagementProfile_CNT
  648. };
  649. enum ReservationProfile{
  650. ReserveConnectorZeroSupported
  651. };
  652. enum SmartChargingProfile{
  653. ChargeProfileMaxStackLevel,
  654. ChargingScheduleAllowedChargingRateUnit,
  655. ChargingScheduleMaxPeriods,
  656. ConnectorSwitch3to1PhaseSupported,
  657. MaxChargingProfilesInstalled
  658. };
  659. enum ChargerSystemStatus{
  660. ChargerSystemStatus_Booting,
  661. ChargerSystemStatus_Idle,
  662. ChargerSystemStatus_Authorizing,
  663. ChargerSystemStatus_Preparing,
  664. ChargerSystemStatus_Charging,
  665. ChargerSystemStatus_Terminating,
  666. ChargerSystemStatus_Alarm,
  667. ChargerSystemStatus_Fault
  668. };
  669. enum GetConfigurationKey {
  670. GetConfiguration_AllowOfflineTxForUnknownId=0,
  671. GetConfiguration_AuthorizationCacheEnabled,
  672. GetConfiguration_AuthorizeRemoteTxRequests,
  673. GetConfiguration_BlinkRepeat,
  674. GetConfiguration_ClockAlignedDataInterval,
  675. GetConfiguration_ConnectionTimeOut,
  676. GetConfiguration_GetConfigurationMaxKeys,
  677. GetConfiguration_HeartbeatInterval,
  678. GetConfiguration_LightIntensity,
  679. GetConfiguration_LocalAuthorizeOffline,
  680. GetConfiguration_LocalPreAuthorize,
  681. GetConfiguration_MaxEnergyOnInvalidId,
  682. GetConfiguration_MeterValuesAlignedData,
  683. GetConfiguration_MeterValuesAlignedDataMaxLength,
  684. GetConfiguration_MeterValuesSampledData,
  685. GetConfiguration_MeterValuesSampledDataMaxLength,
  686. GetConfiguration_MeterValueSampleInterval,
  687. GetConfiguration_MinimumStatusDuration,
  688. GetConfiguration_NumberOfConnectors,
  689. GetConfiguration_ResetRetries,
  690. GetConfiguration_ConnectorPhaseRotation,
  691. GetConfiguration_ConnectorPhaseRotationMaxLength,
  692. GetConfiguration_StopTransactionOnEVSideDisconnect,
  693. GetConfiguration_StopTransactionOnInvalidId,
  694. GetConfiguration_StopTxnAlignedData,
  695. GetConfiguration_StopTxnAlignedDataMaxLength,
  696. GetConfiguration_StopTxnSampledData,
  697. GetConfiguration_StopTxnSampledDataMaxLength,
  698. GetConfiguration_SupportedFeatureProfiles,
  699. GetConfiguration_SupportedFeatureProfilesMaxLength,
  700. GetConfiguration_TransactionMessageAttempts,
  701. GetConfiguration_TransactionMessageRetryInterval,
  702. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  703. GetConfiguration_WebSocketPingInterval,
  704. GetConfiguration_LocalAuthListEnabled,
  705. GetConfiguration_LocalAuthListMaxLength,
  706. GetConfiguration_SendLocalListMaxLength,
  707. GetConfiguration_ReserveConnectorZeroSupported,
  708. GetConfiguration_ChargeProfileMaxStackLevel,
  709. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  710. GetConfiguration_ChargingScheduleMaxPeriods,
  711. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  712. GetConfiguration_MaxChargingProfilesInstalled,
  713. };
  714. //GetConfiguration Array
  715. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  717. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  718. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  719. //==========================================
  720. // GetCompositeSchedule logic related function
  721. //==========================================
  722. int DiffTimebSec(struct timeb ST, struct timeb ET)
  723. {
  724. //return milli-second
  725. unsigned int StartTime,StopTime;
  726. StartTime=(unsigned int)ST.time;
  727. StopTime=(unsigned int)ET.time;
  728. return (StopTime-StartTime);
  729. }
  730. int DiffTimebWithNowSec(struct timeb ST)
  731. {
  732. //return milli-second
  733. struct timeb ET;
  734. unsigned int StartTime,StopTime;
  735. ftime(&ET);
  736. StartTime=(unsigned int)ST.time;
  737. StopTime=(unsigned int)ET.time;
  738. return (StopTime-StartTime);
  739. }
  740. int getStartStop(uint8_t *start, uint8_t *stop)
  741. {
  742. int result = -1;
  743. struct tm tmStart;
  744. struct timeb tbStart;
  745. struct tm tmStop;
  746. struct timeb tbStop;
  747. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  748. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  749. {
  750. tmStart.tm_year -= 1900;
  751. tmStart.tm_mon -= 1;
  752. tbStart.time = mktime(&tmStart);
  753. tbStart.millitm = 0;
  754. tmStop.tm_year -= 1900;
  755. tmStop.tm_mon -= 1;
  756. tbStop.time = mktime(&tmStop);
  757. tbStop.millitm = 0;
  758. result = DiffTimebSec(tbStart, tbStop);
  759. }
  760. else
  761. {
  762. DEBUG_WARN("Start or stop date parsing error.\r\n");
  763. }
  764. return result;
  765. }
  766. int getStartSinceToday(uint8_t *stop)
  767. {
  768. int result = -1;
  769. time_t t;
  770. struct tm *tmStartToday;
  771. struct timeb tbStartToday;
  772. struct tm tmStop;
  773. struct timeb tbStop;
  774. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  775. {
  776. t=time(NULL);
  777. tmStartToday=localtime(&t);
  778. tmStartToday->tm_hour = 0;
  779. tmStartToday->tm_min = 0;
  780. tmStartToday->tm_sec = 0;
  781. tbStartToday.time = mktime(tmStartToday);
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStartToday, tbStop);
  787. }
  788. return result;
  789. }
  790. int getStartSinceWeek(uint8_t *stop)
  791. {
  792. int result = -1;
  793. time_t t;
  794. struct tm *tmStartWeek;
  795. struct timeb tbStartWeek;
  796. struct tm tmStop;
  797. struct timeb tbStop;
  798. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  799. {
  800. t=time(NULL);
  801. tmStartWeek=localtime(&t);
  802. t-=86400*tmStartWeek->tm_wday;
  803. tmStartWeek=localtime(&t);
  804. tmStartWeek->tm_hour = 0;
  805. tmStartWeek->tm_min = 0;
  806. tmStartWeek->tm_sec = 0;
  807. tbStartWeek.time = mktime(tmStartWeek);
  808. tmStop.tm_year -= 1900;
  809. tmStop.tm_mon -= 1;
  810. tbStop.time = mktime(&tmStop);
  811. tbStop.millitm = 0;
  812. result = DiffTimebSec(tbStartWeek, tbStop);
  813. }
  814. return result;
  815. }
  816. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  817. {
  818. FILE *fp;
  819. char profileFileName[128];
  820. char *line = NULL;
  821. size_t len = 0;
  822. time_t CurrentTime;
  823. struct tm *tmComposite;
  824. struct StructChargingProfile maxProfile;
  825. struct StructChargingProfile defaultTxProfile;
  826. struct StructChargingProfile txProfile;
  827. struct StructChargingSchedulePeriod tmpPeriod;
  828. uint8_t limitMax=0;
  829. uint8_t limitDef=0;
  830. uint8_t limitTx=0;
  831. int compositePeriodIdx = 0;
  832. CurrentTime = time(NULL);
  833. tmComposite=localtime(&CurrentTime);
  834. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  835. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  836. compositeProfile->ChargingSchedule.Duration = durationReq;
  837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  838. {
  839. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  840. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  841. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  842. }
  843. compositeProfile->ChargingProfileId = 1;
  844. compositeProfile->StackLevel = 99 ;
  845. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  846. maxProfile.ChargingProfileId = -1;
  847. defaultTxProfile.ChargingProfileId = -1;
  848. txProfile.ChargingProfileId = -1;
  849. system("yes|rm /tmp/*.json");
  850. system("cp /Storage/OCPP/*.json /tmp");
  851. /*
  852. * Search valid charging profile
  853. */
  854. //DEBUG_INFO("====================================\n");
  855. // Search max profile
  856. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  857. if((access(profileFileName, F_OK))!=-1)
  858. {
  859. fp = fopen(profileFileName, "r");
  860. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  861. {
  862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  863. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  864. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  865. }
  866. maxProfile.ChargingProfileId = -1;
  867. maxProfile.StackLevel = -1;
  868. while(getline(&line, &len, fp) != -1)
  869. {
  870. json_object *obj = NULL;
  871. obj = json_tokener_parse(line);
  872. if(is_error(obj))
  873. {
  874. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  875. }
  876. else
  877. {
  878. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  879. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  880. )
  881. {
  882. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  883. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  884. )
  885. {
  886. struct tm tmFrom, tmTo;
  887. struct timeb tbFrom, tbTo;
  888. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  889. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  890. {
  891. tmFrom.tm_year -= 1900;
  892. tmFrom.tm_mon -= 1;
  893. tbFrom.time = mktime(&tmFrom);
  894. tmTo.tm_year -= 1900;
  895. tmTo.tm_mon -= 1;
  896. tbTo.time = mktime(&tmTo);
  897. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  898. {
  899. if(maxProfile.ChargingProfileId == -1)
  900. DEBUG_INFO("MaxProfile found.\n");
  901. else
  902. DEBUG_INFO("MaxProfile updated.\n");
  903. // Required item
  904. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  905. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  906. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  907. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  908. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  909. {
  910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  913. 3:
  914. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  915. }
  916. // Optional item
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  918. {
  919. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  920. }
  921. else
  922. {
  923. sprintf((char*)maxProfile.ValidFrom, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  926. {
  927. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  928. }
  929. else
  930. {
  931. sprintf((char*)maxProfile.ValidTo, " ");
  932. }
  933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  934. {
  935. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  936. }
  937. else
  938. {
  939. sprintf((char*)maxProfile.RecurrencyKind, " ");
  940. }
  941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  942. {
  943. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  944. }
  945. else
  946. {
  947. maxProfile.TransactionId = -1;
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  950. {
  951. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  952. }
  953. else
  954. {
  955. maxProfile.ChargingSchedule.Duration = -1;
  956. }
  957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  958. {
  959. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  960. }
  961. else
  962. {
  963. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  966. {
  967. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  968. }
  969. else
  970. {
  971. maxProfile.ChargingSchedule.MinChargingRate = -1;
  972. }
  973. }
  974. }
  975. }
  976. else
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  987. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  988. {
  989. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  990. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  991. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  992. 3:
  993. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  994. }
  995. // Optional item
  996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  997. {
  998. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  999. }
  1000. else
  1001. {
  1002. sprintf((char*)maxProfile.ValidFrom, " ");
  1003. }
  1004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1005. {
  1006. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1007. }
  1008. else
  1009. {
  1010. sprintf((char*)maxProfile.ValidTo, " ");
  1011. }
  1012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1013. {
  1014. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1015. }
  1016. else
  1017. {
  1018. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1019. }
  1020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1021. {
  1022. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1023. }
  1024. else
  1025. {
  1026. maxProfile.TransactionId = -1;
  1027. }
  1028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1029. {
  1030. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1031. }
  1032. else
  1033. {
  1034. maxProfile.ChargingSchedule.Duration = -1;
  1035. }
  1036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1037. {
  1038. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1039. }
  1040. else
  1041. {
  1042. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1043. }
  1044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1045. {
  1046. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1047. }
  1048. else
  1049. {
  1050. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1051. }
  1052. }
  1053. }
  1054. }
  1055. json_object_put(obj);
  1056. }
  1057. fclose(fp);
  1058. /*
  1059. if(maxProfile.ChargingProfileId !=-1)
  1060. {
  1061. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1062. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1063. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1064. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1065. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1067. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1068. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1069. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1070. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1071. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1073. {
  1074. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1075. {
  1076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1079. }
  1080. }
  1081. }
  1082. else
  1083. DEBUG_INFO("MaxProfile not found.\n");
  1084. DEBUG_INFO("------------------------------------\n");*/
  1085. }
  1086. // Search default tx profile
  1087. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1088. if((access(profileFileName, F_OK))==-1)
  1089. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1090. if((access(profileFileName, F_OK))!=-1)
  1091. {
  1092. fp = fopen(profileFileName, "r");
  1093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1094. {
  1095. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1096. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1097. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1098. }
  1099. defaultTxProfile.ChargingProfileId = -1;
  1100. defaultTxProfile.StackLevel = -1;
  1101. while(getline(&line, &len, fp) != -1)
  1102. {
  1103. json_object *obj = NULL;
  1104. obj = json_tokener_parse(line);
  1105. if(is_error(obj))
  1106. {
  1107. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1108. }
  1109. else
  1110. {
  1111. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1112. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1113. )
  1114. {
  1115. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1116. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1117. )
  1118. {
  1119. struct tm tmFrom, tmTo;
  1120. struct timeb tbFrom, tbTo;
  1121. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1122. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1123. {
  1124. tmFrom.tm_year -= 1900;
  1125. tmFrom.tm_mon -= 1;
  1126. tbFrom.time = mktime(&tmFrom);
  1127. tmTo.tm_year -= 1900;
  1128. tmTo.tm_mon -= 1;
  1129. tbTo.time = mktime(&tmTo);
  1130. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1131. {
  1132. if(defaultTxProfile.ChargingProfileId == -1)
  1133. DEBUG_INFO("TxDefaultProfile found.\n");
  1134. else
  1135. DEBUG_INFO("TxDefaultProfile updated.\n");
  1136. // Required item
  1137. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1138. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1139. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1140. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1141. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1142. {
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1144. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1145. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1146. 3:
  1147. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1148. }
  1149. // Optional item
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1151. {
  1152. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1159. {
  1160. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1161. }
  1162. else
  1163. {
  1164. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1165. }
  1166. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1167. {
  1168. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1173. }
  1174. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1175. {
  1176. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1177. }
  1178. else
  1179. {
  1180. defaultTxProfile.TransactionId = -1;
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1183. {
  1184. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1185. }
  1186. else
  1187. {
  1188. defaultTxProfile.ChargingSchedule.Duration = -1;
  1189. }
  1190. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1191. {
  1192. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1193. }
  1194. else
  1195. {
  1196. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1197. }
  1198. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1199. {
  1200. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1201. }
  1202. else
  1203. {
  1204. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(defaultTxProfile.ChargingProfileId == -1)
  1212. DEBUG_INFO("TxDefaultProfile found.\n");
  1213. else
  1214. DEBUG_INFO("TxDefaultProfile updated.\n");
  1215. // Required item
  1216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1219. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1220. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1221. {
  1222. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1223. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1224. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1225. 3:
  1226. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1227. }
  1228. // Optional item
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1230. {
  1231. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1232. }
  1233. else
  1234. {
  1235. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1236. }
  1237. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1238. {
  1239. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1240. }
  1241. else
  1242. {
  1243. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1244. }
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1246. {
  1247. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1254. {
  1255. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.TransactionId = -1;
  1260. }
  1261. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1262. {
  1263. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1264. }
  1265. else
  1266. {
  1267. defaultTxProfile.ChargingSchedule.Duration = -1;
  1268. }
  1269. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1270. {
  1271. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. json_object_put(obj);
  1289. }
  1290. fclose(fp);
  1291. /*
  1292. if(defaultTxProfile.ChargingProfileId != -1)
  1293. {
  1294. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1295. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1296. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1297. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1298. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1299. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1300. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1301. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1302. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1303. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1304. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1308. {
  1309. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1310. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1311. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1312. }
  1313. }
  1314. }
  1315. else
  1316. DEBUG_INFO("TxDefaultProfile not found.\n");
  1317. DEBUG_INFO("------------------------------------\n");*/
  1318. }
  1319. // Search tx profile
  1320. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1321. if((access(profileFileName, F_OK))!=-1)
  1322. {
  1323. fp = fopen(profileFileName, "r");
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1327. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1329. }
  1330. txProfile.ChargingProfileId = -1;
  1331. txProfile.StackLevel = -1;
  1332. while(getline(&line, &len, fp) != -1)
  1333. {
  1334. json_object *obj = NULL;
  1335. obj = json_tokener_parse(line);
  1336. if(is_error(obj))
  1337. {
  1338. DEBUG_ERROR("Parse txProfile from file error.\n");
  1339. }
  1340. else
  1341. {
  1342. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1343. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1344. )
  1345. {
  1346. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1347. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. )
  1349. {
  1350. struct tm tmFrom, tmTo;
  1351. struct timeb tbFrom, tbTo;
  1352. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1353. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1354. {
  1355. tmFrom.tm_year -= 1900;
  1356. tmFrom.tm_mon -= 1;
  1357. tbFrom.time = mktime(&tmFrom);
  1358. tmTo.tm_year -= 1900;
  1359. tmTo.tm_mon -= 1;
  1360. tbTo.time = mktime(&tmTo);
  1361. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1362. {
  1363. if(txProfile.ChargingProfileId == -1)
  1364. DEBUG_INFO("TxProfile found.\n");
  1365. else
  1366. DEBUG_INFO("TxProfile updated.\n");
  1367. // Required item
  1368. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1369. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1370. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1371. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1372. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1373. {
  1374. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1375. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1376. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1377. 3:
  1378. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1379. }
  1380. // Optional item
  1381. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1382. {
  1383. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1384. }
  1385. else
  1386. {
  1387. sprintf((char*)txProfile.ValidFrom, " ");
  1388. }
  1389. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1390. {
  1391. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1392. }
  1393. else
  1394. {
  1395. sprintf((char*)txProfile.ValidTo, " ");
  1396. }
  1397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1398. {
  1399. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1400. }
  1401. else
  1402. {
  1403. sprintf((char*)txProfile.RecurrencyKind, " ");
  1404. }
  1405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1406. {
  1407. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1408. }
  1409. else
  1410. {
  1411. txProfile.TransactionId = -1;
  1412. }
  1413. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1414. {
  1415. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1416. }
  1417. else
  1418. {
  1419. txProfile.ChargingSchedule.Duration = -1;
  1420. }
  1421. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1422. {
  1423. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1428. }
  1429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1430. {
  1431. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1432. }
  1433. else
  1434. {
  1435. txProfile.ChargingSchedule.MinChargingRate = -1;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if(txProfile.ChargingProfileId == -1)
  1443. DEBUG_INFO("TxProfile found.\n");
  1444. else
  1445. DEBUG_INFO("TxProfile updated.\n");
  1446. // Required item
  1447. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1448. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1449. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1450. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1451. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1452. {
  1453. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1455. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1456. 3:
  1457. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1458. }
  1459. // Optional item
  1460. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1461. {
  1462. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)txProfile.ValidFrom, " ");
  1467. }
  1468. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1469. {
  1470. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1471. }
  1472. else
  1473. {
  1474. sprintf((char*)txProfile.ValidTo, " ");
  1475. }
  1476. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1477. {
  1478. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)txProfile.RecurrencyKind, " ");
  1483. }
  1484. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1485. {
  1486. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1487. }
  1488. else
  1489. {
  1490. txProfile.TransactionId = -1;
  1491. }
  1492. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1493. {
  1494. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1495. }
  1496. else
  1497. {
  1498. txProfile.ChargingSchedule.Duration = -1;
  1499. }
  1500. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1501. {
  1502. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1509. {
  1510. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1511. }
  1512. else
  1513. {
  1514. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. json_object_put(obj);
  1520. }
  1521. fclose(fp);
  1522. /*
  1523. if(defaultTxProfile.ChargingProfileId != -1)
  1524. {
  1525. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1526. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1527. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1528. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1529. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1530. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1531. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1532. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1533. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1534. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1535. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1537. {
  1538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1539. {
  1540. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1541. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1542. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1543. }
  1544. }
  1545. }
  1546. else
  1547. DEBUG_INFO("TxProfile not found.\n");*/
  1548. }
  1549. /*
  1550. * Align found profile start schedule & periods
  1551. */
  1552. //DEBUG_INFO("====================================\n");
  1553. /*
  1554. // For local test usage, force modify found profile start schedule info
  1555. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1556. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1557. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1558. */
  1559. if(maxProfile.ChargingProfileId != -1)
  1560. {
  1561. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1562. {
  1563. if(maxProfile.ChargingSchedule.Duration != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1568. }
  1569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1574. 0:
  1575. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1576. }
  1577. }
  1578. }
  1579. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1600. {
  1601. if(maxProfile.ChargingSchedule.Duration != -1)
  1602. {
  1603. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1604. 0:
  1605. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1606. }
  1607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1608. {
  1609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1610. {
  1611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. }
  1616. }
  1617. else
  1618. {
  1619. if(maxProfile.ChargingSchedule.Duration != -1)
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1622. 0:
  1623. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1624. }
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1628. {
  1629. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1630. 0:
  1631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1632. }
  1633. }
  1634. }
  1635. }
  1636. /*
  1637. DEBUG_INFO("MaxProfile after align.\n");
  1638. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1639. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1640. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1641. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1642. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1643. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1644. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1645. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1646. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1647. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1648. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1650. {
  1651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1652. {
  1653. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1654. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1655. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1656. }
  1657. }
  1658. DEBUG_INFO("------------------------------------\n");*/
  1659. }
  1660. if(defaultTxProfile.ChargingProfileId != -1)
  1661. {
  1662. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1663. {
  1664. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1665. {
  1666. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1667. 0:
  1668. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1669. }
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1673. {
  1674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1675. 0:
  1676. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1677. }
  1678. }
  1679. }
  1680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1681. {
  1682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1683. {
  1684. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1685. 0:
  1686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1687. }
  1688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1689. {
  1690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1691. {
  1692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1693. 0:
  1694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1701. {
  1702. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1703. {
  1704. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1705. 0:
  1706. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1707. }
  1708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1711. {
  1712. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1733. }
  1734. }
  1735. }
  1736. }
  1737. /*
  1738. DEBUG_INFO("defaultTxProfile after align.\n");
  1739. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1740. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1741. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1742. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1743. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1744. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1745. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1746. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1747. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1748. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1749. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1753. {
  1754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1757. }
  1758. }
  1759. DEBUG_INFO("------------------------------------\n");*/
  1760. }
  1761. if(txProfile.ChargingProfileId != -1)
  1762. {
  1763. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1764. {
  1765. if(txProfile.ChargingSchedule.Duration != -1)
  1766. {
  1767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1768. 0:
  1769. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1770. }
  1771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1772. {
  1773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1774. {
  1775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1776. 0:
  1777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1778. }
  1779. }
  1780. }
  1781. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1782. {
  1783. if(txProfile.ChargingSchedule.Duration != -1)
  1784. {
  1785. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1786. 0:
  1787. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1788. }
  1789. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1790. {
  1791. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1794. 0:
  1795. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1796. }
  1797. }
  1798. }
  1799. else
  1800. {
  1801. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1802. {
  1803. if(txProfile.ChargingSchedule.Duration != -1)
  1804. {
  1805. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1808. }
  1809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1814. 0:
  1815. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1834. }
  1835. }
  1836. }
  1837. }
  1838. /*
  1839. DEBUG_INFO("txProfile after align.\n");
  1840. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1841. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1842. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1843. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1844. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1845. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1846. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1847. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1848. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1849. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1850. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1856. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1857. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1858. }
  1859. }*/
  1860. }
  1861. /*
  1862. * Merge to conposite schedule
  1863. */
  1864. //DEBUG_INFO("====================================\n");
  1865. // Find each profile period quantity
  1866. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1867. {
  1868. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1869. limitMax = idx+1;
  1870. }
  1871. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1872. {
  1873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1874. limitDef = idx+1;
  1875. }
  1876. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1877. {
  1878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1879. limitTx = idx+1;
  1880. }
  1881. // TxProfile found, composite schedule based on it
  1882. if(txProfile.ChargingProfileId != -1)
  1883. {
  1884. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1885. {
  1886. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1887. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1888. {
  1889. if(maxProfile.ChargingProfileId != -1)
  1890. {
  1891. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1892. {
  1893. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1894. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1895. {
  1896. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1897. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1898. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1899. }
  1900. if(idxMaxPeriod == (limitMax-1))
  1901. {
  1902. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1903. {
  1904. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1905. {
  1906. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1907. compositePeriodIdx++;
  1908. }
  1909. else
  1910. {
  1911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. compositePeriodIdx++;
  1923. }
  1924. else
  1925. {
  1926. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1927. }
  1928. }
  1929. }
  1930. if(idxTxPeriod == (limitTx-1))
  1931. {
  1932. if(defaultTxProfile.ChargingProfileId != -1)
  1933. {
  1934. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1935. {
  1936. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1937. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1938. {
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1942. {
  1943. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1944. {
  1945. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1946. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1947. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1949. {
  1950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1951. {
  1952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1953. compositePeriodIdx++;
  1954. }
  1955. else
  1956. {
  1957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1958. }
  1959. }
  1960. break;
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1967. {
  1968. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1969. compositePeriodIdx++;
  1970. }
  1971. else
  1972. {
  1973. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1983. else if(defaultTxProfile.ChargingProfileId != -1)
  1984. {
  1985. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1986. {
  1987. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1988. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1989. {
  1990. if(maxProfile.ChargingProfileId != -1)
  1991. {
  1992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1995. {
  1996. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1997. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1998. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1999. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2000. {
  2001. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2002. {
  2003. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2004. compositePeriodIdx++;
  2005. }
  2006. else
  2007. {
  2008. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2009. }
  2010. }
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. else
  2016. {
  2017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2018. {
  2019. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2020. compositePeriodIdx++;
  2021. }
  2022. else
  2023. {
  2024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. // Fill other period by MaxProfile
  2031. if(maxProfile.ChargingProfileId != -1)
  2032. {
  2033. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2034. {
  2035. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2036. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2037. {
  2038. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2039. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2040. {
  2041. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2042. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2043. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2044. }
  2045. if(idxMaxPeriod == (limitMax-1))
  2046. {
  2047. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2048. {
  2049. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2050. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2051. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2052. }
  2053. if(tmpPeriod.Limit != -1)
  2054. {
  2055. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2056. {
  2057. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2058. {
  2059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2060. compositePeriodIdx++;
  2061. }
  2062. else
  2063. {
  2064. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2073. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2074. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2078. {
  2079. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2080. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2081. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2082. }
  2083. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2084. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2085. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2086. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2087. }
  2088. if(line)
  2089. free(line);
  2090. }
  2091. //==========================================
  2092. // Init all share memory
  2093. //==========================================
  2094. int InitShareMemory()
  2095. {
  2096. int result = PASS;
  2097. int MeterSMId;
  2098. //creat ShmSysConfigAndInfo
  2099. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2100. {
  2101. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2102. result = FAIL;
  2103. }
  2104. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2105. {
  2106. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2107. result = FAIL;
  2108. }
  2109. else
  2110. {}
  2111. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2112. {
  2113. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2114. result = FAIL;
  2115. }
  2116. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2117. {
  2118. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2119. result = FAIL;
  2120. }
  2121. else
  2122. {}
  2123. //creat ShmPsuData
  2124. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2125. {
  2126. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2127. result = FAIL;
  2128. }
  2129. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2130. {
  2131. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2132. result = FAIL;
  2133. }
  2134. else
  2135. {}
  2136. //creat ShmOCPP16Data
  2137. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2138. {
  2139. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2140. result = FAIL;
  2141. }
  2142. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2143. {
  2144. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2145. result = FAIL;
  2146. }
  2147. else
  2148. {}
  2149. /****************************** For Initial Settings************************************************/
  2150. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2151. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2152. // allocate Configuration memory address
  2153. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2154. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2155. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2156. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2157. //offline MeterValue Interval
  2158. TempMeterValueInterval = 0;
  2159. return result;
  2160. }
  2161. int ProcessShareMemory()
  2162. {
  2163. if(InitShareMemory() == FAIL)
  2164. {
  2165. DEBUG_ERROR("InitShareMemory NG\n");
  2166. if(ShmStatusCodeData!=NULL)
  2167. {
  2168. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2169. }
  2170. sleep(5);
  2171. return FAIL;
  2172. }
  2173. return PASS;
  2174. }
  2175. //---------------------common routine---------------------------//
  2176. int isOFFline(void)
  2177. {
  2178. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2179. {
  2180. if(TempMeterValueInterval >= 2 )
  2181. {
  2182. TempMeterValueInterval = 0;
  2183. return TRUE;
  2184. }
  2185. else
  2186. {
  2187. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2188. return FALSE;
  2189. }
  2190. }
  2191. else
  2192. {
  2193. return FALSE;
  2194. }
  2195. }
  2196. //---------------------------------------------
  2197. // new:
  2198. // enum SYSTEM_STATUS
  2199. // {
  2200. // SYS_MODE_BOOTING = 0,
  2201. // SYS_MODE_IDLE = 1,
  2202. // SYS_MODE_AUTHORIZING = 2,
  2203. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2204. // SYS_MODE_REASSIGN = 4,
  2205. // SYS_MODE_PREPARING = 5,
  2206. // SYS_MODE_PREPARE_FOR_EV = 6,
  2207. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2208. // SYS_MODE_CHARGING = 8,
  2209. // SYS_MODE_TERMINATING = 9,
  2210. // SYS_MODE_COMPLETE = 10,
  2211. // SYS_MODE_ALARM = 11,
  2212. // SYS_MODE_FAULT = 12,
  2213. // SYS_MODE_RESERVATION = 13,
  2214. // SYS_MODE_BOOKING = 14,
  2215. // SYS_MODE_MAINTAIN = 15,
  2216. // SYS_MODE_DEBUG = 16,
  2217. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2218. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2219. // SYS_MODE_UPDATE = 19
  2220. // };
  2221. //
  2222. //
  2223. //-----------------------------------------
  2224. void CheckSystemValue(void)
  2225. {
  2226. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2227. //int IdleModeCnt = 0;
  2228. char filenmae[100]={0};
  2229. char str[100]={0};
  2230. //===============================
  2231. // send Heartbeat
  2232. //===============================
  2233. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2234. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2235. {
  2236. clientTime.Heartbeat=time((time_t*)NULL);
  2237. if(server_sign == TRUE)
  2238. {
  2239. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2240. }
  2241. else
  2242. {
  2243. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2244. }
  2245. }
  2246. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2247. {
  2248. //parameter for test
  2249. sendHeartbeatRequest(0);
  2250. //==============================================
  2251. // Reset Waiting Time
  2252. //==============================================
  2253. clientTime.Heartbeat=time((time_t*)NULL);
  2254. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2255. }
  2256. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2257. {
  2258. //===============================
  2259. // CSU Trigger Reset Conf
  2260. //===============================
  2261. if((server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2262. {
  2263. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2264. }
  2265. //===============================
  2266. // CSU Trigger Authorize Request
  2267. //===============================
  2268. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2269. {
  2270. sendAuthorizeRequest(0);
  2271. authorizeRetryTimes = authorizeRetryTimes + 1;
  2272. if(authorizeRetryTimes < 3)
  2273. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2274. }
  2275. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  2276. {
  2277. authorizeRetryTimes = 0;
  2278. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2279. server_sign = FALSE;
  2280. }
  2281. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2282. {
  2283. sendAuthorizeRequest(0);
  2284. }
  2285. //===============================
  2286. // CSU Trigger Smart Charging Profilw
  2287. //===============================
  2288. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2289. {
  2290. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2291. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2292. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2293. }
  2294. //==============================================
  2295. // Charger start transaction
  2296. //==============================================
  2297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2298. {
  2299. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2300. sendStartTransactionRequest(gun_index);
  2301. clientTime.StartTransaction = time((time_t*)NULL);
  2302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2303. }
  2304. //==============================================
  2305. // Charger stop transaction
  2306. //==============================================
  2307. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2308. {
  2309. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2310. sendStopTransactionRequest(gun_index);
  2311. clientTime.StopTransaction = time((time_t*)NULL);
  2312. }
  2313. //==============================================
  2314. // Charger status report
  2315. //==============================================
  2316. //--- Check Mode Change ---//
  2317. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2318. if(gunType[gun_index] == 'J')
  2319. {
  2320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2321. {
  2322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2323. {
  2324. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2325. {
  2326. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2327. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2328. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2329. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2330. statusModeChage[gun_index] = TRUE;
  2331. }
  2332. #if 1 // for TempStopTransaction
  2333. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2334. {
  2335. checkTempStopTransaction(gun_index);
  2336. }
  2337. #endif
  2338. }
  2339. }
  2340. }
  2341. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2342. {
  2343. for (int index = 0; index < CCS_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2346. {
  2347. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2348. {
  2349. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2350. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2351. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2353. statusModeChage[gun_index] = TRUE;
  2354. }
  2355. #if 1 // for TempStopTransaction
  2356. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2357. {
  2358. checkTempStopTransaction(gun_index);
  2359. }
  2360. #endif
  2361. }
  2362. }
  2363. }
  2364. else if(gunType[gun_index] == 'G')
  2365. {
  2366. for (int index = 0; index < GB_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2369. {
  2370. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2371. {
  2372. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2373. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2374. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. #if 1 // for TempStopTransaction
  2379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2380. {
  2381. checkTempStopTransaction(gun_index);
  2382. }
  2383. #endif
  2384. }
  2385. }
  2386. }
  2387. else
  2388. {
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2392. {
  2393. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2394. {
  2395. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2396. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2397. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2398. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2399. statusModeChage[gun_index] = TRUE;
  2400. }
  2401. #if 1 // for TempStopTransaction
  2402. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2403. {
  2404. checkTempStopTransaction(gun_index);
  2405. }
  2406. #endif
  2407. }
  2408. }// END
  2409. }
  2410. if(((server_sign == TRUE) && (SystemInitial > 0)) ||
  2411. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2412. {
  2413. if(SystemInitial > 0)
  2414. SystemInitial = SystemInitial -1;
  2415. sendStatusNotificationRequest(gun_index);
  2416. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2417. statusModeChage[gun_index] = FALSE;
  2418. }
  2419. //==============================================
  2420. // Meter report
  2421. //==============================================
  2422. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  2423. {
  2424. //check Transaction active
  2425. if(gunType[gun_index] == 'J')
  2426. {
  2427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2428. {
  2429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2430. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2431. {
  2432. meterValueSend[gun_index] =1;
  2433. }
  2434. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2435. {
  2436. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2437. if((access(filenmae,F_OK))!=-1)
  2438. {
  2439. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2440. sprintf(str,"rm -f %s",filenmae);
  2441. system(str);
  2442. }
  2443. }
  2444. }// End for CHAdeMO
  2445. }
  2446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2447. {
  2448. for (int index = 0; index < CCS_QUANTITY; index++)
  2449. {
  2450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2451. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2452. {
  2453. meterValueSend[gun_index] =1;
  2454. }
  2455. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2456. {
  2457. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2458. if((access(filenmae,F_OK))!=-1)
  2459. {
  2460. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2461. sprintf(str,"rm -f %s",filenmae);
  2462. system(str);
  2463. }
  2464. }
  2465. } // End for CCS
  2466. }
  2467. else if(gunType[gun_index] == 'G')
  2468. {
  2469. for (int index = 0; index < GB_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2473. {
  2474. meterValueSend[gun_index] =1;
  2475. }
  2476. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2477. {
  2478. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2479. if((access(filenmae,F_OK))!=-1)
  2480. {
  2481. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2482. sprintf(str,"rm -f %s",filenmae);
  2483. system(str);
  2484. }
  2485. }
  2486. }// End for GB
  2487. }
  2488. else
  2489. {
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2493. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2494. {
  2495. meterValueSend[gun_index] =1;
  2496. }
  2497. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2498. {
  2499. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2500. if((access(filenmae,F_OK))!=-1)
  2501. {
  2502. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2503. sprintf(str,"rm -f %s",filenmae);
  2504. system(str);
  2505. }
  2506. }
  2507. }//End for AC
  2508. }
  2509. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2510. if(meterValueSend[gun_index] == 1)
  2511. {
  2512. sendMeterValuesRequest(gun_index);
  2513. #if 1 // for TempStopTransaction
  2514. storeTempStopTransaction(gun_index);
  2515. #endif
  2516. }
  2517. }
  2518. //==============================================
  2519. // Check Connector reserved
  2520. //==============================================
  2521. //===============================
  2522. // Check if Reserve is expired
  2523. //===============================
  2524. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2525. {
  2526. double diff_t;
  2527. struct tm tp;
  2528. // current time
  2529. time_t t = time(NULL);
  2530. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2531. tp.tm_isdst = -1;
  2532. time_t utc = mktime(&tp);
  2533. diff_t = difftime(utc, t);
  2534. if(diff_t <= 0)
  2535. {
  2536. DEBUG_INFO("reserve expired.\n");
  2537. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2538. }
  2539. }//END OF Check if Reserve is expired
  2540. //==========================================
  2541. // csu trigger FirmwareStatusNotificationReq
  2542. //==========================================
  2543. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2544. {
  2545. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2546. }
  2547. //==========================================
  2548. // csu trigger CancelReservationConf
  2549. //==========================================
  2550. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2551. {
  2552. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2553. }
  2554. //==========================================
  2555. // csu trigger ChangeAvailabilityConf
  2556. //==========================================
  2557. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2558. {
  2559. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2560. }
  2561. //==========================================
  2562. // csu trigger UnlockConnectorConf
  2563. //==========================================
  2564. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2565. {
  2566. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2567. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2568. }
  2569. //==========================================
  2570. // csu trigger ReserveNowConf
  2571. //==========================================
  2572. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2573. {
  2574. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2575. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2576. }
  2577. //==========================================
  2578. // csu trigger DataTransferReq
  2579. //==========================================
  2580. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2581. {
  2582. sendDataTransferRequest(gun_index);
  2583. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2584. }
  2585. }
  2586. }
  2587. //==========================================
  2588. // send request routine
  2589. //==========================================
  2590. int sendAuthorizeRequest(int gun_index)
  2591. {
  2592. mtrace();
  2593. int result = FAIL;
  2594. char message[100]={0};
  2595. char guid[37];
  2596. char tempdata[65]={0};
  2597. DEBUG_INFO("sendAuthorizeRequest...\n");
  2598. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2599. //Local Authorize
  2600. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2601. {
  2602. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2604. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2605. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2606. result = PASS;
  2607. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2608. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2609. authorizeRetryTimes = 0;
  2610. return result;
  2611. }
  2612. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  2613. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2614. {
  2615. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2616. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2617. {
  2618. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2619. {
  2620. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2621. }
  2622. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2623. {
  2624. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2625. }
  2626. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2627. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2628. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2629. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2630. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2631. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2632. authorizeRetryTimes = 0;
  2633. return result;
  2634. }
  2635. else
  2636. {
  2637. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2641. result = PASS;
  2642. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2644. authorizeRetryTimes = 0;
  2645. return result;
  2646. }
  2647. }
  2648. //initailize struct Authorize
  2649. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2650. //get data from shared memory
  2651. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2652. random_uuid(guid);
  2653. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2654. LWS_Send(message);
  2655. sprintf(tempdata, "Authorize,%d", gun_index);
  2656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2657. {
  2658. result = PASS;
  2659. DEBUG_INFO("Authorize mapItem pass\n");
  2660. }
  2661. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2662. return result;
  2663. }
  2664. int sendBootNotificationRequest(void)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[500]={0}, payload[700]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. int IsGunCharging = FALSE;
  2672. //check Transaction active
  2673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2676. {
  2677. IsGunCharging = TRUE;
  2678. }
  2679. }
  2680. for (int index = 0; index < CCS_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2683. {
  2684. IsGunCharging = TRUE;
  2685. }
  2686. }
  2687. for (int index = 0; index < GB_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2690. {
  2691. IsGunCharging = TRUE;
  2692. }
  2693. }
  2694. for (int index = 0; index < AC_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2697. {
  2698. IsGunCharging = TRUE;
  2699. }
  2700. }
  2701. if(IsGunCharging == TRUE)
  2702. {
  2703. server_sign = TRUE;
  2704. return result;
  2705. }
  2706. // Fill BootNotification fields
  2707. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2708. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2709. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2710. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2711. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2712. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2713. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2714. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2715. ShmOCPP16Data->ChargeBoxId
  2716. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2717. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2718. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2719. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2720. ,ShmOCPP16Data->BootNotification.CpIccid
  2721. ,ShmOCPP16Data->BootNotification.CpImsi);
  2722. random_uuid(guid);
  2723. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2724. LWS_Send(message);
  2725. sprintf(tempdata, "BootNotification,0");
  2726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2727. {
  2728. result = PASS;
  2729. }
  2730. memset(queuedata, 0, sizeof(queuedata));
  2731. strcpy(queuedata,message);
  2732. return result;
  2733. }
  2734. int sendDataTransferRequest(int gun_index)
  2735. {
  2736. mtrace();
  2737. char message[1000]={0};
  2738. char guid[37]={0};
  2739. char tempdata[65]={0};
  2740. int result = FAIL;
  2741. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2742. random_uuid(guid);
  2743. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2744. MESSAGE_TYPE_CALL,
  2745. guid,
  2746. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2747. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2748. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2749. LWS_Send(message);
  2750. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2751. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2752. {
  2753. result = PASS;
  2754. DEBUG_INFO("DataTransfer mapItem pass\n");
  2755. }
  2756. return result;
  2757. }
  2758. int sendFirmwareVersionByDataTransfer(void)
  2759. {
  2760. int8_t result = FAIL;
  2761. json_object *FirmwareDataTransfer = json_object_new_object();
  2762. // AC & DC model
  2763. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  2764. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  2765. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  2766. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  2767. // DC model
  2768. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  2769. {
  2770. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  2771. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  2772. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  2773. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  2774. }
  2775. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  2776. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  2777. {
  2778. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  2779. }
  2780. // 4G model
  2781. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  2782. {
  2783. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  2784. }
  2785. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  2786. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  2787. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  2788. if(sendDataTransferRequest(0))
  2789. {
  2790. result = PASS;
  2791. }
  2792. return result;
  2793. }
  2794. int sendDiagnosticsStatusNotificationRequest(char *status)
  2795. {
  2796. mtrace();
  2797. int result = FAIL;
  2798. char message[110]={0};
  2799. char guid[37]={0};
  2800. char tempdata[65]={0};
  2801. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2802. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2803. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2804. random_uuid(guid);
  2805. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2806. LWS_Send(message);
  2807. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2808. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2809. {
  2810. result = PASS;
  2811. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2812. }
  2813. //#ifdef SystemLogMessage
  2814. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2816. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2817. //#endif
  2818. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2819. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2820. //record status
  2821. if(strcmp(status,"Idle")==0)
  2822. {
  2823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2824. }
  2825. else if(strcmp(status,"Uploaded")==0)
  2826. {
  2827. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2828. }
  2829. else if(strcmp(status,"UploadFailed")==0)
  2830. {
  2831. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2832. }
  2833. else if(strcmp(status,"Uploading")==0)
  2834. {
  2835. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2836. }
  2837. return result;
  2838. }
  2839. int sendFirmwareStatusNotificationRequest(char *status)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[110]={0};
  2844. char guid[37]={0};
  2845. char tempdata[65]={0};
  2846. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2847. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2848. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2849. random_uuid(guid);
  2850. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2851. LWS_Send(message);
  2852. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2853. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2854. {
  2855. result = PASS;
  2856. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2857. }
  2858. //#ifdef SystemLogMessage
  2859. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2860. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2861. //#endif
  2862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2864. //record status
  2865. if(strcmp(status,"Downloaded")==0)
  2866. {
  2867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2868. }
  2869. else if(strcmp(status,"DownloadFailed")==0)
  2870. {
  2871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2872. }
  2873. else if(strcmp(status,"Downloading")==0)
  2874. {
  2875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2876. }
  2877. else if(strcmp(status,"Idle")==0)
  2878. {
  2879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2880. }
  2881. else if(strcmp(status,"InstallationFailed")==0)
  2882. {
  2883. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2884. }
  2885. else if(strcmp(status,"Installing")==0)
  2886. {
  2887. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2888. }
  2889. else if(strcmp(status,"Installed")==0)
  2890. {
  2891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2892. }
  2893. return result;
  2894. }
  2895. int sendHeartbeatRequest(int gun_index)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[80]={0};
  2900. char guid[37]={0};
  2901. char tempdata[65]={0};
  2902. random_uuid(guid);
  2903. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2904. , MESSAGE_TYPE_CALL
  2905. , guid );
  2906. LWS_Send(message);
  2907. sprintf(tempdata, "Heartbeat,%d", 0);
  2908. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2909. {
  2910. result = PASS;
  2911. }
  2912. return result;
  2913. }
  2914. int sendStartTransactionRequest(int gun_index)
  2915. {
  2916. mtrace();
  2917. int result = FAIL;
  2918. char message[250]={0};
  2919. char guid[37]={0};
  2920. struct timeval tmnow;
  2921. struct tm *tm;
  2922. char buf[28];//, usec_buf[6];
  2923. char tempdata[65]={0};
  2924. int tempIndex = 0;
  2925. DEBUG_INFO("sendStartTransactionRequest...\n");
  2926. gettimeofday(&tmnow, NULL);
  2927. time_t t;
  2928. t = time(NULL);
  2929. /*UTC time and date*/
  2930. tm = gmtime(&t);
  2931. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2932. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2933. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2934. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2935. // clear StartTransaction Response
  2936. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2937. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2938. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2939. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2940. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2941. if(gunType[gun_index] == 'J')
  2942. {
  2943. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2944. {
  2945. tempIndex = ((gun_index==2) ? 1: 0);
  2946. }
  2947. else
  2948. {
  2949. tempIndex = gun_index;
  2950. }
  2951. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2952. {
  2953. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2954. {
  2955. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2956. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2957. }
  2958. }
  2959. }
  2960. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2961. {
  2962. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2963. {
  2964. tempIndex = ((gun_index==2) ? 1: 0);
  2965. }
  2966. else
  2967. {
  2968. tempIndex = gun_index;
  2969. }
  2970. for (int index = 0; index < CCS_QUANTITY; index++)
  2971. {
  2972. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2973. {
  2974. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2975. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2976. }
  2977. }
  2978. }
  2979. else if(gunType[gun_index] == 'G')
  2980. {
  2981. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2982. {
  2983. tempIndex = ((gun_index==2) ? 1: 0);
  2984. }
  2985. else
  2986. {
  2987. tempIndex = gun_index;
  2988. }
  2989. for (int index = 0; index < GB_QUANTITY; index++)
  2990. {
  2991. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2992. {
  2993. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  2994. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2995. }
  2996. }
  2997. }
  2998. else
  2999. {
  3000. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3001. {
  3002. tempIndex = 2;
  3003. }
  3004. else
  3005. {
  3006. tempIndex = gun_index;
  3007. }
  3008. for (int index = 0; index < AC_QUANTITY; index++)
  3009. {
  3010. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3011. {
  3012. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3013. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3014. }
  3015. }
  3016. }
  3017. random_uuid(guid);
  3018. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1)
  3019. {
  3020. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3021. , MESSAGE_TYPE_CALL
  3022. , guid
  3023. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3024. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3025. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3026. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3027. }
  3028. else
  3029. {
  3030. sprintf(message, "[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3031. , MESSAGE_TYPE_CALL
  3032. , guid
  3033. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3034. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3035. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3036. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3037. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3038. }
  3039. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3040. 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*/)
  3041. {
  3042. result = PASS;
  3043. }
  3044. strcpy(queuedata, message);
  3045. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3046. if(GetTransactionQueueNum() == 1)
  3047. {
  3048. LWS_Send(message);
  3049. }
  3050. return result;
  3051. }
  3052. int sendStatusNotificationRequest(int gun_index)
  3053. {
  3054. mtrace();
  3055. int result = FAIL;
  3056. char message[600]={0};
  3057. char guid[37];
  3058. int currentStatus = 0;
  3059. struct timeval tmnow;
  3060. struct tm *tm;
  3061. char buf[28];//, usec_buf[6];
  3062. char tempdata[65]={0};
  3063. int tempIndex = 0;
  3064. gettimeofday(&tmnow, NULL);
  3065. time_t t;
  3066. t = time(NULL);
  3067. /*UTC time and date*/
  3068. tm = gmtime(&t);
  3069. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3070. printf("%s",buf);
  3071. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3072. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3073. // it's option
  3074. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3075. /*
  3076. enum _SYSTEM_STATUS
  3077. {
  3078. S_BOOTING = 0,
  3079. S_IDLE, = 1
  3080. S_AUTHORIZING, =2
  3081. S_REASSIGN_CHECK, =3
  3082. S_REASSIGN, =4
  3083. S_PRECHARGE, =5
  3084. S_PREPARING_FOR_EV, =6
  3085. S_PREPARING_FOR_EVSE, =7
  3086. S_CHARGING, =8
  3087. S_TERMINATING, =9
  3088. S_COMPLETE, =10
  3089. S_ALARM, =11
  3090. S_FAULT =12
  3091. }
  3092. */
  3093. //check Transaction active
  3094. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3095. if(gunType[gun_index] == 'J')
  3096. {
  3097. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3098. {
  3099. tempIndex = ((gun_index==2) ? 1: 0);
  3100. }
  3101. else
  3102. {
  3103. tempIndex = gun_index;
  3104. }
  3105. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3106. {
  3107. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3108. {
  3109. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3110. {
  3111. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3112. {
  3113. currentStatus = 1; //OCPP Status: Preparing
  3114. }
  3115. else
  3116. {
  3117. currentStatus = 0; //OCPP Status: Available
  3118. }
  3119. }
  3120. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3121. {
  3122. currentStatus = 1; //OCPP Status: Preparing
  3123. }
  3124. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3125. {
  3126. currentStatus = 2; //OCPP Status: Charging
  3127. }
  3128. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3129. {
  3130. currentStatus = 5; //OCPP Status: Finishing
  3131. }
  3132. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3133. {
  3134. currentStatus = 4; //OCPP Status: SuspendedEV
  3135. }
  3136. 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
  3137. {
  3138. currentStatus = 7; //OCPP Status: Unavailable
  3139. }
  3140. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3141. {
  3142. currentStatus = 8; //OCPP Status: Faulted
  3143. }
  3144. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3145. {
  3146. currentStatus = 6; //OCPP Status: Reserved
  3147. }
  3148. } //end of the same index
  3149. }//end of for CHAdeMO_QUANTITY
  3150. }
  3151. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3152. {
  3153. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3154. {
  3155. tempIndex = ((gun_index==2) ? 1: 0);
  3156. }
  3157. else
  3158. {
  3159. tempIndex = gun_index;
  3160. }
  3161. for (int index = 0; index < CCS_QUANTITY; index++)
  3162. {
  3163. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3164. {
  3165. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3166. {
  3167. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3168. {
  3169. currentStatus = 1; //OCPP Status: Preparing
  3170. }
  3171. else
  3172. {
  3173. currentStatus = 0; //OCPP Status: Available
  3174. }
  3175. }
  3176. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3177. {
  3178. currentStatus = 1; //OCPP Status: Preparing
  3179. }
  3180. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3181. {
  3182. currentStatus = 2; //OCPP Status: Charging
  3183. }
  3184. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3185. {
  3186. currentStatus = 5; //OCPP Status: Finishing
  3187. }
  3188. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3189. {
  3190. currentStatus = 4; //OCPP Status: SuspendedEV
  3191. }
  3192. 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
  3193. {
  3194. currentStatus = 7; //OCPP Status : Unavailable
  3195. }
  3196. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3197. {
  3198. currentStatus = 8; //OCPP Status: Faulted
  3199. }
  3200. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3201. {
  3202. currentStatus = 6; //OCPP Status: Reserved
  3203. }
  3204. } //end of the same index
  3205. } // end of for CCS_QUANTITY
  3206. }
  3207. else if(gunType[gun_index] == 'G')
  3208. {
  3209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3210. {
  3211. tempIndex = ((gun_index==2) ? 1: 0);
  3212. }
  3213. else
  3214. {
  3215. tempIndex = gun_index;
  3216. }
  3217. for (int index = 0; index < GB_QUANTITY; index++)
  3218. {
  3219. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3220. {
  3221. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3222. {
  3223. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3224. {
  3225. currentStatus = 1; //OCPP Status: Preparing
  3226. }
  3227. else
  3228. {
  3229. currentStatus = 0; //OCPP Status: Available
  3230. }
  3231. }
  3232. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //S_PRECHARGE
  3233. {
  3234. currentStatus = 1; //OCPP Status: Preparing
  3235. }
  3236. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3237. {
  3238. currentStatus = 2; //OCPP Status: Charging
  3239. }
  3240. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3241. {
  3242. currentStatus = 5; //OCPP Status: Finishing
  3243. }
  3244. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3245. {
  3246. currentStatus = 4; //OCPP Status: SuspendedEV
  3247. }
  3248. 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
  3249. {
  3250. currentStatus = 7; //OCPP Status: Unavailable
  3251. }
  3252. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3253. {
  3254. currentStatus = 8; //OCPP Status: Faulted
  3255. }
  3256. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3257. {
  3258. currentStatus = 6; //OCPP Status: Reserved
  3259. }
  3260. } //end of the same index
  3261. } // end of for GB_QUANTITY
  3262. }
  3263. else
  3264. {
  3265. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3266. {
  3267. tempIndex = 2;
  3268. }
  3269. else
  3270. {
  3271. tempIndex = gun_index;
  3272. }
  3273. for (int index = 0; index < AC_QUANTITY; index++)
  3274. {
  3275. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3276. {
  3277. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3278. {
  3279. 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))
  3280. {
  3281. currentStatus = 1; //OCPP Status: Preparing
  3282. }
  3283. else
  3284. {
  3285. currentStatus = 0; //OCPP Status: Available
  3286. }
  3287. }
  3288. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)) //SYS_MODE_PREPARING
  3289. {
  3290. currentStatus = 1; //OCPP Status: Preparing
  3291. }
  3292. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3293. {
  3294. currentStatus = 2; //OCPP Status: Charging
  3295. }
  3296. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3297. {
  3298. currentStatus = 5; //OCPP Status: Finishing
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3301. {
  3302. currentStatus = 4; //OCPP Status: SuspendedEV
  3303. }
  3304. 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
  3305. {
  3306. currentStatus = 7; //OCPP Status: Unavailable
  3307. }
  3308. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3309. {
  3310. currentStatus = 8; //OCPP Status: Faulted
  3311. }
  3312. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3313. {
  3314. currentStatus = 6; //OCPP Status: Reserved
  3315. }
  3316. }//end of the same index
  3317. }//end of for AC_QUANTITY
  3318. }
  3319. //it's option
  3320. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3321. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3322. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3323. random_uuid(guid);
  3324. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3325. , MESSAGE_TYPE_CALL
  3326. , guid
  3327. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3328. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3329. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3330. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3331. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3332. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3333. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3334. LWS_Send(message);
  3335. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3336. 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*/)
  3337. {
  3338. result = PASS;
  3339. }
  3340. return result;
  3341. }
  3342. int sendStopTransactionRequest(int gun_index)
  3343. {
  3344. mtrace();
  3345. int result = FAIL;
  3346. //char message[1500]={0};
  3347. char guid[37]={0};
  3348. char tempdata[65]={0};
  3349. int tempIndex = 0;
  3350. //int idx_sample=0;
  3351. DEBUG_INFO("sendStopTransactionRequest...\n");
  3352. memset(queuedata, 0, sizeof(queuedata));
  3353. //ENERGY_ACTIVE_IMPORT_REGISTER
  3354. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3355. if(gunType[gun_index] == 'J')
  3356. {
  3357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3358. {
  3359. tempIndex = ((gun_index==2) ? 1: 0);
  3360. }
  3361. else
  3362. {
  3363. tempIndex = gun_index;
  3364. }
  3365. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3366. {
  3367. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3368. {
  3369. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3370. }
  3371. }// END OF CHAdeMO_QUANTITY
  3372. }
  3373. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3374. {
  3375. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3376. {
  3377. tempIndex = ((gun_index==2) ? 1: 0);
  3378. }
  3379. else
  3380. {
  3381. tempIndex = gun_index;
  3382. }
  3383. for (int index = 0; index < CCS_QUANTITY; index++)
  3384. {
  3385. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3386. {
  3387. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3388. }
  3389. }// END OF CCS_QUANTITY
  3390. }
  3391. else if(gunType[gun_index] == 'G')
  3392. {
  3393. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3394. {
  3395. tempIndex = ((gun_index==2) ? 1: 0);
  3396. }
  3397. else
  3398. {
  3399. tempIndex = gun_index;
  3400. }
  3401. for (int index = 0; index < GB_QUANTITY; index++)
  3402. {
  3403. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3404. {
  3405. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3406. }
  3407. }// END OF GB_QUANTITY
  3408. }
  3409. else
  3410. {
  3411. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3412. {
  3413. tempIndex = 2;
  3414. }
  3415. else
  3416. {
  3417. tempIndex = gun_index;
  3418. }
  3419. for (int index = 0; index < AC_QUANTITY; index++)
  3420. {
  3421. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3422. {
  3423. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3424. }
  3425. }// END OF AC_QUANTITY
  3426. }
  3427. //Stop Transaction Time
  3428. struct timeval tmnow;
  3429. struct tm *tm;
  3430. char buf[28];//, usec_buf[6];
  3431. gettimeofday(&tmnow, NULL);
  3432. time_t t;
  3433. t = time(NULL);
  3434. /*UTC time and date*/
  3435. tm = gmtime(&t);
  3436. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3437. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3438. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3439. random_uuid(guid);
  3440. /***********************************transactionData******************************************************/
  3441. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3443. //=================================
  3444. // Transaction_Begin
  3445. //=================================
  3446. // Energy.Active.Export.Interval
  3447. //idx_sample=0;
  3448. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3450. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3451. 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*/]);
  3452. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3453. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3454. {
  3455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3456. }
  3457. else
  3458. {
  3459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3460. }
  3461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3462. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3463. //=================================
  3464. // Transaction_End
  3465. //=================================
  3466. //Current.Export
  3467. //idx_sample=1;
  3468. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3469. if(gunType[gun_index] == 'J')
  3470. {
  3471. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3472. {
  3473. tempIndex = ((gun_index==2) ? 1: 0);
  3474. }
  3475. else
  3476. {
  3477. tempIndex = gun_index;
  3478. }
  3479. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3480. {
  3481. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3482. {
  3483. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3484. }
  3485. }// End of for CHAdeMO_QUANTITY
  3486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3487. }
  3488. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3489. {
  3490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3491. {
  3492. tempIndex = ((gun_index==2) ? 1: 0);
  3493. }
  3494. else
  3495. {
  3496. tempIndex = gun_index;
  3497. }
  3498. for (int index = 0; index < CCS_QUANTITY; index++)
  3499. {
  3500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3501. {
  3502. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3503. }
  3504. }// End of for CCS_QUANTITY
  3505. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3506. }
  3507. else if(gunType[gun_index] == 'G')
  3508. {
  3509. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3510. {
  3511. tempIndex = ((gun_index==2) ? 1: 0);
  3512. }
  3513. else
  3514. {
  3515. tempIndex = gun_index;
  3516. }
  3517. for (int index = 0; index < GB_QUANTITY; index++)
  3518. {
  3519. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3520. {
  3521. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3522. }
  3523. }// End of for GB_QUANTITY
  3524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3525. }
  3526. else
  3527. {
  3528. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3529. {
  3530. tempIndex = 2;
  3531. }
  3532. else
  3533. {
  3534. tempIndex = gun_index;
  3535. }
  3536. for (int index = 0; index < AC_QUANTITY; index++)
  3537. {
  3538. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3539. {
  3540. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3541. }
  3542. }// End of for AC_QUANTITY
  3543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3544. }
  3545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3548. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3549. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3551. //Energy.Active.Export.Interval
  3552. //idx_sample=2;
  3553. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3554. if(gunType[gun_index] == 'J')
  3555. {
  3556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3557. {
  3558. tempIndex = ((gun_index==2) ? 1: 0);
  3559. }
  3560. else
  3561. {
  3562. tempIndex = gun_index;
  3563. }
  3564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3565. {
  3566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3567. {
  3568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3569. }
  3570. }// END OF CHAdeMO_QUANTITY
  3571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3572. }
  3573. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3574. {
  3575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3576. {
  3577. tempIndex = ((gun_index==2) ? 1: 0);
  3578. }
  3579. else
  3580. {
  3581. tempIndex = gun_index;
  3582. }
  3583. for (int index = 0; index < CCS_QUANTITY; index++)
  3584. {
  3585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3586. {
  3587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3588. }
  3589. }// END OF CCS_QUANTITY
  3590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3591. }
  3592. else if(gunType[gun_index] == 'G')
  3593. {
  3594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3595. {
  3596. tempIndex = ((gun_index==2) ? 1: 0);
  3597. }
  3598. else
  3599. {
  3600. tempIndex = gun_index;
  3601. }
  3602. for (int index = 0; index < GB_QUANTITY; index++)
  3603. {
  3604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3605. {
  3606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3607. }
  3608. }// END OF GB_QUANTITY
  3609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3610. }
  3611. else
  3612. {
  3613. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3614. {
  3615. tempIndex = 2;
  3616. }
  3617. else
  3618. {
  3619. tempIndex = gun_index;
  3620. }
  3621. for (int index = 0; index < AC_QUANTITY; index++)
  3622. {
  3623. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3624. {
  3625. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3626. }
  3627. }// END OF AC_QUANTITY
  3628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3629. }
  3630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3633. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3635. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3636. //Power.Active.Export
  3637. //idx_sample=3;
  3638. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3639. if(gunType[gun_index] == 'J')
  3640. {
  3641. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3642. {
  3643. tempIndex = ((gun_index==2) ? 1: 0);
  3644. }
  3645. else
  3646. {
  3647. tempIndex = gun_index;
  3648. }
  3649. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3650. {
  3651. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3652. {
  3653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3654. }
  3655. } // End for CHAdeMO_QUANTITY
  3656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3657. }
  3658. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3661. {
  3662. tempIndex = ((gun_index==2) ? 1: 0);
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < CCS_QUANTITY; index++)
  3669. {
  3670. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3671. {
  3672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3673. }
  3674. } // END for CCS_QUANTITY
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3676. }
  3677. else if(gunType[gun_index] == 'G')
  3678. {
  3679. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3680. {
  3681. tempIndex = ((gun_index==2) ? 1: 0);
  3682. }
  3683. else
  3684. {
  3685. tempIndex = gun_index;
  3686. }
  3687. for (int index = 0; index < GB_QUANTITY; index++)
  3688. {
  3689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3690. {
  3691. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3692. }
  3693. }// END for GB_QUANTITY
  3694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3695. }
  3696. else
  3697. {
  3698. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3699. {
  3700. tempIndex = 2;
  3701. }
  3702. else
  3703. {
  3704. tempIndex = gun_index;
  3705. }
  3706. for (int index = 0; index < AC_QUANTITY; index++)
  3707. {
  3708. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3709. {
  3710. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3711. }
  3712. } // END for AC_QUANTITY
  3713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3714. }
  3715. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3716. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3718. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3719. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3720. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3721. //Voltage
  3722. //idx_sample=4;
  3723. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3724. if(gunType[gun_index] == 'J')
  3725. {
  3726. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3727. {
  3728. tempIndex = ((gun_index==2) ? 1: 0);
  3729. }
  3730. else
  3731. {
  3732. tempIndex = gun_index;
  3733. }
  3734. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3735. {
  3736. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3737. {
  3738. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3739. }
  3740. } // END OF FOR CHAdeMO_QUANTITY
  3741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3742. }
  3743. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3744. {
  3745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3746. {
  3747. tempIndex = ((gun_index==2) ? 1: 0);
  3748. }
  3749. else
  3750. {
  3751. tempIndex = gun_index;
  3752. }
  3753. for (int index = 0; index < CCS_QUANTITY; index++)
  3754. {
  3755. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3756. {
  3757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3758. }
  3759. } // END OF FOR CCS_QUANTITY
  3760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3761. }
  3762. else if(gunType[gun_index] == 'G')
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((gun_index==2) ? 1: 0);
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < GB_QUANTITY; index++)
  3773. {
  3774. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3775. {
  3776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3777. }
  3778. } // END OF FOR GB_QUANTITY
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3780. }
  3781. else
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3784. {
  3785. tempIndex = 2;
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < AC_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3794. {
  3795. 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
  3796. }
  3797. } // END OF FOR AC_QUANTITY
  3798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3799. }
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3803. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3804. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3805. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3806. //SoC
  3807. //idx_sample=5;
  3808. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3809. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3810. {
  3811. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3812. {
  3813. tempIndex = ((gun_index==2) ? 1: 0);
  3814. }
  3815. else
  3816. {
  3817. tempIndex = gun_index;
  3818. }
  3819. if(gunType[gun_index] == 'J')
  3820. {
  3821. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3822. {
  3823. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3824. {
  3825. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3826. }
  3827. }
  3828. }
  3829. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3830. {
  3831. for (int index = 0; index < CCS_QUANTITY; index++)
  3832. {
  3833. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3834. {
  3835. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3836. }
  3837. }
  3838. }
  3839. else if(gunType[gun_index] == 'G')
  3840. {
  3841. for (int index = 0; index < GB_QUANTITY; index++)
  3842. {
  3843. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3844. {
  3845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3846. }
  3847. }
  3848. }
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3850. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3855. } // END FOR DC CASE
  3856. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3857. {
  3858. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3859. ,MESSAGE_TYPE_CALL
  3860. ,guid
  3861. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3862. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3866. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3909. );
  3910. }
  3911. else
  3912. {
  3913. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3914. ,MESSAGE_TYPE_CALL
  3915. ,guid
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3921. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3957. );
  3958. }
  3959. #if 1 // for TempStopTransaction
  3960. //Delete TempStopTransaction
  3961. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3962. {
  3963. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3964. }
  3965. #endif
  3966. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3967. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  3968. {
  3969. result = PASS;
  3970. DEBUG_INFO("StopTransaction mapitem pass\n");
  3971. }
  3972. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3973. if(GetTransactionQueueNum() == 1)
  3974. {
  3975. LWS_Send(queuedata);
  3976. }
  3977. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  3978. int gettransactionId = GetTransactionId(gun_index+1, (char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  3979. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  3980. {
  3981. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  3982. }
  3983. //for test
  3984. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  3985. return result;
  3986. }
  3987. int sendMeterValuesRequest(int gun_index)
  3988. {
  3989. mtrace();
  3990. int result = FAIL;
  3991. // char message[1500]={0};
  3992. char guid[37]={0};
  3993. //int idx_sample=0;
  3994. //int length = 0;
  3995. char tempdata[65]={0};
  3996. int tempIndex = 0;
  3997. DEBUG_INFO("sendMeterValuesRequest...\n");
  3998. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  3999. {
  4000. DEBUG_ERROR("NOT SENT METER Vlaue\n");
  4001. return result;
  4002. }
  4003. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4004. {
  4005. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4006. }
  4007. memset(queuedata, 0, sizeof(queuedata));
  4008. //set value
  4009. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4010. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4011. random_uuid(guid);
  4012. //UTC Date time
  4013. struct timeval tmnow;
  4014. struct tm *tm;
  4015. char buf[28];//, usec_buf[6];
  4016. gettimeofday(&tmnow, NULL);
  4017. time_t t;
  4018. t = time(NULL);
  4019. /*UTC time and date*/
  4020. tm = gmtime(&t);
  4021. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4022. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4023. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4024. //idx_sample=0;
  4025. //********************************(1)Current.Export************************************************/
  4026. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4027. if(gunType[gun_index] == 'J')
  4028. {
  4029. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4030. {
  4031. tempIndex = ((gun_index==2) ? 1: 0);
  4032. }
  4033. else
  4034. {
  4035. tempIndex = gun_index;
  4036. }
  4037. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4038. {
  4039. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4040. {
  4041. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4042. }
  4043. }
  4044. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4045. }
  4046. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4047. {
  4048. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4049. {
  4050. tempIndex = ((gun_index==2) ? 1: 0);
  4051. }
  4052. else
  4053. {
  4054. tempIndex = gun_index;
  4055. }
  4056. for (int index = 0; index < CCS_QUANTITY; index++)
  4057. {
  4058. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4059. {
  4060. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4061. }
  4062. }
  4063. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4064. }
  4065. else if(gunType[gun_index] == 'G')
  4066. {
  4067. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4068. {
  4069. tempIndex = ((gun_index==2) ? 1: 0);
  4070. }
  4071. else
  4072. {
  4073. tempIndex = gun_index;
  4074. }
  4075. for (int index = 0; index < GB_QUANTITY; index++)
  4076. {
  4077. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4078. {
  4079. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4080. }
  4081. }
  4082. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4083. }
  4084. else
  4085. {
  4086. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4087. {
  4088. tempIndex = 2;
  4089. }
  4090. else
  4091. {
  4092. tempIndex = gun_index;
  4093. }
  4094. for (int index = 0; index < AC_QUANTITY; index++)
  4095. {
  4096. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4097. {
  4098. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4099. }
  4100. }
  4101. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4102. }
  4103. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4104. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4105. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4106. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4107. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4108. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4109. //idx_sample=1;
  4110. //********************************(2)Energy.Active.Import.Register ************************************************/
  4111. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4112. if(gunType[gun_index] == 'J')
  4113. {
  4114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4115. {
  4116. tempIndex = ((gun_index==2) ? 1: 0);
  4117. }
  4118. else
  4119. {
  4120. tempIndex = gun_index;
  4121. }
  4122. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4123. {
  4124. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4125. {
  4126. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4127. }
  4128. }
  4129. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4130. }
  4131. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4132. {
  4133. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4134. {
  4135. tempIndex = ((gun_index==2) ? 1: 0);
  4136. }
  4137. else
  4138. {
  4139. tempIndex = gun_index;
  4140. }
  4141. for (int index = 0; index < CCS_QUANTITY; index++)
  4142. {
  4143. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4144. {
  4145. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4146. }
  4147. }
  4148. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4149. }
  4150. else if(gunType[gun_index] == 'G')
  4151. {
  4152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4153. {
  4154. tempIndex = ((gun_index==2) ? 1: 0);
  4155. }
  4156. else
  4157. {
  4158. tempIndex = gun_index;
  4159. }
  4160. for (int index = 0; index < GB_QUANTITY; index++)
  4161. {
  4162. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4163. {
  4164. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4165. }
  4166. }
  4167. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4168. }
  4169. else
  4170. {
  4171. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4172. {
  4173. tempIndex = 2;
  4174. }
  4175. else
  4176. {
  4177. tempIndex = gun_index;
  4178. }
  4179. for (int index = 0; index < AC_QUANTITY; index++)
  4180. {
  4181. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4182. {
  4183. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4184. }
  4185. }
  4186. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4187. }
  4188. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4189. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4190. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4191. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4192. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4193. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4194. //idx_sample=2;
  4195. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4196. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4197. if(gunType[gun_index] == 'J')
  4198. {
  4199. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4200. {
  4201. tempIndex = ((gun_index==2) ? 1: 0);
  4202. }
  4203. else
  4204. {
  4205. tempIndex = gun_index;
  4206. }
  4207. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4208. {
  4209. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4210. {
  4211. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4212. }
  4213. } // END OF FOR CHAdeMO_QUANTITY
  4214. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4215. }
  4216. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4217. {
  4218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4219. {
  4220. tempIndex = ((gun_index==2) ? 1: 0);
  4221. }
  4222. else
  4223. {
  4224. tempIndex = gun_index;
  4225. }
  4226. for (int index = 0; index < CCS_QUANTITY; index++)
  4227. {
  4228. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4229. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4230. {
  4231. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4232. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4233. }
  4234. } // END OF CCS_QUANTITY
  4235. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4236. }
  4237. else if(gunType[gun_index] == 'G')
  4238. {
  4239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4240. {
  4241. tempIndex = ((gun_index==2) ? 1: 0);
  4242. }
  4243. else
  4244. {
  4245. tempIndex = gun_index;
  4246. }
  4247. for (int index = 0; index < GB_QUANTITY; index++)
  4248. {
  4249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4250. {
  4251. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4252. }
  4253. } // END OF GB_QUANTITY
  4254. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4255. }
  4256. else
  4257. {
  4258. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4259. {
  4260. tempIndex = 2;
  4261. }
  4262. else
  4263. {
  4264. tempIndex = gun_index;
  4265. }
  4266. for (int index = 0; index < AC_QUANTITY; index++)
  4267. {
  4268. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4269. {
  4270. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4271. }
  4272. }
  4273. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4274. }
  4275. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4276. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4277. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4278. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4280. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4281. //idx_sample=3;
  4282. //********************************(4)Power.Active.Export************************************************/
  4283. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4284. if(gunType[gun_index] == 'J')
  4285. {
  4286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4287. {
  4288. tempIndex = ((gun_index==2) ? 1: 0);
  4289. }
  4290. else
  4291. {
  4292. tempIndex = gun_index;
  4293. }
  4294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4297. {
  4298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4299. }
  4300. } // END OF FOR
  4301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4302. }
  4303. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4304. {
  4305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4306. {
  4307. tempIndex = ((gun_index==2) ? 1: 0);
  4308. }
  4309. else
  4310. {
  4311. tempIndex = gun_index;
  4312. }
  4313. for (int index = 0; index < CCS_QUANTITY; index++)
  4314. {
  4315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4316. {
  4317. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4318. }
  4319. }
  4320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4321. }
  4322. else if(gunType[gun_index] == 'G')
  4323. {
  4324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4325. {
  4326. tempIndex = ((gun_index==2) ? 1: 0);
  4327. }
  4328. else
  4329. {
  4330. tempIndex = gun_index;
  4331. }
  4332. for (int index = 0; index < GB_QUANTITY; index++)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4335. {
  4336. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4337. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4338. }
  4339. }
  4340. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4341. }
  4342. else
  4343. {
  4344. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4345. {
  4346. tempIndex = 2;
  4347. }
  4348. else
  4349. {
  4350. tempIndex = gun_index;
  4351. }
  4352. for (int index = 0; index < AC_QUANTITY; index++)
  4353. {
  4354. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4355. {
  4356. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4357. }
  4358. }
  4359. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4360. }
  4361. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4362. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4363. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4364. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4365. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4367. //idx_sample=4;
  4368. //***********************************************(5)VOLTAGE******************************************************/
  4369. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4370. if(gunType[gun_index] == 'J')
  4371. {
  4372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4373. {
  4374. tempIndex = ((gun_index==2) ? 1: 0);
  4375. }
  4376. else
  4377. {
  4378. tempIndex = gun_index;
  4379. }
  4380. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4381. {
  4382. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4383. {
  4384. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4385. }
  4386. }
  4387. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4388. }
  4389. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4390. {
  4391. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4392. {
  4393. tempIndex = ((gun_index==2) ? 1: 0);
  4394. }
  4395. else
  4396. {
  4397. tempIndex = gun_index;
  4398. }
  4399. for (int index = 0; index < CCS_QUANTITY; index++)
  4400. {
  4401. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4402. {
  4403. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4404. }
  4405. }
  4406. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4407. }
  4408. else if(gunType[gun_index] == 'G')
  4409. {
  4410. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4411. {
  4412. tempIndex = ((gun_index==2) ? 1: 0);
  4413. }
  4414. else
  4415. {
  4416. tempIndex = gun_index;
  4417. }
  4418. for (int index = 0; index < GB_QUANTITY; index++)
  4419. {
  4420. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4421. {
  4422. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4423. }
  4424. }
  4425. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4426. }
  4427. else
  4428. {
  4429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4430. {
  4431. tempIndex = 2;
  4432. }
  4433. else
  4434. {
  4435. tempIndex = gun_index;
  4436. }
  4437. for (int index = 0; index < AC_QUANTITY; index++)
  4438. {
  4439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4440. {
  4441. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4442. }
  4443. }
  4444. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4445. }
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4449. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4450. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4452. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4453. {
  4454. //idx_sample=5;
  4455. //sampledValue = NULL;
  4456. //***********************************************(6)SOC******************************************************/
  4457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4458. {
  4459. tempIndex = ((gun_index==2) ? 1: 0);
  4460. }
  4461. else
  4462. {
  4463. tempIndex = gun_index;
  4464. }
  4465. if(gunType[gun_index] == 'J')
  4466. {
  4467. //tempIndex = ((gun_index==2) ? 1: 0);
  4468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4469. {
  4470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4471. {
  4472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4473. }
  4474. }
  4475. }
  4476. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4477. {
  4478. //tempIndex = ((gun_index==2) ? 1: 0);
  4479. for (int index = 0; index < CCS_QUANTITY; index++)
  4480. {
  4481. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4482. {
  4483. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4484. }
  4485. }
  4486. }
  4487. else if(gunType[gun_index] == 'G')
  4488. {
  4489. //tempIndex = ((gun_index==2) ? 1: 0);
  4490. for (int index = 0; index < GB_QUANTITY; index++)
  4491. {
  4492. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4493. {
  4494. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4495. }
  4496. }
  4497. }
  4498. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4499. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4500. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4501. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4502. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4503. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4504. }
  4505. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4506. {
  4507. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4508. ,MESSAGE_TYPE_CALL
  4509. ,guid
  4510. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4511. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4512. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4513. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4514. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4515. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4516. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4517. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4518. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4519. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4520. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4521. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4522. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4523. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4524. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4525. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4526. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4527. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4528. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4529. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4530. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4531. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4532. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4533. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4534. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4535. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4536. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4537. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4538. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4539. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4540. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4541. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4542. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4543. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4544. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4545. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4546. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4547. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4548. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4549. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4550. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4551. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4552. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4553. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4554. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4555. );
  4556. }
  4557. else
  4558. {
  4559. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4560. ,MESSAGE_TYPE_CALL
  4561. ,guid
  4562. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4563. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4564. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4587. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4588. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4589. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4590. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4591. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4592. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4593. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4594. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4595. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4596. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4597. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4600. );
  4601. }
  4602. // Put request guid to hash map
  4603. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4604. 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*/)
  4605. {
  4606. result = PASS;
  4607. DEBUG_INFO("MeterValues mapitem pass\n");
  4608. }
  4609. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4610. if(GetTransactionQueueNum() == 1)
  4611. {
  4612. LWS_Send(queuedata);
  4613. }
  4614. return result;
  4615. }
  4616. //==========================================
  4617. // send confirm routine
  4618. //==========================================
  4619. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4620. {
  4621. mtrace();
  4622. int result = FAIL;
  4623. char message[100]={0};
  4624. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4625. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4626. LWS_Send(message);
  4627. result = TRUE;
  4628. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4629. return result;
  4630. }
  4631. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4632. {
  4633. mtrace();
  4634. int result = FAIL;
  4635. char message[100]={0};
  4636. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4637. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4638. LWS_Send(message);
  4639. result = TRUE;
  4640. return result;
  4641. }
  4642. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4643. {
  4644. mtrace();
  4645. int result = FAIL;
  4646. char message[100]={0};
  4647. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4648. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4649. LWS_Send(message);
  4650. result = TRUE;
  4651. return result;
  4652. }
  4653. int sendClearCacheConfirmation(char *uuid,char *payload)
  4654. {
  4655. mtrace();
  4656. int result = FAIL;
  4657. char message[500]={0};
  4658. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4659. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4660. LWS_Send(message);
  4661. return result;
  4662. }
  4663. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4664. {
  4665. mtrace();
  4666. int result = FAIL;
  4667. char message[500]={0};
  4668. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4669. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4670. LWS_Send(message);
  4671. return result;
  4672. }
  4673. int sendDataTransferConfirmation(char *uuid,char *payload)
  4674. {
  4675. mtrace();
  4676. char statusStr[20]={0};
  4677. char dataStr[10]={0};
  4678. char sstr[20]={0};
  4679. int c = 0;
  4680. char *loc;
  4681. int result = FAIL;
  4682. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4683. /**********************status**************************/
  4684. loc = strstr(payload, "status");
  4685. memset(sstr ,0, sizeof(sstr) );
  4686. c = 0;
  4687. while (loc[3+strlen("status")+c] != '\"')
  4688. {
  4689. sstr[c] = loc[3+strlen("status")+c];
  4690. c++;
  4691. }
  4692. sstr[c] = '\0';
  4693. strcpy(statusStr, sstr);
  4694. /**********************data**************************/
  4695. loc = strstr(payload, "data");
  4696. memset(sstr ,0, sizeof(sstr) );
  4697. c = 0;
  4698. while (loc[3+strlen("data")+c] != '\"')
  4699. {
  4700. sstr[c] = loc[3+strlen("data")+c];
  4701. c++;
  4702. }
  4703. sstr[c] = '\0';
  4704. strcpy(dataStr, sstr);
  4705. return result;
  4706. }
  4707. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4708. {
  4709. mtrace();
  4710. int result = FAIL;
  4711. char message[1000]={0};
  4712. int CompositeScheduleIndex = 0;
  4713. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4714. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4715. if(nPeriod == 0)
  4716. {
  4717. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4718. {
  4719. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4720. ,MESSAGE_TYPE_CALLRESULT
  4721. ,uuid
  4722. ,payload
  4723. ,connectorIdInt);
  4724. }
  4725. else
  4726. {
  4727. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":0,\"numberPhases\":3}]}}]"
  4728. ,MESSAGE_TYPE_CALLRESULT
  4729. ,uuid
  4730. ,payload
  4731. ,connectorIdInt
  4732. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4733. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4734. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4735. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4736. }
  4737. }
  4738. else
  4739. {
  4740. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4741. ,MESSAGE_TYPE_CALLRESULT
  4742. ,uuid
  4743. ,payload
  4744. ,connectorIdInt
  4745. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4746. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4747. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4748. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4749. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4750. {
  4751. if (idx_sample == 0)
  4752. {
  4753. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4754. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4755. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4756. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4757. }
  4758. else
  4759. {
  4760. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4761. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4762. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4763. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4764. }
  4765. }
  4766. sprintf(message + strlen(message), "]}}]");
  4767. }
  4768. LWS_Send(message);
  4769. result = TRUE;
  4770. return result;
  4771. }
  4772. int sendGetConfigurationConfirmation(char *uuid)
  4773. {
  4774. mtrace();
  4775. int result = FAIL;
  4776. int MaxKeySupported = 0;
  4777. int sentConfigurationNumber= 0;
  4778. int sentunConfigurationNumber= 0;
  4779. char message[4000]={0};
  4780. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4781. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4782. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4783. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4784. ,MESSAGE_TYPE_CALLRESULT
  4785. ,uuid );
  4786. //configuration key
  4787. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4788. {
  4789. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4790. {
  4791. if (sentConfigurationNumber == 0)
  4792. {
  4793. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4794. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4795. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4796. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4797. }
  4798. else
  4799. {
  4800. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4801. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4802. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4803. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4804. }
  4805. sentConfigurationNumber = sentConfigurationNumber + 1;
  4806. }
  4807. }
  4808. sprintf(message + strlen(message), "]");
  4809. if(UnknownKeynum != 0)
  4810. {
  4811. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4812. //unkown key
  4813. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4814. {
  4815. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4816. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4817. if(sentunConfigurationNumber == 0)
  4818. {
  4819. sprintf(message + strlen(message), "\"%s\""
  4820. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4821. }
  4822. else
  4823. {
  4824. sprintf(message + strlen(message), ",\"%s\""
  4825. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4826. }
  4827. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4828. }
  4829. sprintf(message + strlen(message), "]");
  4830. }
  4831. sprintf(message + strlen(message), "}]");
  4832. LWS_Send(message);
  4833. return result;
  4834. }
  4835. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4836. {
  4837. mtrace();
  4838. int result = FAIL;
  4839. char message[400]={0};
  4840. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4841. if(strcmp(payload,"")==0)
  4842. {
  4843. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4844. }
  4845. else
  4846. {
  4847. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4848. }
  4849. LWS_Send(message);
  4850. result = TRUE;
  4851. return result;
  4852. }
  4853. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4854. {
  4855. mtrace();
  4856. int result = FAIL;
  4857. char message[80]={0};
  4858. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4859. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4860. LWS_Send(message);
  4861. result = TRUE;
  4862. return result;
  4863. }
  4864. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4865. {
  4866. mtrace();
  4867. int result = FAIL;
  4868. char message[80]={0};
  4869. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4870. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4871. LWS_Send(message);
  4872. result = TRUE;
  4873. return result;
  4874. }
  4875. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4876. {
  4877. mtrace();
  4878. int result = FAIL;
  4879. char message[80]={0};
  4880. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4881. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4882. LWS_Send(message);
  4883. result = TRUE;
  4884. return result;
  4885. }
  4886. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4887. {
  4888. mtrace();
  4889. int result = FAIL;
  4890. char message[80]={0};
  4891. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4892. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4893. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4894. LWS_Send(message);
  4895. result = TRUE;
  4896. return result;
  4897. }
  4898. int sendResetConfirmation(char *uuid,char *payload)
  4899. {
  4900. mtrace();
  4901. int result = FAIL;
  4902. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4903. char message[80]={0};
  4904. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4905. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4906. LWS_Send(message);
  4907. result = TRUE;
  4908. return result;
  4909. }
  4910. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4911. {
  4912. mtrace();
  4913. int result = FAIL;
  4914. char message[500]={0};
  4915. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4916. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4917. LWS_Send(message);
  4918. result = TRUE;
  4919. return result;
  4920. }
  4921. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4922. {
  4923. mtrace();
  4924. int result = FAIL;
  4925. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4926. char message[80]={0};
  4927. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4928. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4929. LWS_Send(message);
  4930. result = TRUE;
  4931. return result;
  4932. }
  4933. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4934. {
  4935. mtrace();
  4936. int result = FAIL;
  4937. char message[80]={0};
  4938. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  4939. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4940. LWS_Send(message);
  4941. result = TRUE;
  4942. return result;
  4943. }
  4944. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  4945. {
  4946. mtrace();
  4947. int result = FAIL;
  4948. char message[80]={0};
  4949. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4950. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  4951. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4952. LWS_Send(message);
  4953. result = TRUE;
  4954. return result;
  4955. }
  4956. int sendUpdateFirmwareConfirmation(char *uuid)
  4957. {
  4958. mtrace();
  4959. int result = FAIL;
  4960. char message[60]={0};
  4961. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4962. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  4963. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4964. LWS_Send(message);
  4965. result = TRUE;
  4966. return result;
  4967. }
  4968. //==========================================
  4969. // send CallError routine
  4970. //==========================================
  4971. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  4972. {
  4973. mtrace();
  4974. char message[220]={0};
  4975. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  4976. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  4977. LWS_Send(message);
  4978. }
  4979. //==========================================
  4980. // Handle server request routine Start
  4981. //==========================================
  4982. int handleCancelReservationRequest(char *uuid, char *payload)
  4983. {
  4984. mtrace();
  4985. int result = FAIL;
  4986. int gunNO = 0;
  4987. int reservationIdInt =0;
  4988. char comfirmstr[20];
  4989. DEBUG_INFO("handleCancelReservationRequest...\n");
  4990. json_object *CancelReservation;
  4991. CancelReservation = json_tokener_parse(payload);
  4992. if(!is_error(CancelReservation))
  4993. {
  4994. // Required data
  4995. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  4996. }
  4997. json_object_put(CancelReservation);
  4998. memset(comfirmstr, 0, sizeof comfirmstr);
  4999. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5000. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5001. //check Transaction active
  5002. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5003. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5004. {
  5005. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5006. {
  5007. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5008. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5009. if(gunType[2] == 'J')
  5010. {
  5011. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5012. }
  5013. else
  5014. {
  5015. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5016. }
  5017. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5018. goto end;
  5019. }
  5020. }
  5021. for (int index = 0; index < CCS_QUANTITY; index++)
  5022. {
  5023. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5024. {
  5025. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5026. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5027. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5028. {
  5029. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5030. }
  5031. else
  5032. {
  5033. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5034. }
  5035. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5036. goto end;
  5037. }
  5038. }
  5039. for (int index = 0; index < GB_QUANTITY; index++)
  5040. {
  5041. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5042. {
  5043. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5044. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5045. if(gunType[2] == 'G')
  5046. {
  5047. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5048. }
  5049. else
  5050. {
  5051. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5052. }
  5053. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5054. goto end;
  5055. }
  5056. }
  5057. for (int index = 0; index < AC_QUANTITY; index++)
  5058. {
  5059. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5060. {
  5061. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5062. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5063. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5064. {
  5065. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5066. }
  5067. else
  5068. {
  5069. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5070. }
  5071. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5072. goto end;
  5073. }
  5074. }
  5075. //The reservationId does NOT match the reservationId
  5076. sendCancelReservationConfirmation(uuid, comfirmstr);
  5077. end:
  5078. // Fill in ocpp packet uuid
  5079. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5080. return result;
  5081. }
  5082. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5083. {
  5084. mtrace();
  5085. int result = FAIL;
  5086. int gunIndex = 0;
  5087. char typeStr[16]={0};
  5088. char comfirmstr[20];
  5089. int specificId = FALSE;
  5090. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5091. json_object *ChangeAvailability;
  5092. ChangeAvailability = json_tokener_parse(payload);
  5093. if(!is_error(ChangeAvailability))
  5094. {
  5095. // Required data
  5096. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5097. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5098. }
  5099. json_object_put(ChangeAvailability);
  5100. if(gunIndex != 0)
  5101. {
  5102. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5103. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5104. }
  5105. else
  5106. {
  5107. ShmOCPP16Data->ChangeAvailability[0].ConnectorId= gunIndex;
  5108. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].Type, "%s", typeStr);
  5109. }
  5110. memset(comfirmstr, 0, sizeof comfirmstr);
  5111. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5112. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5113. {
  5114. specificId = TRUE;
  5115. }
  5116. if(specificId == FALSE)
  5117. goto end;
  5118. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5119. {
  5120. //check Transaction active
  5121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5122. {
  5123. if ((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')))
  5124. {
  5125. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5126. {
  5127. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5128. goto end;
  5129. }
  5130. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5131. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5132. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5133. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5134. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5135. {
  5136. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5137. goto end;
  5138. }
  5139. else
  5140. {
  5141. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5142. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5143. goto end;
  5144. }
  5145. }
  5146. }//END FOR CHAdeMO_QUANTITY
  5147. for (int index = 0; index < CCS_QUANTITY; index++)
  5148. {
  5149. if ((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))))
  5150. {
  5151. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5152. {
  5153. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5154. goto end;
  5155. }
  5156. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5157. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5158. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5159. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5160. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5161. {
  5162. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5163. goto end;
  5164. }
  5165. else
  5166. {
  5167. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5168. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5169. goto end;
  5170. }
  5171. }
  5172. }//END FOR CCS_QUANTITY
  5173. for (int index = 0; index < GB_QUANTITY; index++)
  5174. {
  5175. if ((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))
  5176. {
  5177. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5178. {
  5179. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5180. goto end;
  5181. }
  5182. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5183. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5184. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5185. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5186. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5187. {
  5188. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5189. goto end;
  5190. }
  5191. else
  5192. {
  5193. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5194. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5195. goto end;
  5196. }
  5197. }
  5198. }// END FOR GB_QUANTITY
  5199. for (int index = 0; index < AC_QUANTITY; index++)
  5200. {
  5201. if ((gunIndex == 0) || ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))))
  5202. {
  5203. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5204. {
  5205. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5206. goto end;
  5207. }
  5208. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5209. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5210. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5211. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5212. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5213. {
  5214. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5215. goto end;
  5216. }
  5217. else
  5218. {
  5219. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5220. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5221. goto end;
  5222. }
  5223. }
  5224. }//END FOR AC_QUANTITY
  5225. }//END FOR AvailabilityTypeStr[Inoperative]
  5226. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5227. {
  5228. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5229. //check Transaction active
  5230. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5231. {
  5232. if (((gunIndex == 0) || ((gunIndex > 0) && (gunType[gunIndex-1] == 'J'))) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5233. {
  5234. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5235. goto end;
  5236. }
  5237. }//END FOR CHAdeMO_QUANTITY
  5238. for (int index = 0; index < CCS_QUANTITY; index++)
  5239. {
  5240. if (((gunIndex == 0) || ((gunIndex > 0) && ((gunType[gunIndex - 1] == 'U') || (gunType[gunIndex - 1] == 'E')))) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5241. {
  5242. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5243. goto end;
  5244. }
  5245. }//END FOR CCS_QUANTITY
  5246. for (int index = 0; index < GB_QUANTITY; index++)
  5247. {
  5248. if (((gunIndex == 0) || ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5249. {
  5250. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5251. goto end;
  5252. }
  5253. }// END FOR GB_QUANTITY
  5254. for (int index = 0; index < AC_QUANTITY; index++)
  5255. {
  5256. if( ((gunIndex == 0) || ((gunIndex > 0) && ((gunType[gunIndex-1] > '0') && (gunType[gunIndex-1] <= '9')))) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5257. {
  5258. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5259. goto end;
  5260. }
  5261. }//END FOR AC_QUANTITY
  5262. }//END FOR AvailabilityTypeStr[Operative]
  5263. end:
  5264. if(gunIndex != 0)
  5265. {
  5266. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5267. }
  5268. else
  5269. {
  5270. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5271. }
  5272. if(gunIndex != 0)
  5273. {
  5274. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5275. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5276. }
  5277. else
  5278. {
  5279. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5280. {
  5281. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5282. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5283. }
  5284. }
  5285. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5286. return result;
  5287. }
  5288. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5289. {
  5290. mtrace();
  5291. int result = FAIL;
  5292. char keystr[40]={0};
  5293. char valuestr[100]={0};
  5294. char comfirmstr[20]={0};
  5295. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5296. json_object *ChangeConfiguration;
  5297. ChangeConfiguration = json_tokener_parse(payload);
  5298. if(!is_error(ChangeConfiguration))
  5299. {
  5300. // Required data
  5301. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5302. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5303. }
  5304. json_object_put(ChangeConfiguration);
  5305. if((uuid==NULL) || (payload ==NULL) )
  5306. {
  5307. DEBUG_ERROR("Payload is null\n");
  5308. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5309. }
  5310. else
  5311. {
  5312. int status = setKeyValue(keystr, valuestr);
  5313. switch(status)
  5314. {
  5315. case ConfigurationStatus_Accepted:
  5316. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5317. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5318. StoreConfigurationTable();
  5319. break;
  5320. case ConfigurationStatus_Rejected:
  5321. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5322. break;
  5323. case RebootRequired:
  5324. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5325. StoreConfigurationTable();
  5326. break;
  5327. case NotSupported:
  5328. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5329. break;
  5330. default:
  5331. break;
  5332. }
  5333. }
  5334. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5335. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5336. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5337. {
  5338. ChageWebSocketPingInterval(atoi(valuestr));
  5339. }
  5340. return result;
  5341. }
  5342. int handleClearCacheRequest(char *uuid, char *payload)
  5343. {
  5344. mtrace();
  5345. int result = FAIL;
  5346. char comfirmstr[20];
  5347. int fd;
  5348. char rmFileCmd[100]={0};
  5349. struct stat stats;
  5350. DEBUG_INFO("handleClearCacheRequest...\n");
  5351. stat("/Storage/OCPP", &stats);
  5352. // Check for directory existence
  5353. if (S_ISDIR(stats.st_mode) == 1)
  5354. {}
  5355. else
  5356. {
  5357. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5358. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5359. system(rmFileCmd);
  5360. }
  5361. memset(rmFileCmd, 0, sizeof rmFileCmd);
  5362. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5363. {
  5364. DEBUG_INFO("AuthorizationCache file exist.\n");
  5365. }
  5366. else
  5367. {
  5368. DEBUG_INFO("AuthorizationCache file not exist\n");
  5369. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5370. if(log == NULL)
  5371. {
  5372. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5373. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5374. goto end;
  5375. }
  5376. else
  5377. {
  5378. fclose(log);
  5379. }
  5380. }
  5381. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5382. {
  5383. DEBUG_INFO("open AuthorizationCache file failed\n");
  5384. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5385. }
  5386. else
  5387. {
  5388. DEBUG_INFO("open AuthorizationCache file successful\n");
  5389. ftruncate(fd,0);
  5390. lseek(fd,0,SEEK_SET);
  5391. close(fd);
  5392. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5393. }
  5394. end:
  5395. sendClearCacheConfirmation(uuid, comfirmstr);
  5396. return result;
  5397. }
  5398. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5399. {
  5400. mtrace();
  5401. int result = FAIL;
  5402. int resultRename;
  5403. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5404. char chargingProfilePurposeStr[26]={0};
  5405. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5406. char tempchargingProfilePurposeStr[26]={0};
  5407. char sstr[160]={0};
  5408. char str[100]={0};
  5409. int c = 0;
  5410. char *loc;
  5411. char fname[200]={0};
  5412. char comfirmstr[20]={0};
  5413. char word[1600]={0};
  5414. int clearflag = FALSE;
  5415. int chargingProfileIdIsNULL = FALSE;
  5416. int connectorIsNULL = FALSE;
  5417. int chargingProfilePurposeIsNULL = FALSE;
  5418. int stackLevelIsNULL = FALSE;
  5419. //int GotoEnd = FALSE;
  5420. FILE *fptr1, *fptr2;
  5421. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5422. int n_chargingProfile=0;
  5423. int isEmptyFile = FALSE;
  5424. char sLineWord[1600]={0};
  5425. char chargingProfiles[10][100]={0};
  5426. int ChargeProfileCount = 0;
  5427. char ch;
  5428. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5429. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5430. json_object *ClearChargingProfile;
  5431. ClearChargingProfile = json_tokener_parse(payload);
  5432. if(!is_error(ClearChargingProfile))
  5433. {
  5434. // Optional data
  5435. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5436. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5437. else
  5438. chargingProfileIdIsNULL = TRUE;
  5439. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5440. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5441. else
  5442. connectorIsNULL = TRUE;
  5443. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5444. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5445. else
  5446. chargingProfilePurposeIsNULL = TRUE;
  5447. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5448. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5449. else
  5450. stackLevelIsNULL = TRUE;
  5451. }
  5452. json_object_put(ClearChargingProfile);
  5453. if(connectorIsNULL == FALSE)
  5454. {
  5455. switch(connectorIdInt)
  5456. {
  5457. case 0:
  5458. if(chargingProfilePurposeIsNULL == TRUE)
  5459. {
  5460. int l = 0;
  5461. strcpy(fname, ChargePointMaxProfile_JSON);
  5462. if((access(fname,F_OK))!=-1)
  5463. {
  5464. strcpy(chargingProfiles[l], fname);
  5465. l = l + 1;
  5466. }
  5467. strcpy(fname, TxDefaultProfile_0_JSON);
  5468. if((access(fname,F_OK))!=-1)
  5469. {
  5470. strcpy(chargingProfiles[l], fname);
  5471. l = l + 1;
  5472. }
  5473. ChargeProfileCount = l;
  5474. }
  5475. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5476. {
  5477. strcpy(fname, ChargePointMaxProfile_JSON);
  5478. if((access(fname,F_OK))!=-1)
  5479. {
  5480. strcpy(chargingProfiles[0], fname);
  5481. ChargeProfileCount = 1;
  5482. }
  5483. }
  5484. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5485. {
  5486. strcpy(fname, TxDefaultProfile_0_JSON);
  5487. if((access(fname,F_OK))!=-1)
  5488. {
  5489. strcpy(chargingProfiles[0], fname);
  5490. ChargeProfileCount = 1;
  5491. }
  5492. }
  5493. break;
  5494. default:
  5495. if(chargingProfilePurposeIsNULL == TRUE)
  5496. {
  5497. int m = 0;
  5498. memset(fname, 0, sizeof fname);
  5499. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5500. if((access(fname,F_OK))!=-1)
  5501. {
  5502. strcpy(chargingProfiles[m], fname);
  5503. m = m + 1;
  5504. }
  5505. memset(fname, 0, sizeof fname);
  5506. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5507. if((access(fname,F_OK))!=-1)
  5508. {
  5509. strcpy(chargingProfiles[m], fname);
  5510. m = m + 1;
  5511. }
  5512. ChargeProfileCount = m;
  5513. }
  5514. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5515. {
  5516. //strcpy(fname, TxDefaultProfile_1_JSON);
  5517. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5518. if((access(fname,F_OK))!=-1)
  5519. {
  5520. strcpy(chargingProfiles[0], fname);
  5521. ChargeProfileCount = 1;
  5522. }
  5523. }
  5524. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5525. {
  5526. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5527. if((access(fname,F_OK))!=-1)
  5528. {
  5529. strcpy(chargingProfiles[0], fname);
  5530. ChargeProfileCount = 1;
  5531. }
  5532. //strcpy(fname, TxProfile_1_JSON);
  5533. }
  5534. //strcpy(fname, ChargePointMaxProfile_JSON );
  5535. break;
  5536. }
  5537. }
  5538. else // Check all Charging Profiles
  5539. {
  5540. int i = 0;
  5541. char fnametemp[200]={0};
  5542. ChargeProfileCount = 0;
  5543. //Check ChargePointMaxProfile.json exit
  5544. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5545. {
  5546. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5547. i = i + 1;
  5548. }
  5549. //Check TxDefaultProfile_0.json exit
  5550. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5551. {
  5552. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5553. i = i + 1;
  5554. }
  5555. //Check TxDefaultProfile_%d.json
  5556. for(int j=1; j <= gunTotalNumber; j++)
  5557. {
  5558. memset(fnametemp, 0, sizeof fnametemp);
  5559. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5560. if((access(fnametemp,F_OK))!=-1)
  5561. {
  5562. strcpy(chargingProfiles[i], fnametemp);
  5563. i = i + 1;
  5564. }
  5565. }
  5566. //Check TxProfile_%d.json
  5567. for(int j=1; j <= gunTotalNumber; j++)
  5568. {
  5569. memset(fnametemp, 0, sizeof fnametemp);
  5570. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5571. if((access(fnametemp,F_OK))!=-1)
  5572. {
  5573. strcpy(chargingProfiles[i], fnametemp);
  5574. i = i + 1;
  5575. }
  5576. }
  5577. ChargeProfileCount = i;
  5578. }// End connectorIsNULL is TRUE
  5579. if(ChargeProfileCount == 0)
  5580. {
  5581. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5582. goto end;
  5583. }
  5584. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5585. {
  5586. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5587. goto end;
  5588. }
  5589. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5590. {
  5591. memset(str, 0, sizeof str);
  5592. // clear temp file
  5593. sprintf(str,"rm -f %s",temp);
  5594. system(str);
  5595. for(int k=0; k < ChargeProfileCount; k++)
  5596. {
  5597. memset(str, 0, sizeof str);
  5598. //clear file in C
  5599. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5600. system(str);
  5601. }
  5602. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5603. goto end;
  5604. }
  5605. else if(connectorIsNULL == TRUE)
  5606. {
  5607. for(int k=0; k < ChargeProfileCount; k++)
  5608. {
  5609. fptr1 = fopen(chargingProfiles[k], "r");
  5610. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5611. //Check Charging Profile Count
  5612. while(fscanf(fptr1, "%s", word) != EOF)
  5613. {
  5614. //DEBUG_INFO("word=%s\n",word);
  5615. if(strstr(word, "chargingProfileId")!= NULL)
  5616. {
  5617. //DEBUG_INFO("test chargingProfileId \n");
  5618. n_chargingProfile = n_chargingProfile + 1;
  5619. //DEBUG_INFO("chargingProfileId Found\n");
  5620. }
  5621. }
  5622. rewind(fptr1);
  5623. //search Charging Profile Element
  5624. //int i= 0;
  5625. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5626. {
  5627. //------------------------tempconnectorIdInt------------------------//
  5628. loc = strstr(sLineWord, "connectorId");
  5629. c = 0;
  5630. memset(sstr ,0, sizeof(sstr) );
  5631. while (loc[strlen("connectorId")+2+c] != ',')
  5632. {
  5633. sstr[c] = loc[strlen("connectorId")+2+c];
  5634. c++;
  5635. }
  5636. sstr[c] = '\0';
  5637. tempconnectorIdInt = atoi(sstr);
  5638. printf("file's gun number is %d\n", tempconnectorIdInt);
  5639. //--------------------------chargingProfileId--------------------//
  5640. c = 0;
  5641. loc = strstr(sLineWord, "chargingProfileId");
  5642. memset(sstr ,0, sizeof(sstr) );
  5643. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5644. {
  5645. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5646. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5647. c++;
  5648. }
  5649. sstr[c] = '\0';
  5650. tempchargingProfileIdInt = atoi(sstr);
  5651. //stackLevel
  5652. c = 0;
  5653. loc = strstr(sLineWord, "stackLevel");
  5654. memset(sstr ,0, sizeof(sstr) );
  5655. while (loc[strlen("stackLevel")+2+c] != ',')
  5656. {
  5657. sstr[c] = loc[strlen("stackLevel")+2+c];
  5658. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5659. c++;
  5660. }
  5661. sstr[c] = '\0';
  5662. tempstackLevelInt = atoi(sstr);
  5663. c = 0;
  5664. loc = strstr(sLineWord, "chargingProfilePurpose");
  5665. memset(sstr ,0, sizeof(sstr) );
  5666. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5667. {
  5668. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5669. c++;
  5670. }
  5671. sstr[c] = '\0';
  5672. strcpy(tempchargingProfilePurposeStr, sstr);
  5673. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5674. {
  5675. //------- not write to fptr2-------//
  5676. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5677. //clearflag = TRUE;
  5678. }
  5679. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5680. {
  5681. //------- not write to fptr2-------//
  5682. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5683. }
  5684. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5685. {
  5686. //------- not write to fptr2-------//
  5687. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5688. }
  5689. else
  5690. {
  5691. fprintf(fptr2, sLineWord);//writing data into file
  5692. }
  5693. memset(sLineWord, 0, sizeof sLineWord);
  5694. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5695. if(clearflag == TRUE)
  5696. {
  5697. fclose(fptr1);
  5698. fclose(fptr2);
  5699. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5700. system(str);
  5701. // clear temp file
  5702. sprintf(str,"rm -f %s",temp);
  5703. system(str);
  5704. }
  5705. else
  5706. {
  5707. fclose(fptr1);
  5708. fclose(fptr2);
  5709. memset(str, 0, sizeof str);
  5710. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5711. system(str);
  5712. resultRename = rename(temp, chargingProfiles[k]);
  5713. if(resultRename == 0)
  5714. {
  5715. DEBUG_INFO("File ChargingProfile renamed successfully");
  5716. }
  5717. else
  5718. {
  5719. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5720. }
  5721. if(comfirmstr[0]== 0)
  5722. {
  5723. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5724. }
  5725. //Check chargingProfile is empty file
  5726. /*------ Read the file ----------------*/
  5727. fptr1=fopen(chargingProfiles[k],"r");
  5728. ch=fgetc(fptr1);
  5729. rewind(fptr1);
  5730. memset(sLineWord, 0, sizeof sLineWord);
  5731. if(ch!=EOF)
  5732. {
  5733. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5734. {
  5735. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5736. if(sLineWord[0]=='\0')
  5737. {
  5738. isEmptyFile = TRUE;
  5739. break;
  5740. }
  5741. else
  5742. {
  5743. isEmptyFile = FALSE;
  5744. break;
  5745. }
  5746. }
  5747. }
  5748. fclose(fptr1);
  5749. if(isEmptyFile == TRUE)
  5750. {
  5751. memset(str, 0, sizeof str);
  5752. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5753. system(str);
  5754. }
  5755. }
  5756. }// End of while(int k=0; k < ChargePointCount; k++)
  5757. }
  5758. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5759. {
  5760. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5761. for(int k=0; k < ChargeProfileCount; k++)
  5762. {
  5763. fptr1 = fopen(chargingProfiles[k], "r");
  5764. fptr2 = fopen(temp, "w+");
  5765. //Check Charging Profile Count
  5766. while(fscanf(fptr1, "%s", word) != EOF)
  5767. {
  5768. //DEBUG_INFO("word=%s\n",word);
  5769. if(strstr(word, "chargingProfileId")!= NULL)
  5770. {
  5771. n_chargingProfile = n_chargingProfile + 1;
  5772. }
  5773. }
  5774. rewind(fptr1);
  5775. //search Charging Profile Element
  5776. //int i= 0;
  5777. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5778. {
  5779. //*************************tempconnectorIdInt*********************************/
  5780. loc = strstr(sLineWord, "connectorId");
  5781. c = 0;
  5782. memset(sstr ,0, sizeof(sstr) );
  5783. while (loc[strlen("connectorId")+2+c] != ',')
  5784. {
  5785. sstr[c] = loc[strlen("connectorId")+2+c];
  5786. c++;
  5787. }
  5788. sstr[c] = '\0';
  5789. tempconnectorIdInt = atoi(sstr);
  5790. //chargingProfileId
  5791. c = 0;
  5792. loc = strstr(sLineWord, "chargingProfileId");
  5793. memset(sstr ,0, sizeof(sstr) );
  5794. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5795. {
  5796. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5797. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5798. c++;
  5799. }
  5800. sstr[c] = '\0';
  5801. tempchargingProfileIdInt = atoi(sstr);
  5802. //stackLevel
  5803. c = 0;
  5804. loc = strstr(sLineWord, "stackLevel");
  5805. memset(sstr ,0, sizeof(sstr) );
  5806. while (loc[strlen("stackLevel")+2+c] != ',')
  5807. {
  5808. sstr[c] = loc[strlen("stackLevel")+2+c];
  5809. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5810. c++;
  5811. }
  5812. sstr[c] = '\0';
  5813. tempstackLevelInt = atoi(sstr);
  5814. c = 0;
  5815. loc = strstr(sLineWord, "chargingProfilePurpose");
  5816. memset(sstr ,0, sizeof(sstr) );
  5817. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5818. {
  5819. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5820. c++;
  5821. }
  5822. sstr[c] = '\0';
  5823. strcpy(tempchargingProfilePurposeStr, sstr);
  5824. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5825. {
  5826. //------- not write to fptr2-------//
  5827. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5828. //clearflag = TRUE;
  5829. }
  5830. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5831. {
  5832. //------- not write to fptr2-------//
  5833. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5834. }
  5835. else if(stackLevelIsNULL == TRUE)
  5836. {
  5837. //Clear Whole File
  5838. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5839. clearflag = TRUE;
  5840. break;
  5841. }
  5842. else
  5843. {
  5844. fprintf(fptr2, sLineWord);//writing data into file
  5845. }
  5846. memset(sLineWord, 0, sizeof sLineWord);
  5847. }
  5848. if(clearflag == TRUE)
  5849. {
  5850. fclose(fptr1);
  5851. fclose(fptr2);
  5852. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5853. system(str);
  5854. // clear temp file
  5855. sprintf(str,"rm -f %s",temp);
  5856. system(str);
  5857. }
  5858. else
  5859. {
  5860. fclose(fptr1);
  5861. fclose(fptr2);
  5862. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5863. system(str);
  5864. resultRename = rename(temp, chargingProfiles[k]);
  5865. if(resultRename == 0)
  5866. {
  5867. DEBUG_INFO("File ChargingProfile renamed successfully");
  5868. }
  5869. else
  5870. {
  5871. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5872. }
  5873. if(comfirmstr[0]== 0)
  5874. {
  5875. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5876. }
  5877. //Check chargingProfile is empty file
  5878. /*------ Read the file ----------------*/
  5879. fptr1=fopen(chargingProfiles[k],"r");
  5880. ch=fgetc(fptr1);
  5881. rewind(fptr1);
  5882. memset(sLineWord, 0, sizeof sLineWord);
  5883. if(ch!=EOF)
  5884. {
  5885. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5886. {
  5887. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5888. if(sLineWord[0]=='\0')
  5889. {
  5890. isEmptyFile = TRUE;
  5891. break;
  5892. }
  5893. else
  5894. {
  5895. isEmptyFile = FALSE;
  5896. break;
  5897. }
  5898. }
  5899. }
  5900. fclose(fptr1);
  5901. if(isEmptyFile == TRUE)
  5902. {
  5903. memset(str, 0, sizeof str);
  5904. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5905. system(str);
  5906. }
  5907. /*------- End of reading ---------------*/
  5908. }
  5909. } // while(int k=0; k < ChargeProfileCount; k++)
  5910. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  5911. end:
  5912. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  5913. return result;
  5914. }
  5915. int handleDataTransferRequest(char *uuid, char *payload)
  5916. {
  5917. mtrace();
  5918. int result = FAIL;
  5919. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  5920. char tempvendorId[255]={0};
  5921. char tempmessageId[50]={0};
  5922. char tempdata[50]={0};
  5923. char message[80]={0};
  5924. DEBUG_INFO("handleDataTransferRequest...\n");
  5925. if((uuid != NULL) && (payload != NULL))
  5926. {
  5927. json_object *DataTransfer;
  5928. DataTransfer = json_tokener_parse(payload);
  5929. if(!is_error(DataTransfer))
  5930. {
  5931. // Required data
  5932. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  5933. // Optional data
  5934. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  5935. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  5936. if(json_object_object_get(DataTransfer, "data") != NULL)
  5937. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  5938. result = PASS;
  5939. }
  5940. json_object_put(DataTransfer);
  5941. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  5942. }
  5943. else
  5944. {
  5945. char guid[37]={0};
  5946. random_uuid(guid);
  5947. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  5948. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  5949. }
  5950. LWS_Send(message);
  5951. return result;
  5952. }
  5953. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  5954. {
  5955. mtrace();
  5956. int result = FAIL;
  5957. int connectorIdInt, durationInt;
  5958. char chargingRateUnitStr[4]={0};
  5959. char comfirmstr[20];
  5960. int confirmPeriods = 0;
  5961. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  5962. json_object *GetCompositeSchedule;
  5963. GetCompositeSchedule = json_tokener_parse(payload);
  5964. if(!is_error(GetCompositeSchedule))
  5965. {
  5966. // Required data
  5967. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  5968. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  5969. // Optional data
  5970. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  5971. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  5972. }
  5973. json_object_put(GetCompositeSchedule);
  5974. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  5975. if((connectorIdInt == 0) ||
  5976. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  5977. {
  5978. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  5979. struct StructChargingProfile tmpProfile[1];
  5980. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  5981. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  5982. {
  5983. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  5984. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  5985. }
  5986. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  5987. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  5988. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  5989. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  5990. {
  5991. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  5992. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  5993. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  5994. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  5995. {
  5996. confirmPeriods = idx;
  5997. break;
  5998. }
  5999. }
  6000. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6001. }
  6002. else
  6003. {
  6004. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6005. }
  6006. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6007. return result;
  6008. }
  6009. int handleGetConfigurationRequest(char *uuid, char *payload)
  6010. {
  6011. mtrace();
  6012. int result = FAIL;
  6013. int MaxKeySupported = 0;
  6014. int n_keys = 0;
  6015. char requestKey[43][50]={0};
  6016. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6017. json_object *GetConfiguration;
  6018. GetConfiguration = json_tokener_parse(payload);
  6019. if(!is_error(GetConfiguration))
  6020. {
  6021. // Optional data
  6022. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6023. {
  6024. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6025. {
  6026. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6027. n_keys = idx + 1;
  6028. }
  6029. }
  6030. }
  6031. json_object_put(GetConfiguration);
  6032. UnknownKeynum = 0;
  6033. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6034. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6035. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6036. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6037. if(n_keys != 0)
  6038. {
  6039. for(int i=0;i<n_keys;i++)
  6040. {
  6041. getKeyValue(requestKey[i]);
  6042. }
  6043. }
  6044. else
  6045. {
  6046. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6047. getKeyValue("");
  6048. }
  6049. processUnkownKey();
  6050. sendGetConfigurationConfirmation(uuid);
  6051. return result;
  6052. }
  6053. static char fnamePlusPath[100]={0};
  6054. static char fnamePWithNoPath[60]={0};
  6055. void checkUploadLog(void)
  6056. {
  6057. FILE *fp;
  6058. /* Open the command for reading. */
  6059. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6060. if (fp == NULL) {
  6061. printf("Failed to run command\n" );
  6062. exit(1);
  6063. }
  6064. int ftppathlen = 0;
  6065. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6066. int i = 0;
  6067. /* Read the output a line at a time - output it. */
  6068. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6069. if(i==0)
  6070. {
  6071. ftppathlen = strlen(fnamePlusPath);
  6072. printf("%s\n", fnamePlusPath);
  6073. fnamePlusPath[ftppathlen]='\0';
  6074. break;
  6075. }
  6076. i= i+1;
  6077. }
  6078. /* close */
  6079. pclose(fp);
  6080. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6081. {
  6082. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6083. {
  6084. fnamePlusPath[k]='\0';
  6085. }
  6086. }
  6087. i=1;
  6088. //char fname[60]={0};
  6089. while(i < ftppathlen)
  6090. {
  6091. int len=ftppathlen-i;
  6092. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6093. {
  6094. printf("compare '/' all right\n");
  6095. break;
  6096. }
  6097. i=i+1;
  6098. }
  6099. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6100. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6101. fnamePWithNoPath[i+1] = '\0';
  6102. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6103. {
  6104. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6105. {
  6106. fnamePWithNoPath[j]='\0';
  6107. }
  6108. }
  6109. FILE* fp1 = fopen(fnamePlusPath, "r");
  6110. if (fp1)
  6111. {
  6112. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6113. // file exists
  6114. fclose(fp1);
  6115. }
  6116. else
  6117. {
  6118. // file doesn't exist
  6119. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6120. }
  6121. }
  6122. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6123. {
  6124. mtrace();
  6125. int result = FAIL;
  6126. char cmdBuf[512];
  6127. char fName[258];
  6128. time_t CurrentTime;
  6129. struct tm *tm;
  6130. pthread_t th_Status;
  6131. CurrentTime = time(NULL);
  6132. tm = localtime(&CurrentTime);
  6133. 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);
  6134. sendGetDiagnosticsConfirmation(uuid, fName);
  6135. system("exec /root/logPackTools 'log' 6");
  6136. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6137. system(cmdBuf);
  6138. checkUploadLog();
  6139. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6140. return result;
  6141. }
  6142. void* GetDiagnosticsProcess(void* data)
  6143. {
  6144. pthread_detach(pthread_self());
  6145. mtrace();
  6146. int retriesInt=0, retryIntervalInt=0;
  6147. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6148. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6149. 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};
  6150. int port=0;
  6151. char sstr[260]={ 0 };
  6152. int c = 0;
  6153. char *loc;
  6154. int isSuccess = FALSE;
  6155. char ftpbuf[200]={0};
  6156. char * pch;
  6157. char str[300]={ 0 };
  6158. strcpy(str,(const char*)data);
  6159. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6160. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6161. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6162. //****************location*******************/
  6163. c = 0;
  6164. memset(sstr ,0, sizeof(sstr) );
  6165. loc = strstr(str, "location");
  6166. while (loc[3+strlen("location")+c] != '\"')
  6167. {
  6168. sstr[c] = loc[3+strlen("location")+c];
  6169. c++;
  6170. }
  6171. sstr[c] = '\0';
  6172. strcpy(locationstr,sstr);
  6173. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6174. if(strcmp(locationstr,"")==0)
  6175. {
  6176. DEBUG_INFO("location is <Empty>!\n");
  6177. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6178. goto end;
  6179. }
  6180. //****************retries*******************/
  6181. c = 0;
  6182. loc = strstr(str, "retries");
  6183. if(loc == NULL)
  6184. {
  6185. retriesIsNULL = TRUE;
  6186. }
  6187. else
  6188. {
  6189. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6190. {
  6191. sstr[c] = loc[strlen("retries")+2+c];
  6192. c++;
  6193. }
  6194. sstr[c] = '\0';
  6195. retriesInt = atoi(sstr);
  6196. }
  6197. if(retriesIsNULL == TRUE)
  6198. {
  6199. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6200. }
  6201. //****************retryInterval*******************/
  6202. c = 0;
  6203. loc = strstr(str, "retryInterval");
  6204. if(loc == NULL)
  6205. {
  6206. retryIntervalIsNULL = TRUE;
  6207. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6208. }
  6209. else
  6210. {
  6211. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6212. {
  6213. sstr[c] = loc[strlen("retryInterval")+2+c];
  6214. c++;
  6215. }
  6216. sstr[c] = '\0';
  6217. retryIntervalInt = atoi(sstr);
  6218. }
  6219. //****************startTime*******************/
  6220. c = 0;
  6221. memset(sstr ,0, sizeof(sstr) );
  6222. loc = strstr(str, "startTime");
  6223. if(loc == NULL)
  6224. {
  6225. startTimeIsNULL = TRUE;
  6226. }
  6227. else
  6228. {
  6229. while (loc[3+strlen("startTime")+c] != '\"')
  6230. {
  6231. sstr[c] = loc[3+strlen("startTime")+c];
  6232. c++;
  6233. }
  6234. sstr[c] = '\0';
  6235. strcpy(startTimestr,sstr);
  6236. }
  6237. //****************stopTime*******************/
  6238. c = 0;
  6239. memset(sstr ,0, sizeof(sstr) );
  6240. loc = strstr(str, "stopTime");
  6241. if(loc == NULL)
  6242. {
  6243. stopTimeIsNULL = TRUE;
  6244. }
  6245. else
  6246. {
  6247. while (loc[3+strlen("stopTime")+c] != '\"')
  6248. {
  6249. sstr[c] = loc[3+strlen("stopTime")+c];
  6250. c++;
  6251. }
  6252. sstr[c] = '\0';
  6253. strcpy(stopTimestr,sstr);
  6254. }
  6255. memset(protocol, 0, sizeof(protocol));
  6256. memset(user, 0, sizeof(user) );
  6257. memset(password, 0, sizeof(password));
  6258. memset(host, 0, sizeof(host));
  6259. memset(path, 0, sizeof(path));
  6260. memset(ftppath, 0, sizeof(ftppath));
  6261. memset(host1, 0, sizeof(host1));
  6262. memset(path1, 0, sizeof(path1));
  6263. /*location: ftp://user:password@host:port/path*/
  6264. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6265. if((access(fnamePlusPath,F_OK))!=-1)
  6266. {
  6267. DEBUG_INFO("fnamePlusPath exist.\n");
  6268. }
  6269. else
  6270. {
  6271. DEBUG_INFO("fnamePlusPath not exist!\n");
  6272. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6273. goto end;
  6274. }
  6275. pch=strchr(locationstr,'@');
  6276. if(pch==NULL)
  6277. {
  6278. sscanf(locationstr,
  6279. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6280. protocol, host, &port, path);
  6281. strcpy(user,"anonymous");
  6282. strcpy(password,"");
  6283. }
  6284. else
  6285. {
  6286. //DEBUG_INFO("pch=%s\n", pch);
  6287. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6288. protocol, user, password, host, &port, path);
  6289. }
  6290. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6291. {
  6292. DEBUG_INFO("protocol is not ftp/http ! \n");
  6293. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6294. goto end;
  6295. }
  6296. if(strncmp(locationstr,"http", 4) == 0)
  6297. {
  6298. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6299. sprintf(ftppath,"/%s", path);
  6300. do{
  6301. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6302. sleep(retryIntervalInt);
  6303. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6304. if(!isSuccess)
  6305. {
  6306. DEBUG_INFO("Diagnostics fail.\n");
  6307. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6308. }
  6309. else
  6310. {
  6311. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6312. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6313. }
  6314. }
  6315. else
  6316. {
  6317. sscanf(host,"%[^/]%s",host1, path1);
  6318. sprintf(ftppath,"%s", path1);
  6319. int ftppathlen=strlen(ftppath);
  6320. int i=1;
  6321. char filenametemp[50];
  6322. while(i < ftppathlen)
  6323. {
  6324. int len=ftppathlen-i;
  6325. if(ftppath[len]== 47) // '/' ascll code: 47
  6326. {
  6327. DEBUG_INFO("find '/' all right\n");
  6328. break;
  6329. }
  6330. i=i+1;
  6331. }
  6332. memset(filenametemp, 0, sizeof(filenametemp));
  6333. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6334. filenametemp[i+1] = 0;
  6335. memset(ftpbuf, 0, sizeof(ftpbuf));
  6336. if(port == 0)
  6337. port = 21;
  6338. do{
  6339. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6340. sleep(retryIntervalInt);
  6341. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6342. if(!isSuccess)
  6343. {
  6344. DEBUG_INFO("Diagnostics fail.\n");
  6345. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6346. }
  6347. else
  6348. {
  6349. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6350. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6351. }
  6352. }
  6353. end:
  6354. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6355. pthread_exit(NULL);
  6356. }
  6357. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6358. {
  6359. mtrace();
  6360. int result = FAIL;
  6361. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6362. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6363. {
  6364. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6365. localversion = -1;
  6366. }
  6367. else
  6368. {
  6369. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6370. OCPP_getListVerion();
  6371. }
  6372. //from db.OCPP_getListVerion
  6373. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6374. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6375. sendGetLocalListVersionConfirmation(uuid,"");
  6376. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6377. return result;
  6378. }
  6379. int handleRemoteStartRequest(char *uuid, char *payload)
  6380. {
  6381. mtrace();
  6382. int result = FAIL;
  6383. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6384. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6385. int tempIndex = 0;
  6386. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6387. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6388. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6389. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6390. int chargingSchedulePeriodCount = 0;
  6391. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6392. int c = 0;
  6393. char *loc;
  6394. char comfirmstr[20]={0};
  6395. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6396. if(server_pending == TRUE)
  6397. {
  6398. return 0;
  6399. }
  6400. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6401. strcpy(sstrtemp, stringtrimspace(payload));
  6402. //**********connectorId****************/
  6403. c = 0;
  6404. memset(sstr ,0, sizeof(sstr) );
  6405. loc = strstr(sstrtemp, "connectorId");
  6406. if(loc == NULL)
  6407. {
  6408. connectorIdIsNULL = TRUE;
  6409. }
  6410. else
  6411. {
  6412. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6413. {
  6414. sstr[c] = loc[strlen("connectorId")+2+c];
  6415. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6416. c++;
  6417. }
  6418. sstr[c] = '\0';
  6419. connectorIdInt = atoi(sstr);
  6420. }
  6421. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6422. {
  6423. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6424. goto end;
  6425. }
  6426. //****************idTag*******************/
  6427. c = 0;
  6428. memset(sstr ,0, sizeof(sstr) );
  6429. loc = strstr(sstrtemp, "idTag");
  6430. while (loc[3+strlen("idTag")+c] != '\"')
  6431. {
  6432. sstr[c] = loc[3+strlen("idTag")+c];
  6433. c++;
  6434. }
  6435. sstr[c] = '\0';
  6436. strcpy(idTagstr,sstr);
  6437. //****************chargingProfile*******************/
  6438. c = 0;
  6439. memset(sstr ,0, sizeof(sstr) );
  6440. loc = strstr(sstrtemp, "chargingProfile");
  6441. if(loc == NULL)
  6442. {
  6443. chargingProfileIsNULL = TRUE;
  6444. }
  6445. else
  6446. {
  6447. //****************chargingProfileId*******************/
  6448. c=0;
  6449. loc = strstr(sstrtemp, "chargingProfileId");
  6450. memset(sstr ,0, sizeof(sstr) );
  6451. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6452. {
  6453. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6454. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6455. c++;
  6456. }
  6457. sstr[c] = '\0';
  6458. chargingProfileIdInt = atoi(sstr);
  6459. //****************transactionId*******************/
  6460. loc = strstr(sstrtemp, "transactionId");
  6461. if(loc == NULL)
  6462. {
  6463. transactionIdIsNULL = TRUE;
  6464. }
  6465. else
  6466. {
  6467. c=0;
  6468. memset(sstr ,0, sizeof(sstr) );
  6469. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6470. {
  6471. sstr[c] = loc[strlen("transactionId")+2+c];
  6472. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6473. c++;
  6474. }
  6475. sstr[c] = '\0';
  6476. transactionIdInt = atoi(sstr);
  6477. }
  6478. //****************stackLevel*******************/
  6479. c=0;
  6480. loc = strstr(sstrtemp, "stackLevel");
  6481. memset(sstr ,0, sizeof(sstr) );
  6482. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6483. {
  6484. sstr[c] = loc[strlen("stackLevel")+2+c];
  6485. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6486. c++;
  6487. }
  6488. sstr[c] = '\0';
  6489. stackLevelInt = atoi(sstr);
  6490. //****************chargingProfilePurpose*******************/
  6491. c = 0;
  6492. memset(sstr ,0, sizeof(sstr) );
  6493. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6494. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6495. {
  6496. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6497. c++;
  6498. }
  6499. sstr[c] = '\0';
  6500. strcpy(chargingProfilePurposestr,sstr);
  6501. //****************chargingProfileKind*******************/
  6502. c = 0;
  6503. memset(sstr ,0, sizeof(sstr) );
  6504. loc = strstr(sstrtemp, "chargingProfileKind");
  6505. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6506. {
  6507. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6508. c++;
  6509. }
  6510. sstr[c] = '\0';
  6511. strcpy(chargingProfileKindstr,sstr);
  6512. //****************recurrencyKind*******************/
  6513. loc = strstr(sstrtemp, "recurrencyKind");
  6514. if(loc == NULL)
  6515. {
  6516. recurrencyKindIsNULL = TRUE;
  6517. }
  6518. else
  6519. {
  6520. c = 0;
  6521. memset(sstr ,0, sizeof(sstr) );
  6522. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6523. {
  6524. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6525. c++;
  6526. }
  6527. sstr[c] = '\0';
  6528. strcpy(recurrencyKindstr,sstr);
  6529. }
  6530. //****************validFrom*******************/
  6531. loc = strstr(sstrtemp, "validFrom");
  6532. if(loc == NULL)
  6533. {
  6534. validFromIsNULL = TRUE;
  6535. }
  6536. else
  6537. {
  6538. c = 0;
  6539. memset(sstr ,0, sizeof(sstr) );
  6540. while (loc[3+strlen("validFrom")+c] != '\"')
  6541. {
  6542. sstr[c] = loc[3+strlen("validFrom")+c];
  6543. c++;
  6544. }
  6545. sstr[c] = '\0';
  6546. strcpy(validFromstr,sstr);
  6547. }
  6548. //****************validTo*******************/
  6549. loc = strstr(sstrtemp, "validTo");
  6550. if(loc == NULL)
  6551. {
  6552. validToIsNULL = TRUE;
  6553. }
  6554. else
  6555. {
  6556. c = 0;
  6557. memset(sstr ,0, sizeof(sstr) );
  6558. while (loc[3+strlen("validTo")+c] != '\"')
  6559. {
  6560. sstr[c] = loc[3+strlen("validTo")+c];
  6561. c++;
  6562. }
  6563. sstr[c] = '\0';
  6564. strcpy(validTostr,sstr);
  6565. }
  6566. //****************chargingSchedule*******************/
  6567. loc = strstr(sstrtemp, "chargingSchedule");
  6568. if(loc != NULL)
  6569. {
  6570. //****************duration*******************/
  6571. loc = strstr(sstrtemp, "duration");
  6572. if(loc == NULL)
  6573. {
  6574. durationIsNULL = TRUE;
  6575. }
  6576. else
  6577. {
  6578. c=0;
  6579. memset(sstr ,0, sizeof(sstr) );
  6580. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6581. {
  6582. sstr[c] = loc[strlen("duration")+2+c];
  6583. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6584. c++;
  6585. }
  6586. sstr[c] = '\0';
  6587. durationInt = atoi(sstr);
  6588. }
  6589. //****************startSchedule******************/
  6590. loc = strstr(sstrtemp, "startSchedule");
  6591. if(loc == NULL)
  6592. {
  6593. startScheduleIsNULL = TRUE;
  6594. }
  6595. else
  6596. {
  6597. c = 0;
  6598. memset(sstr ,0, sizeof(sstr) );
  6599. while (loc[3+strlen("startSchedule")+c] != '\"')
  6600. {
  6601. sstr[c] = loc[3+strlen("startSchedule")+c];
  6602. c++;
  6603. }
  6604. sstr[c] = '\0';
  6605. strcpy(startSchedulestr,sstr);
  6606. }
  6607. //****************chargingRateUnit*******************/
  6608. c = 0;
  6609. memset(sstr ,0, sizeof(sstr) );
  6610. loc = strstr(sstrtemp, "chargingRateUnit");
  6611. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6612. {
  6613. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6614. c++;
  6615. }
  6616. sstr[c] = '\0';
  6617. strcpy(chargingRateUnitstr,sstr);
  6618. //****************minChargingRate*******************/
  6619. loc = strstr(sstrtemp, "minChargingRate");
  6620. if(loc == NULL)
  6621. {
  6622. minChargingRateIsNULL = TRUE;
  6623. }
  6624. else
  6625. {
  6626. c=0;
  6627. memset(sstr ,0, sizeof(sstr) );
  6628. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6629. {
  6630. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6631. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6632. c++;
  6633. }
  6634. sstr[c] = '\0';
  6635. minChargingRateflaot = atof(sstr);
  6636. }
  6637. //****************chargingSchedulePeriod count*******************/
  6638. int what_len = strlen("startPeriod");
  6639. char *where = sstrtemp;
  6640. while ((where = strstr(where, "startPeriod"))) {
  6641. where += what_len;
  6642. chargingSchedulePeriodCount++;
  6643. }
  6644. where = sstrtemp;
  6645. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6646. {
  6647. //****************startPeriod*******************/
  6648. c=0;
  6649. loc = strstr(where, "startPeriod");
  6650. memset(sstr ,0, sizeof(sstr) );
  6651. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6652. {
  6653. sstr[c] = loc[strlen("startPeriod")+2+c];
  6654. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6655. c++;
  6656. }
  6657. sstr[c] = '\0';
  6658. startPeriodInt[periodNums] = atoi(sstr);
  6659. //****************limit*******************/
  6660. c=0;
  6661. loc = strstr(where, "limit");
  6662. memset(sstr ,0, sizeof(sstr) );
  6663. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6664. {
  6665. sstr[c] = loc[strlen("limit")+2+c];
  6666. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6667. c++;
  6668. }
  6669. sstr[c] = '\0';
  6670. limitflaot[periodNums] = atof(sstr);
  6671. //****************numberPhases*******************/
  6672. loc = strstr(where, "numberPhases");
  6673. if(loc == NULL)
  6674. {
  6675. numberPhasesIsNULL = TRUE;
  6676. }
  6677. else
  6678. {
  6679. c=0;
  6680. memset(sstr ,0, sizeof(sstr) );
  6681. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6682. {
  6683. sstr[c] = loc[strlen("numberPhases")+2+c];
  6684. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6685. c++;
  6686. }
  6687. sstr[c] = '\0';
  6688. numberPhasesInt[periodNums] = atoi(sstr);
  6689. }
  6690. where = loc;
  6691. } // END FOR chargingSchedulePeriodCount
  6692. }// END IF chargingSchedule
  6693. } // END chargingProfile
  6694. /*
  6695. enum _SYSTEM_STATUS
  6696. {
  6697. S_BOOTING = 0,
  6698. S_IDLE, = 1
  6699. S_AUTHORIZING, =2
  6700. S_REASSIGN_CHECK, =3
  6701. S_REASSIGN, =4
  6702. S_PRECHARGE, =5
  6703. S_PREPARING_FOR_EV, =6
  6704. S_PREPARING_FOR_EVSE, =7
  6705. S_CHARGING, =8
  6706. S_TERMINATING, =9
  6707. S_COMPLETE, =10
  6708. S_ALARM, =11
  6709. S_FAULT =12
  6710. }
  6711. */
  6712. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6713. {
  6714. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6715. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6716. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6717. //check Transaction active
  6718. if(gunType[connectorIdInt -1] == 'J')
  6719. {
  6720. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6721. {
  6722. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6723. }
  6724. else
  6725. {
  6726. tempIndex = connectorIdInt -1;
  6727. }
  6728. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6729. {
  6730. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6731. {
  6732. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6733. {
  6734. //Reserved
  6735. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6736. }
  6737. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6738. {
  6739. //Reserved
  6740. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6741. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6742. goto end;
  6743. }
  6744. else
  6745. {
  6746. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6747. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6748. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6749. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6750. {
  6751. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6752. goto end;
  6753. }
  6754. }//END FOR ELSE
  6755. }
  6756. }// END FOR CHAdeMO_QUANTITY
  6757. }
  6758. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6759. {
  6760. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6761. {
  6762. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6763. }
  6764. else
  6765. {
  6766. tempIndex = connectorIdInt -1;
  6767. }
  6768. for (int index = 0; index < CCS_QUANTITY; index++)
  6769. {
  6770. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6771. {
  6772. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6773. {
  6774. //Reserved
  6775. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6776. }
  6777. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6778. {
  6779. //Reserved
  6780. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6781. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6782. goto end;
  6783. }
  6784. else
  6785. {
  6786. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6787. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6788. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6789. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6790. {
  6791. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6792. goto end;
  6793. }
  6794. }// END FOR ELSE
  6795. }
  6796. }// END FOR CCS_QUANTITY
  6797. }
  6798. else if(gunType[connectorIdInt -1] == 'G')
  6799. {
  6800. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6801. {
  6802. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6803. }
  6804. else
  6805. {
  6806. tempIndex = connectorIdInt -1;
  6807. }
  6808. for (int index = 0; index < GB_QUANTITY; index++)
  6809. {
  6810. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6811. {
  6812. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6813. {
  6814. //Reserved
  6815. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6816. }
  6817. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6818. {
  6819. //Reserved
  6820. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6821. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6822. goto end;
  6823. }
  6824. else
  6825. {
  6826. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6827. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6828. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6829. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6830. {
  6831. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6832. goto end;
  6833. }
  6834. }// END FOR ELSE
  6835. }
  6836. } // END FOR GB_QUANTITY
  6837. }
  6838. else
  6839. {
  6840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6841. {
  6842. tempIndex = 2;
  6843. }
  6844. else
  6845. {
  6846. tempIndex = connectorIdInt -1;
  6847. }
  6848. for (int index = 0; index < AC_QUANTITY; index++)
  6849. {
  6850. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6851. {
  6852. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6853. {
  6854. //Reserved
  6855. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6856. }
  6857. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6858. {
  6859. //Reserved
  6860. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6861. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6862. goto end;
  6863. }
  6864. else
  6865. {
  6866. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6867. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6868. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6869. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6870. {
  6871. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6872. goto end;
  6873. }
  6874. }//END FOR ELSE
  6875. }
  6876. }// END FOR AC_QUANTITY
  6877. }
  6878. if(chargingProfileIsNULL == FALSE)
  6879. {
  6880. //ChargingProfile
  6881. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  6882. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  6883. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  6884. if(recurrencyKindIsNULL == FALSE) //OPTION
  6885. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  6886. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  6887. if(transactionIdIsNULL == FALSE) // OPTION
  6888. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6889. if(validFromIsNULL == FALSE) // OPTION
  6890. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  6891. if(validToIsNULL == FALSE) //OPTION
  6892. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  6893. //ChargingSchedule
  6894. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  6895. if(durationIsNULL == FALSE) //OPTION
  6896. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  6897. if(minChargingRateIsNULL == FALSE) //OPTION
  6898. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  6899. if(startScheduleIsNULL == FALSE) //OPTION
  6900. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  6901. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6902. {
  6903. //ChargingSchedulePeriod
  6904. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  6905. if(numberPhasesIsNULL == FALSE)
  6906. {
  6907. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  6908. }
  6909. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  6910. }
  6911. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  6912. {
  6913. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6914. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6915. //memset idTag
  6916. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6917. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6918. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6919. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6920. }
  6921. else
  6922. {
  6923. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6924. }
  6925. }
  6926. else
  6927. {
  6928. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  6929. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  6930. //memset idTag
  6931. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  6932. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6933. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  6934. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  6935. }
  6936. }
  6937. else
  6938. {
  6939. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6940. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6941. }
  6942. end:
  6943. if(connectorIdIsNULL == FALSE)
  6944. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  6945. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  6946. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  6947. //OCPP send RemoteStartConfirmation by first.
  6948. sendRemoteStartConfirmation(uuid, comfirmstr);
  6949. return result;
  6950. }
  6951. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  6952. {
  6953. mtrace();
  6954. int result = FAIL;
  6955. int match = FALSE;
  6956. int GunNO = 0;
  6957. int tempIndex = 0;
  6958. int transactionIdInt=0;
  6959. int transactionIdIsNULL= FALSE;
  6960. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  6961. int c = 0;
  6962. char *loc;
  6963. char comfirmstr[20];
  6964. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  6965. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  6966. if(server_pending == TRUE)
  6967. {
  6968. return 0;
  6969. }
  6970. strcpy(sstrtemp, stringtrimspace(payload));
  6971. c=0;
  6972. loc = strstr(sstrtemp, "transactionId");
  6973. if(loc == NULL)
  6974. {
  6975. transactionIdIsNULL= TRUE;
  6976. }
  6977. else
  6978. {
  6979. memset(sstr ,0, sizeof(sstr) );
  6980. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6981. {
  6982. sstr[c] = loc[strlen("transactionId")+2+c];
  6983. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6984. c++;
  6985. }
  6986. sstr[c] = '\0';
  6987. transactionIdInt = atoi(sstr);
  6988. }
  6989. if(transactionIdIsNULL == FALSE)
  6990. {
  6991. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  6992. {
  6993. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  6994. {
  6995. //check Transaction active
  6996. if(gunType[gun_index] == 'J')
  6997. {
  6998. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6999. {
  7000. tempIndex = ((gun_index==2) ? 1: 0);
  7001. }
  7002. else
  7003. {
  7004. tempIndex = gun_index;
  7005. }
  7006. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7007. {
  7008. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7009. {
  7010. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7011. {
  7012. match = TRUE;
  7013. GunNO = gun_index;
  7014. }
  7015. }
  7016. }// END FOR CHAdeMO_QUANTITY
  7017. }
  7018. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7019. {
  7020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7021. {
  7022. tempIndex = ((gun_index==2) ? 1: 0);
  7023. }
  7024. else
  7025. {
  7026. tempIndex = gun_index;
  7027. }
  7028. for (int index = 0; index < CCS_QUANTITY; index++)
  7029. {
  7030. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7031. {
  7032. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7033. {
  7034. match = TRUE;
  7035. GunNO = gun_index;
  7036. }
  7037. }
  7038. }// END FOR CCS_QUANTITY
  7039. }
  7040. else if(gunType[gun_index] == 'G')
  7041. {
  7042. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7043. {
  7044. tempIndex = ((gun_index==2) ? 1: 0);
  7045. }
  7046. else
  7047. {
  7048. tempIndex = gun_index;
  7049. }
  7050. for (int index = 0; index < GB_QUANTITY; index++)
  7051. {
  7052. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7053. {
  7054. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7055. {
  7056. match = TRUE;
  7057. GunNO = gun_index;
  7058. }
  7059. }
  7060. }// END FOR GB_QUANTITY
  7061. }
  7062. else
  7063. {
  7064. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7065. {
  7066. tempIndex = 2;
  7067. }
  7068. else
  7069. {
  7070. tempIndex = gun_index;
  7071. }
  7072. for (int index = 0; index < AC_QUANTITY; index++)
  7073. {
  7074. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7075. {
  7076. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7077. {
  7078. match = TRUE;
  7079. GunNO = gun_index;
  7080. }
  7081. }
  7082. }// END FOR CHAdeMO_QUANTITY
  7083. } // END FOR AC ELSE
  7084. }// CHECK IF ResponseTransactionId == transactionIdInt
  7085. }//END FOR
  7086. if( match == TRUE)
  7087. {
  7088. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7090. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7091. }
  7092. else
  7093. {
  7094. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7095. }
  7096. }
  7097. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7098. return result;
  7099. }
  7100. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7101. {
  7102. mtrace();
  7103. int result = FAIL;
  7104. int connectorIdInt=0, reservationIdInt=0;
  7105. int tempIndex = 0;
  7106. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7107. char comfirmstr[20]={0};
  7108. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7109. int c = 0;
  7110. char *loc;
  7111. //char *ptr;
  7112. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7113. strcpy(sstrtemp, stringtrimspace(payload));
  7114. //***(1)connectorId ****/
  7115. c=0;
  7116. loc = strstr(sstrtemp, "connectorId");
  7117. memset(sstr ,0, sizeof(sstr) );
  7118. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7119. {
  7120. sstr[c] = loc[strlen("connectorId")+2+c];
  7121. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7122. c++;
  7123. }
  7124. sstr[c] = '\0';
  7125. connectorIdInt = atoi(sstr);
  7126. //***(2)expiryDate ****/
  7127. loc = strstr(sstrtemp, "expiryDate");
  7128. memset(sstr ,0, sizeof(sstr) );
  7129. c = 0;
  7130. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7131. {
  7132. sstr[c] = loc[3+strlen("expiryDate")+c];
  7133. c++;
  7134. }
  7135. sstr[c] = '\0';
  7136. strcpy(expiryDatestr, sstr);
  7137. //***(3)idTag ****/
  7138. loc = strstr(sstrtemp, "idTag");
  7139. memset(sstr ,0, sizeof(sstr) );
  7140. c = 0;
  7141. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7142. {
  7143. sstr[c] = loc[3+strlen("idTag")+c];
  7144. c++;
  7145. }
  7146. sstr[c] = '\0';
  7147. strcpy(idTagstr, sstr);
  7148. //***(4)parentIdTag ****/
  7149. loc = strstr(sstrtemp, "parentIdTag");
  7150. memset(sstr ,0, sizeof(sstr) );
  7151. c = 0;
  7152. if(loc == NULL)
  7153. {
  7154. strcpy(parentIdTagstr, "");
  7155. }
  7156. else
  7157. {
  7158. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7159. {
  7160. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7161. c++;
  7162. }
  7163. sstr[c] = '\0';
  7164. strcpy(parentIdTagstr, sstr);
  7165. }
  7166. //***(5)reservationId ****/
  7167. c=0;
  7168. loc = strstr(sstrtemp, "reservationId");
  7169. memset(sstr ,0, sizeof(sstr) );
  7170. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7171. {
  7172. sstr[c] = loc[strlen("reservationId")+2+c];
  7173. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7174. c++;
  7175. }
  7176. sstr[c] = '\0';
  7177. reservationIdInt = atoi(sstr);
  7178. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7179. /*
  7180. enum SYSTEM_STATUS
  7181. {
  7182. SYS_MODE_BOOTING = 0,
  7183. SYS_MODE_IDLE = 1,
  7184. SYS_MODE_AUTHORIZING = 2,
  7185. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7186. SYS_MODE_REASSIGN = 4,
  7187. SYS_MODE_PREPARING = 5,
  7188. SYS_MODE_PREPARE_FOR_EV = 6,
  7189. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7190. SYS_MODE_CHARGING = 8,
  7191. SYS_MODE_TERMINATING = 9,
  7192. SYS_MODE_COMPLETE = 10,
  7193. SYS_MODE_ALARM = 11,
  7194. SYS_MODE_FAULT = 12,
  7195. SYS_MODE_RESERVATION = 13,
  7196. SYS_MODE_BOOKING = 14,
  7197. SYS_MODE_MAINTAIN = 15,
  7198. SYS_MODE_DEBUG = 16,
  7199. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7200. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7201. SYS_MODE_UPDATE = 19
  7202. };
  7203. */
  7204. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7205. {
  7206. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7207. goto end;
  7208. }
  7209. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7210. {
  7211. //check Transaction active
  7212. if(gunType[connectorIdInt -1] == 'J')
  7213. {
  7214. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7215. {
  7216. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7217. }
  7218. else
  7219. {
  7220. tempIndex = connectorIdInt -1;
  7221. }
  7222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7223. {
  7224. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7225. {
  7226. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7227. {
  7228. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7229. {
  7230. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7231. {
  7232. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7233. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7234. }
  7235. 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'))
  7236. {
  7237. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7238. }
  7239. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7240. {
  7241. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7242. }
  7243. else
  7244. {
  7245. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7246. }
  7247. }
  7248. 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
  7249. {
  7250. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7251. }
  7252. }
  7253. else
  7254. {
  7255. //replace reservation
  7256. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7257. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7258. }
  7259. }
  7260. } // END FOR CHAdeMO_QUANTITY
  7261. }
  7262. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7263. {
  7264. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7265. {
  7266. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7267. }
  7268. else
  7269. {
  7270. tempIndex = connectorIdInt -1;
  7271. }
  7272. for (int index = 0; index < CCS_QUANTITY; index++)
  7273. {
  7274. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7275. {
  7276. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7277. {
  7278. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7279. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7280. {
  7281. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7282. {
  7283. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7284. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7285. }
  7286. 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'))
  7287. {
  7288. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7289. }
  7290. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7291. {
  7292. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7293. }
  7294. else
  7295. {
  7296. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7297. }
  7298. }
  7299. 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
  7300. {
  7301. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7302. }
  7303. }
  7304. else
  7305. {
  7306. //replace reservation
  7307. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7308. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7309. }
  7310. }
  7311. } // END FOR CCS_QUANTITY
  7312. }
  7313. else if(gunType[connectorIdInt -1] == 'G')
  7314. {
  7315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7316. {
  7317. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7318. }
  7319. else
  7320. {
  7321. tempIndex = connectorIdInt -1;
  7322. }
  7323. for (int index = 0; index < GB_QUANTITY; index++)
  7324. {
  7325. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7326. {
  7327. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7328. {
  7329. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7330. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7331. {
  7332. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7333. {
  7334. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7335. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7336. }
  7337. 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'))
  7338. {
  7339. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7340. }
  7341. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7342. {
  7343. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7344. }
  7345. else
  7346. {
  7347. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7348. }
  7349. }
  7350. 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
  7351. {
  7352. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7353. }
  7354. }
  7355. else
  7356. {
  7357. //replace reservation
  7358. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7359. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7360. }
  7361. }
  7362. }// END FOR GB_QUANTITY
  7363. }
  7364. else
  7365. {
  7366. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7367. {
  7368. tempIndex = 2;
  7369. }
  7370. else
  7371. {
  7372. tempIndex = (connectorIdInt -1);
  7373. }
  7374. for (int index = 0; index < AC_QUANTITY; index++)
  7375. {
  7376. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7377. {
  7378. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7379. {
  7380. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7381. {
  7382. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7383. {
  7384. 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))
  7385. {
  7386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7387. }
  7388. else
  7389. {
  7390. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7391. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7392. }
  7393. }
  7394. 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'))
  7395. {
  7396. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7397. }
  7398. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7399. {
  7400. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7401. }
  7402. else
  7403. {
  7404. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7405. }
  7406. }
  7407. 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
  7408. {
  7409. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7410. }
  7411. }
  7412. else
  7413. {
  7414. //replace reservation
  7415. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7416. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7417. }
  7418. }
  7419. } // END FOR AC_QUANTITY
  7420. }
  7421. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7422. }
  7423. else if(connectorIdInt == 0)
  7424. {
  7425. //check Transaction active
  7426. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7427. {
  7428. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7429. {
  7430. 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'))
  7431. {
  7432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7433. goto end;
  7434. }
  7435. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7436. {
  7437. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7438. goto end;
  7439. }
  7440. 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
  7441. {
  7442. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7443. goto end;
  7444. }
  7445. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7446. {
  7447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7448. goto end;
  7449. }
  7450. }
  7451. }// END FOR CHAdeMO_QUANTITY
  7452. for (int index = 0; index < CCS_QUANTITY; index++)
  7453. {
  7454. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7455. {
  7456. 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'))
  7457. {
  7458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7459. goto end;
  7460. }
  7461. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7462. {
  7463. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7464. goto end;
  7465. }
  7466. 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
  7467. {
  7468. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7469. goto end;
  7470. }
  7471. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7472. {
  7473. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7474. goto end;
  7475. }
  7476. }
  7477. } // END FOR CCS_QUANTITY
  7478. for (int index = 0; index < GB_QUANTITY; index++)
  7479. {
  7480. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7481. {
  7482. 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'))
  7483. {
  7484. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7485. goto end;
  7486. }
  7487. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7488. {
  7489. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7490. goto end;
  7491. }
  7492. 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
  7493. {
  7494. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7495. goto end;
  7496. }
  7497. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7498. {
  7499. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7500. goto end;
  7501. }
  7502. }
  7503. } // END FOR GB_QUANTITY
  7504. for (int index = 0; index < AC_QUANTITY; index++)
  7505. {
  7506. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7507. {
  7508. 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'))
  7509. {
  7510. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7511. goto end;
  7512. }
  7513. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7514. {
  7515. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7516. goto end;
  7517. }
  7518. 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
  7519. {
  7520. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7521. goto end;
  7522. }
  7523. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7524. {
  7525. 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))
  7526. {
  7527. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7528. goto end;
  7529. }
  7530. }
  7531. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7532. {
  7533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7534. goto end;
  7535. }
  7536. }
  7537. }// END FOR AC_QUANTITY
  7538. //The connectorId is 0
  7539. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7540. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7541. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7542. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7543. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7544. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7545. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7546. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7547. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7548. result = TRUE;
  7549. return result;
  7550. }
  7551. else
  7552. {
  7553. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7554. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7555. }
  7556. if(strcmp(comfirmstr,"Accepted") == 0)
  7557. {
  7558. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7559. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7560. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7561. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7562. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7563. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7564. result = TRUE;
  7565. return result;
  7566. }
  7567. end:
  7568. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7569. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7570. return result;
  7571. }
  7572. int handleResetRequest(char *uuid, char *payload)
  7573. {
  7574. mtrace();
  7575. int result = FAIL;
  7576. char sstr[10]={0},sstrtemp[30]={ 0 };
  7577. char typestr[10]={0};
  7578. char comfirmstr[20]={0};
  7579. int c = 0;
  7580. char *loc;
  7581. DEBUG_INFO("handleResetRequest...\n");
  7582. strcpy(sstrtemp, stringtrimspace(payload));
  7583. loc = strstr(sstrtemp, "type");
  7584. memset(sstr ,0, sizeof(sstr) );
  7585. c = 0;
  7586. while (loc[3+strlen("type")+c] != '\"')
  7587. {
  7588. sstr[c] = loc[3+strlen("type")+c];
  7589. c++;
  7590. }
  7591. sstr[c] = '\0';
  7592. strcpy(typestr,sstr);
  7593. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7594. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7595. {
  7596. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7597. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7598. result = TRUE;
  7599. return result;
  7600. }
  7601. else
  7602. {
  7603. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7604. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7605. goto errorend;
  7606. }
  7607. errorend:
  7608. sendResetConfirmation(uuid, comfirmstr);
  7609. return result;
  7610. }
  7611. int handleSendLocalListRequest(char *uuid, char *payload)
  7612. {
  7613. mtrace();
  7614. int result = FAIL;
  7615. int listVersionInt;
  7616. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7617. char listsearch[]="listVersion";
  7618. char updateTypesearch[]="updateType";
  7619. char localAuthorizationListsearch[]="localAuthorizationList";
  7620. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7621. char CardList[500][160]={0};
  7622. char updateTypestr[15]={0};
  7623. char idTagstr[20]={0};
  7624. char parentIdTag[20]={0};
  7625. char expiryDate[30]={0};
  7626. char idTagstatus[16]={0};
  7627. int c = 0;
  7628. int i = 0;
  7629. char *delim1 = "}";
  7630. char * pch;
  7631. char *loc;
  7632. //char *ptr;
  7633. char comfirmstr[20];
  7634. //int n_localAuthorizations = 0;
  7635. int checkState_Faulted = FALSE;
  7636. DEBUG_INFO("handleSendLocalListRequest...\n");
  7637. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7638. {
  7639. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7640. goto end;
  7641. }
  7642. //check Charge Point state
  7643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7644. {
  7645. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7646. {
  7647. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7648. }
  7649. }
  7650. for (int index = 0; index < CCS_QUANTITY; index++)
  7651. {
  7652. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7653. {
  7654. checkState_Faulted = TRUE; //OCPP Status
  7655. }
  7656. }
  7657. for (int index = 0; index < GB_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7660. {
  7661. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7662. }
  7663. }
  7664. //check Charge Point state
  7665. for (int index = 0; index < AC_QUANTITY; index++)
  7666. {
  7667. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7668. {
  7669. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7670. }
  7671. }
  7672. if(checkState_Faulted == TRUE)
  7673. {
  7674. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7675. goto end;
  7676. }
  7677. //Filter payload space
  7678. strcpy(sstrtemp, stringtrimspace(payload));
  7679. //listVersion
  7680. c = 0;
  7681. loc = strstr(sstrtemp, listsearch);
  7682. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7683. {
  7684. sstr[c] = loc[strlen("listVersion")+2+c];
  7685. c++;
  7686. }
  7687. sstr[c] = '\0';
  7688. listVersionInt = atoi(sstr);
  7689. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7690. //updateType
  7691. loc = strstr(sstrtemp, updateTypesearch);
  7692. c = 0;
  7693. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7694. {
  7695. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7696. c++;
  7697. }
  7698. sstr[c] = '\0';
  7699. strcpy(updateTypestr, sstr);
  7700. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7701. //localAuthorizationList
  7702. memset(sstr ,0, sizeof(sstr) );
  7703. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7704. if(loc != NULL) // localAuthorizationList is not NULL
  7705. {
  7706. //Check UpdateType
  7707. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7708. {
  7709. //Local list full update
  7710. printf("Local list full update.\n");
  7711. OCPP_getListVerion();
  7712. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7713. {
  7714. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7715. goto end;
  7716. }
  7717. OCPP_cleanLocalList();
  7718. }
  7719. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7720. {
  7721. //Local list different update
  7722. printf("Local list different update.\n");
  7723. OCPP_getListVerion();
  7724. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7725. {
  7726. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7727. goto end;
  7728. }
  7729. }
  7730. else
  7731. {
  7732. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7733. goto end;
  7734. }
  7735. c = 0;
  7736. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7737. {
  7738. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7739. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7740. c++;
  7741. }
  7742. sstr[c] = '\0';
  7743. //DEBUG_INFO("sstr=%s\n", sstr);
  7744. //parsing strings to words
  7745. i = 0;
  7746. pch = strtok(sstr,delim1);
  7747. while (pch != NULL)
  7748. {
  7749. strcpy(CardList[i], pch);
  7750. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7751. pch = strtok (NULL, delim1);
  7752. i = i + 1;
  7753. }
  7754. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7755. //local Authorizations List Numbers
  7756. //n_localAuthorizations = i;
  7757. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7758. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7759. c= 0;
  7760. while(c < i) // i is CardList Number
  7761. {
  7762. //Search "IdToken"
  7763. memset(sstr ,0, sizeof(sstr) );
  7764. loc = strstr(CardList[c], "idTag");
  7765. int j = 0;
  7766. while (loc[3+strlen("idTag")+j] != '\"')
  7767. {
  7768. sstr[j] = loc[3+strlen("idTag")+j];
  7769. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7770. j++;
  7771. }
  7772. sstr[j] = '\0';
  7773. strcpy(idTagstr, sstr);
  7774. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7775. //Search "expiryDate"
  7776. memset(sstr ,0, sizeof(sstr) );
  7777. loc = strstr(CardList[c], "expiryDate");
  7778. j = 0;
  7779. if(loc != NULL)
  7780. {
  7781. while (loc[3+strlen("expiryDate")+j] != '\"')
  7782. {
  7783. sstr[j] = loc[3+strlen("expiryDate")+j];
  7784. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7785. j++;
  7786. }
  7787. sstr[j] = '\0';
  7788. strcpy(expiryDate, sstr);
  7789. }
  7790. else
  7791. {
  7792. strcpy(expiryDate, "");
  7793. }
  7794. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7795. //Search "parentIdTag"
  7796. memset(sstr ,0, sizeof(sstr) );
  7797. loc = strstr(CardList[c], "parentIdTag");
  7798. j = 0;
  7799. if(loc != NULL)
  7800. {
  7801. while (loc[3+strlen("parentIdTag")+j] != '\"')
  7802. {
  7803. sstr[j] = loc[3+strlen("parentIdTag")+j];
  7804. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7805. j++;
  7806. }
  7807. sstr[j] = '\0';
  7808. strcpy(parentIdTag, sstr);
  7809. }
  7810. else
  7811. {
  7812. strcpy(parentIdTag, "");
  7813. }
  7814. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  7815. //Search "status"
  7816. memset(sstr ,0, sizeof(sstr) );
  7817. loc = strstr(CardList[c], "status");
  7818. j = 0;
  7819. while (loc[3+strlen("status")+j] != '\"')
  7820. {
  7821. sstr[j] = loc[3+strlen("status")+j];
  7822. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7823. j++;
  7824. }
  7825. sstr[j] = '\0';
  7826. strcpy(idTagstatus, sstr);
  7827. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  7828. OCPP_getIdTag(idTagstr);
  7829. //OCPP_getIdTag("test"); For Test
  7830. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  7831. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  7832. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7833. {
  7834. //Local list full update
  7835. DEBUG_INFO("Local list full update.\n");
  7836. // update list
  7837. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  7838. //DEBUG_INFO("Local list full update. 1\n");
  7839. //OCPP_get_TableAuthlocalAllData();
  7840. //DEBUG_INFO("Local list full update. 2\n");
  7841. }
  7842. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7843. {
  7844. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  7845. }
  7846. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  7847. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  7848. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  7849. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  7850. c++;
  7851. }
  7852. }
  7853. else
  7854. {
  7855. //Check UpdateType
  7856. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7857. {
  7858. //Local list full update
  7859. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  7860. OCPP_cleanLocalList();
  7861. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7862. goto end;
  7863. }
  7864. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7865. {
  7866. //Local list different update
  7867. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  7868. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7869. goto end;
  7870. }
  7871. }
  7872. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  7873. end:
  7874. sendSendLocalListConfirmation(uuid, comfirmstr);
  7875. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  7876. return result;
  7877. }
  7878. #define MAX 200
  7879. int handleSetChargingProfileRequest(char *uuid, char *payload)
  7880. {
  7881. mtrace();
  7882. int result = FAIL;
  7883. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  7884. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  7885. char chargingProfilePurposeStr[30]={0};
  7886. char chargingProfileKindStr[16]={0};
  7887. char recurrencyKindStr[10]={0};
  7888. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  7889. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  7890. int chargingSchedulePeriodCount = 0;
  7891. //int updateflag = FALSE;
  7892. char comfirmstr[20]={0};
  7893. int meet= FALSE;
  7894. char sstr[10]={0},sstrtemp[1600]={ 0 };
  7895. int c = 0;
  7896. char *loc;
  7897. FILE *fptr1;//, *fptr2;
  7898. //int lno=0;//, linectr = 0;
  7899. //int modifyflag = FALSE;
  7900. char filename[MAX]={0};
  7901. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  7902. //int resultRename=0;
  7903. char rmFileCmd[50]={0};
  7904. char tempchargingProfilePurposeStr[30]={0};
  7905. char word[1600]={0};
  7906. int n_chargingProfile = 0;
  7907. //[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}}}]
  7908. DEBUG_INFO("handleSetChargingProfileRequest\n");
  7909. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  7910. //Filter string space
  7911. strcpy(sstrtemp, stringtrimspace(payload));
  7912. //*********************connectorId***************************/
  7913. loc = strstr(sstrtemp, "connectorId");
  7914. c = 0;
  7915. memset(sstr ,0, sizeof(sstr) );
  7916. while (loc[strlen("connectorId")+2+c] != ',')
  7917. {
  7918. sstr[c] = loc[strlen("connectorId")+2+c];
  7919. c++;
  7920. }
  7921. sstr[c] = '\0';
  7922. connectorIdInt = atoi(sstr);
  7923. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7924. {
  7925. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  7926. }
  7927. else
  7928. {
  7929. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  7930. }
  7931. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  7932. //*********************chargingProfileId***************************/
  7933. loc = strstr(sstrtemp, "chargingProfileId");
  7934. c = 0;
  7935. memset(sstr ,0, sizeof(sstr) );
  7936. while (loc[strlen("chargingProfileId")+2+c] != ',')
  7937. {
  7938. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  7939. c++;
  7940. }
  7941. sstr[c] = '\0';
  7942. chargingProfileIdInt = atoi(sstr);
  7943. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7944. {
  7945. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7946. }
  7947. else
  7948. {
  7949. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7950. }
  7951. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  7952. //*********************transactionId***************************/
  7953. loc = strstr(sstrtemp, "transactionId");
  7954. if(loc != NULL)
  7955. {
  7956. c = 0;
  7957. memset(sstr ,0, sizeof(sstr) );
  7958. while (loc[strlen("transactionId")+2+c] != ',')
  7959. {
  7960. sstr[c] = loc[strlen("transactionId")+2+c];
  7961. c++;
  7962. }
  7963. sstr[c] = '\0';
  7964. transactionIdInt = atoi(sstr);
  7965. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7966. {
  7967. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  7968. }
  7969. else
  7970. {
  7971. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7972. }
  7973. }
  7974. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  7975. //*********************stackLevel***************************/
  7976. loc = strstr(sstrtemp, "stackLevel");
  7977. c = 0;
  7978. memset(sstr ,0, sizeof(sstr) );
  7979. while (loc[strlen("stackLevel")+2+c] != ',')
  7980. {
  7981. sstr[c] = loc[strlen("stackLevel")+2+c];
  7982. c++;
  7983. }
  7984. sstr[c] = '\0';
  7985. stackLevelInt = atoi(sstr);
  7986. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  7987. {
  7988. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  7989. }
  7990. else
  7991. {
  7992. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7993. }
  7994. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  7995. //*********************chargingProfilePurpose***************************/
  7996. loc = strstr(sstrtemp, "chargingProfilePurpose");
  7997. c = 0;
  7998. memset(sstr ,0, sizeof(sstr) );
  7999. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8000. {
  8001. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8002. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8003. c++;
  8004. }
  8005. sstr[c] = '\0';
  8006. strcpy(chargingProfilePurposeStr,sstr);
  8007. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8008. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8009. {
  8010. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8011. }
  8012. else
  8013. {
  8014. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8015. }
  8016. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8017. //*********************chargingProfileKind***************************/
  8018. loc = strstr(sstrtemp, "chargingProfileKind");
  8019. c = 0;
  8020. memset(sstr ,0, sizeof(sstr) );
  8021. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8022. {
  8023. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8024. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8025. c++;
  8026. }
  8027. sstr[c] = '\0';
  8028. strcpy(chargingProfileKindStr,sstr);
  8029. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8030. {
  8031. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8032. }
  8033. else
  8034. {
  8035. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8036. }
  8037. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8038. //*********************recurrencyKind***************************/
  8039. loc = strstr(sstrtemp, "recurrencyKind");
  8040. if(loc != NULL)
  8041. {
  8042. c = 0;
  8043. memset(sstr ,0, sizeof(sstr) );
  8044. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8045. {
  8046. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8047. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8048. c++;
  8049. }
  8050. sstr[c] = '\0';
  8051. strcpy(recurrencyKindStr,sstr);
  8052. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8053. {
  8054. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8055. }
  8056. else
  8057. {
  8058. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8059. }
  8060. }
  8061. else
  8062. {
  8063. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8064. {
  8065. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8066. }
  8067. else
  8068. {
  8069. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8070. }
  8071. }
  8072. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8073. //*********************validFrom***************************/
  8074. loc = strstr(sstrtemp, "validFrom");
  8075. if(loc != NULL)
  8076. {
  8077. c = 0;
  8078. memset(sstr ,0, sizeof(sstr) );
  8079. while (loc[3+strlen("validFrom")+c] != '\"')
  8080. {
  8081. sstr[c] = loc[3+strlen("validFrom")+c];
  8082. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8083. c++;
  8084. }
  8085. sstr[c] = '\0';
  8086. strcpy(validFromStr,sstr);
  8087. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8088. {
  8089. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8090. }
  8091. else
  8092. {
  8093. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8094. }
  8095. }
  8096. else
  8097. {
  8098. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8099. {
  8100. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8101. }
  8102. else
  8103. {
  8104. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8105. }
  8106. }
  8107. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8108. //*********************validTo***************************/
  8109. loc = strstr(sstrtemp, "validTo");
  8110. if(loc != NULL)
  8111. {
  8112. c = 0;
  8113. memset(sstr ,0, sizeof(sstr) );
  8114. while (loc[3+strlen("validTo")+c] != '\"')
  8115. {
  8116. sstr[c] = loc[3+strlen("validTo")+c];
  8117. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8118. c++;
  8119. }
  8120. sstr[c] = '\0';
  8121. strcpy(validToStr,sstr);
  8122. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8123. {
  8124. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8125. }
  8126. else
  8127. {
  8128. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8129. }
  8130. }
  8131. else
  8132. {
  8133. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8134. {
  8135. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8136. }
  8137. else
  8138. {
  8139. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8140. }
  8141. }
  8142. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8143. //*********************duration***************************/
  8144. loc = strstr(sstrtemp, "duration");
  8145. if(loc != NULL)
  8146. {
  8147. c = 0;
  8148. memset(sstr ,0, sizeof(sstr) );
  8149. while (loc[strlen("duration")+2+c] != ',')
  8150. {
  8151. sstr[c] = loc[strlen("duration")+2+c];
  8152. c++;
  8153. }
  8154. sstr[c] = '\0';
  8155. durationInt = atoi(sstr);
  8156. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8157. {
  8158. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8159. }
  8160. else
  8161. {
  8162. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8163. }
  8164. }
  8165. else
  8166. {
  8167. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8168. {
  8169. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8170. }
  8171. else
  8172. {
  8173. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8174. }
  8175. }
  8176. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8177. //*********************startSchedule***************************/
  8178. loc = strstr(sstrtemp, "startSchedule");
  8179. if(loc != NULL)
  8180. {
  8181. c = 0;
  8182. memset(sstr ,0, sizeof(sstr) );
  8183. while (loc[3+strlen("startSchedule")+c] != '\"')
  8184. {
  8185. sstr[c] = loc[3+strlen("startSchedule")+c];
  8186. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8187. c++;
  8188. }
  8189. sstr[c] = '\0';
  8190. strcpy(startScheduleStr,sstr);
  8191. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8192. {
  8193. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8194. }
  8195. else
  8196. {
  8197. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8198. }
  8199. }
  8200. else
  8201. {
  8202. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8203. {
  8204. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8205. }
  8206. else
  8207. {
  8208. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8209. }
  8210. }
  8211. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8212. //*********************chargingRateUnit***************************/
  8213. loc = strstr(sstrtemp, "chargingRateUnit");
  8214. if(loc != NULL)
  8215. {
  8216. c = 0;
  8217. memset(sstr ,0, sizeof(sstr) );
  8218. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8219. {
  8220. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8221. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8222. c++;
  8223. }
  8224. sstr[c] = '\0';
  8225. strcpy(chargingRateUnitStr,sstr);
  8226. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8227. {
  8228. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8229. }
  8230. else
  8231. {
  8232. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8233. }
  8234. }
  8235. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8236. //****************chargingSchedulePeriod count start*******************/
  8237. int what_len = strlen("startPeriod");
  8238. char tempChargingProfile[1600]={0};
  8239. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8240. char *where = tempChargingProfile;
  8241. if (what_len)
  8242. {
  8243. while ((where = strstr(where, "startPeriod"))) {
  8244. where += what_len;
  8245. chargingSchedulePeriodCount++;
  8246. }
  8247. }
  8248. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8249. {
  8250. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8251. goto end;
  8252. }
  8253. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8254. //where = payload;
  8255. int templength = 0;
  8256. //int searchstart = 0;
  8257. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8258. {
  8259. //****************startPeriod*******************/
  8260. c=0;
  8261. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8262. memset(sstr ,0, sizeof(sstr) );
  8263. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8264. {
  8265. sstr[c] = loc[strlen("startPeriod")+2+c];
  8266. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8267. c++;
  8268. }
  8269. sstr[c] = '\0';
  8270. startPeriodInt[periodNums] = atoi(sstr);
  8271. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8272. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8273. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8274. {
  8275. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8276. }
  8277. else
  8278. {
  8279. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8280. }
  8281. templength = strlen("startPeriod")+2+c;
  8282. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8283. //****************limit*******************/
  8284. c=0;
  8285. loc = strstr(tempChargingProfile + templength, "limit");
  8286. memset(sstr ,0, sizeof(sstr) );
  8287. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8288. {
  8289. sstr[c] = loc[strlen("limit")+2+c];
  8290. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8291. c++;
  8292. }
  8293. sstr[c] = '\0';
  8294. limitflaot[periodNums] = atof(sstr);
  8295. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8296. {
  8297. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8298. }
  8299. else
  8300. {
  8301. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8302. }
  8303. templength = templength + strlen("limit")+2+c;
  8304. //****************numberPhases*******************/
  8305. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8306. if(loc != NULL)
  8307. {
  8308. c=0;
  8309. memset(sstr ,0, sizeof(sstr) );
  8310. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8311. {
  8312. sstr[c] = loc[strlen("numberPhases")+2+c];
  8313. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8314. c++;
  8315. }
  8316. sstr[c] = '\0';
  8317. numberPhasesInt[periodNums] = atoi(sstr);
  8318. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8319. {
  8320. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8321. }
  8322. else
  8323. {
  8324. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8325. }
  8326. templength = templength + strlen("numberPhases")+2+c;
  8327. }
  8328. //where = loc;
  8329. }
  8330. //****************chargingSchedulePeriod count end*******************/
  8331. //*********************minChargingRate***************************/
  8332. loc = strstr(sstrtemp, "minChargingRate");
  8333. if(loc != NULL)
  8334. {
  8335. c = 0;
  8336. memset(sstr ,0, sizeof(sstr) );
  8337. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8338. {
  8339. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8340. c++;
  8341. }
  8342. sstr[c] = '\0';
  8343. minChargingRateFloat = atof(sstr);
  8344. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8345. {
  8346. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8347. }
  8348. else
  8349. {
  8350. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8351. }
  8352. }
  8353. else
  8354. {
  8355. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8356. {
  8357. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8358. }
  8359. else
  8360. {
  8361. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8362. }
  8363. }
  8364. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8365. {
  8366. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8367. if(connectorIdInt != 0)
  8368. {
  8369. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8370. goto end;
  8371. }
  8372. strcpy(filename, ChargePointMaxProfile_JSON );
  8373. fptr1 = fopen(filename, "r");
  8374. if (!fptr1)
  8375. {
  8376. //file not exist
  8377. DEBUG_INFO("Unable to open the input file!!\n");
  8378. fptr1 = fopen(filename, "w+");
  8379. }
  8380. else
  8381. {
  8382. //Check Charging Profile Count
  8383. while(fscanf(fptr1, "%s", word) != EOF)
  8384. {
  8385. //DEBUG_INFO("word=%s\n",word);
  8386. if(strstr(word, "chargingProfileId")!= NULL)
  8387. {
  8388. //DEBUG_INFO("test chargingProfileId \n");
  8389. n_chargingProfile = n_chargingProfile + 1;
  8390. //DEBUG_INFO("chargingProfileId Found\n");
  8391. }
  8392. }
  8393. }
  8394. fclose(fptr1);
  8395. }
  8396. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8397. {
  8398. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8399. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8400. {
  8401. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8402. goto end;
  8403. }
  8404. memset(filename, 0, sizeof filename);
  8405. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8406. fptr1 = fopen(filename, "r");
  8407. if (!fptr1)
  8408. {
  8409. //file not exist
  8410. //DEBUG_INFO("Unable to open the input file!!\n");
  8411. fptr1 = fopen(filename, "w+");
  8412. }
  8413. else
  8414. {
  8415. //Check Charging Profile Count
  8416. while(fscanf(fptr1, "%s", word) != EOF)
  8417. {
  8418. //DEBUG_INFO("word=%s\n",word);
  8419. if(strstr(word, "chargingProfileId")!= NULL)
  8420. {
  8421. //DEBUG_INFO("test chargingProfileId \n");
  8422. n_chargingProfile = n_chargingProfile + 1;
  8423. //DEBUG_INFO("chargingProfileId Found\n");
  8424. }
  8425. }
  8426. }
  8427. fclose(fptr1);
  8428. }
  8429. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8430. {
  8431. //printf("set chargingProfile 1-4\n");
  8432. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8433. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8434. if(connectorIdInt == 0)
  8435. {
  8436. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8437. goto end;
  8438. }
  8439. int tempIndex = 0;
  8440. //check Transaction active
  8441. if(gunType[connectorIdInt -1] == 'J')
  8442. {
  8443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8444. {
  8445. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8446. }
  8447. else
  8448. {
  8449. tempIndex = connectorIdInt -1;
  8450. }
  8451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8452. {
  8453. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8454. {
  8455. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8456. {
  8457. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8458. {
  8459. meet = TRUE;
  8460. break;
  8461. }
  8462. }
  8463. }
  8464. }
  8465. }
  8466. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8467. {
  8468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8469. {
  8470. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8471. }
  8472. else
  8473. {
  8474. tempIndex = connectorIdInt -1;
  8475. }
  8476. for (int index = 0; index < CCS_QUANTITY; index++)
  8477. {
  8478. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8479. {
  8480. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8481. {
  8482. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8483. {
  8484. meet = TRUE;
  8485. break;
  8486. }
  8487. }
  8488. }
  8489. }
  8490. }
  8491. else if(gunType[connectorIdInt -1] == 'G')
  8492. {
  8493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8494. {
  8495. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8496. }
  8497. else
  8498. {
  8499. tempIndex = connectorIdInt -1;
  8500. }
  8501. for (int index = 0; index < GB_QUANTITY; index++)
  8502. {
  8503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8504. {
  8505. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8506. {
  8507. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8508. {
  8509. meet = TRUE;
  8510. break;
  8511. }
  8512. }
  8513. }
  8514. }
  8515. }
  8516. else
  8517. {
  8518. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8519. {
  8520. tempIndex = 2;
  8521. }
  8522. else
  8523. {
  8524. tempIndex = (connectorIdInt -1);
  8525. }
  8526. for (int index = 0; index < AC_QUANTITY; index++)
  8527. {
  8528. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8529. {
  8530. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8531. {
  8532. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8533. {
  8534. meet = TRUE;
  8535. break;
  8536. }
  8537. }
  8538. }
  8539. }
  8540. }
  8541. //check Transaction active
  8542. if(meet == FALSE)
  8543. {
  8544. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8545. goto end;
  8546. }
  8547. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8548. {
  8549. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8550. goto end;
  8551. }
  8552. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8553. fptr1 = fopen(filename, "r");
  8554. if (!fptr1)
  8555. {
  8556. //file not exist
  8557. DEBUG_INFO("Unable to open the input file!!\n");
  8558. fptr1 = fopen(filename, "w+");
  8559. }
  8560. else
  8561. {
  8562. //Check Charging Profile Count
  8563. while(fscanf(fptr1, "%s", word) != EOF)
  8564. {
  8565. //DEBUG_INFO("word=%s\n",word);
  8566. if(strstr(word, "chargingProfileId")!= NULL)
  8567. {
  8568. //DEBUG_INFO("test chargingProfileId \n");
  8569. n_chargingProfile = n_chargingProfile + 1;
  8570. //DEBUG_INFO("chargingProfileId Found\n");
  8571. }
  8572. }
  8573. }
  8574. fclose(fptr1);
  8575. }
  8576. // Check ChargeProfileMaxStackLevel
  8577. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8578. {
  8579. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8580. goto end;
  8581. }
  8582. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8583. {
  8584. int i = 0;
  8585. char fnametemp[200]={0};
  8586. n_chargingProfile = 0;
  8587. //Check ChargePointMaxProfile.json exit
  8588. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8589. {
  8590. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8591. //Check Charging Profile Count
  8592. while(fscanf(fptr1, "%s", word) != EOF)
  8593. {
  8594. //DEBUG_INFO("word=%s\n",word);
  8595. if(strstr(word, "chargingProfileId")!= NULL)
  8596. {
  8597. //DEBUG_INFO("test chargingProfileId \n");
  8598. n_chargingProfile = n_chargingProfile + 1;
  8599. i = i + 1;
  8600. //DEBUG_INFO("chargingProfileId Found\n");
  8601. }
  8602. memset(word, 0, sizeof word);
  8603. }
  8604. fclose(fptr1);
  8605. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8606. }
  8607. //Check TxDefaultProfile_0.json exit
  8608. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8609. {
  8610. i = 0;
  8611. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8612. //Check Charging Profile Count
  8613. while(fscanf(fptr1, "%s", word) != EOF)
  8614. {
  8615. //DEBUG_INFO("word=%s\n",word);
  8616. if(strstr(word, "chargingProfileId")!= NULL)
  8617. {
  8618. //DEBUG_INFO("test chargingProfileId \n");
  8619. n_chargingProfile = n_chargingProfile + 1;
  8620. i = i + 1;
  8621. //DEBUG_INFO("chargingProfileId Found\n");
  8622. }
  8623. memset(word, 0, sizeof word);
  8624. }
  8625. fclose(fptr1);
  8626. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8627. }
  8628. //Check TxDefaultProfile_%d.json
  8629. for(int j=1; j <= gunTotalNumber; j++)
  8630. {
  8631. memset(fnametemp, 0, sizeof fnametemp);
  8632. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8633. if((access(fnametemp,F_OK))!=-1)
  8634. {
  8635. i = 0;
  8636. fptr1 = fopen(fnametemp, "r");
  8637. //Check Charging Profile Count
  8638. while(fscanf(fptr1, "%s", word) != EOF)
  8639. {
  8640. //DEBUG_INFO("word=%s\n",word);
  8641. if(strstr(word, "chargingProfileId")!= NULL)
  8642. {
  8643. //DEBUG_INFO("test chargingProfileId \n");
  8644. n_chargingProfile = n_chargingProfile + 1;
  8645. i = i + 1;
  8646. //DEBUG_INFO("chargingProfileId Found\n");
  8647. }
  8648. memset(word, 0, sizeof word);
  8649. }
  8650. fclose(fptr1);
  8651. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8652. }
  8653. }
  8654. //Check TxProfile_%d.json
  8655. for(int j=1; j <= gunTotalNumber; j++)
  8656. {
  8657. memset(fnametemp, 0, sizeof fnametemp);
  8658. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8659. if((access(fnametemp,F_OK))!=-1)
  8660. {
  8661. i = 0;
  8662. fptr1 = fopen(fnametemp, "r");
  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. i = i + 1;
  8672. //DEBUG_INFO("chargingProfileId Found\n");
  8673. }
  8674. memset(word, 0, sizeof word);
  8675. }
  8676. fclose(fptr1);
  8677. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8678. }
  8679. }
  8680. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8681. {
  8682. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8683. goto end;
  8684. }
  8685. }
  8686. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8687. //**********************************Write to File********************************************************/
  8688. FILE *infile;
  8689. FILE *outfile;
  8690. // open file for writing
  8691. infile = fopen (filename, "r");
  8692. outfile = fopen (tempfile, "w");
  8693. int d =0;
  8694. d = fgetc(infile);
  8695. //DEBUG_INFO("d:%d\n",d);
  8696. rewind(infile);
  8697. //*璉 瘚 辣蝏     1嚗   0 */
  8698. if(d == EOF)
  8699. {
  8700. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8701. fprintf(outfile,"%s\n",payload);
  8702. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8703. fclose(infile);
  8704. fclose(outfile);
  8705. sprintf(rmFileCmd,"rm -f %s",filename);
  8706. system(rmFileCmd);
  8707. rename(tempfile, filename);
  8708. sleep(1);
  8709. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8710. //system(rmFileCmd);
  8711. }
  8712. else
  8713. {
  8714. char buf[1000]={0};
  8715. int ChargingProfileAdded = FALSE;
  8716. while (fgets(buf, sizeof(buf), infile) != NULL)
  8717. {
  8718. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8719. //*************************tempconnectorIdInt*********************************/
  8720. loc = strstr(buf, "connectorId");
  8721. c = 0;
  8722. memset(sstr ,0, sizeof(sstr) );
  8723. while (loc[strlen("connectorId")+2+c] != ',')
  8724. {
  8725. sstr[c] = loc[strlen("connectorId")+2+c];
  8726. c++;
  8727. }
  8728. sstr[c] = '\0';
  8729. tempconnectorIdInt = atoi(sstr);
  8730. //*************************tempchargingProfileIdInt*********************************/
  8731. loc = strstr(buf, "chargingProfileId");
  8732. c = 0;
  8733. memset(sstr ,0, sizeof(sstr) );
  8734. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8735. {
  8736. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8737. c++;
  8738. }
  8739. sstr[c] = '\0';
  8740. tempchargingProfileIdInt = atoi(sstr);
  8741. //*************************tempstackLevelInt*********************************/
  8742. loc = strstr(buf, "stackLevel");
  8743. c = 0;
  8744. memset(sstr ,0, sizeof(sstr) );
  8745. while (loc[strlen("stackLevel")+2+c] != ',')
  8746. {
  8747. sstr[c] = loc[strlen("stackLevel")+2+c];
  8748. c++;
  8749. }
  8750. sstr[c] = '\0';
  8751. tempstackLevelInt = atoi(sstr);
  8752. //*************************tempchargingProfilePurposeStr*********************************/
  8753. loc = strstr(payload, "chargingProfilePurpose");
  8754. c = 0;
  8755. memset(sstr ,0, sizeof(sstr) );
  8756. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8757. {
  8758. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8759. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8760. c++;
  8761. }
  8762. sstr[c] = '\0';
  8763. strcpy(tempchargingProfilePurposeStr,sstr);
  8764. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8765. {
  8766. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8767. {
  8768. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8769. if(ChargingProfileAdded == FALSE)
  8770. {
  8771. fprintf(outfile,"%s\n",payload);
  8772. ChargingProfileAdded = TRUE;
  8773. }
  8774. }
  8775. else
  8776. {
  8777. if(tempstackLevelInt < stackLevelInt)
  8778. {
  8779. if(ChargingProfileAdded == FALSE)
  8780. {
  8781. fprintf(outfile,"%s\n",payload);
  8782. ChargingProfileAdded = TRUE;
  8783. fprintf(outfile,"%s\n",buf);
  8784. }
  8785. else
  8786. {
  8787. fprintf(outfile,"%s\n",buf);
  8788. }
  8789. }
  8790. else
  8791. {
  8792. if(ChargingProfileAdded == FALSE)
  8793. {
  8794. fprintf(outfile,"%s\n",buf);
  8795. fprintf(outfile,"%s\n",payload);
  8796. ChargingProfileAdded = TRUE;
  8797. }
  8798. else
  8799. {
  8800. fprintf(outfile,"%s\n",buf);
  8801. }
  8802. }
  8803. }
  8804. }
  8805. else
  8806. {
  8807. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8808. {
  8809. if(ChargingProfileAdded == FALSE)
  8810. {
  8811. fprintf(outfile,"%s\n",payload);
  8812. ChargingProfileAdded = TRUE;
  8813. fprintf(outfile,"%s\n",buf);
  8814. }
  8815. else
  8816. {
  8817. fprintf(outfile,"%s\n",buf);
  8818. }
  8819. }
  8820. else if(tempstackLevelInt < stackLevelInt)
  8821. {
  8822. if(ChargingProfileAdded == FALSE)
  8823. {
  8824. fprintf(outfile,"%s\n",payload);
  8825. ChargingProfileAdded = TRUE;
  8826. fprintf(outfile,"%s\n",buf);
  8827. }
  8828. else
  8829. {
  8830. fprintf(outfile,"%s\n",buf);
  8831. }
  8832. }
  8833. else
  8834. {
  8835. if(ChargingProfileAdded == FALSE)
  8836. {
  8837. fprintf(outfile,"%s\n",buf);
  8838. fprintf(outfile,"%s\n",payload);
  8839. ChargingProfileAdded = TRUE;
  8840. }
  8841. else
  8842. {
  8843. fprintf(outfile,"%s\n",buf);
  8844. }
  8845. }
  8846. }
  8847. } // end of while loop
  8848. fclose(infile);
  8849. fclose(outfile);
  8850. sprintf(rmFileCmd,"rm -f %s",filename);
  8851. system(rmFileCmd);
  8852. rename(tempfile, filename);
  8853. sleep(1);
  8854. result = TRUE;
  8855. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8856. }
  8857. end:
  8858. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8859. return result;
  8860. return result;
  8861. }
  8862. int handleTriggerMessageRequest(char *uuid, char *payload)
  8863. {
  8864. mtrace();
  8865. int result = FAIL;
  8866. int connectorIdIsNULL = FALSE;
  8867. int connectorIdInt =0;
  8868. char sstr[40]={0},sstrtemp[100]={ 0 };
  8869. char requestedMessagestr[40]={0};
  8870. char comfirmstr[20]={0};
  8871. int c = 0;
  8872. char *loc;
  8873. DEBUG_INFO("handleTriggerMessageRequest\n");
  8874. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8875. strcpy(sstrtemp, stringtrimspace(payload));
  8876. c = 0;
  8877. loc = strstr(sstrtemp, "requestedMessage");
  8878. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8879. {
  8880. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8881. c++;
  8882. }
  8883. sstr[c] = '\0';
  8884. strcpy(requestedMessagestr, sstr);
  8885. c = 0;
  8886. loc = strstr(sstrtemp, "connectorId");
  8887. if(loc == NULL)
  8888. {
  8889. connectorIdIsNULL = TRUE;
  8890. }
  8891. else
  8892. {
  8893. memset(sstr ,0, sizeof(sstr) );
  8894. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8895. {
  8896. sstr[c] = loc[strlen("connectorId")+2+c];
  8897. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8898. c++;
  8899. }
  8900. sstr[c] = '\0';
  8901. connectorIdInt = atoi(sstr);
  8902. }
  8903. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  8904. {
  8905. //connectorIdInt = json_object_get_int(connectorId);
  8906. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8907. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8908. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8909. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8910. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8911. }
  8912. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8913. {
  8914. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8915. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8916. return TRUE;
  8917. }
  8918. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8919. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8920. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8921. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8922. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8923. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8924. {
  8925. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8926. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8927. return TRUE;
  8928. }
  8929. else
  8930. {
  8931. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8932. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8933. }
  8934. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8935. {
  8936. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  8937. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  8938. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  8939. {
  8940. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  8941. }
  8942. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8943. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8944. }
  8945. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8946. {
  8947. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  8948. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8949. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8950. }
  8951. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8952. {
  8953. sendBootNotificationRequest();
  8954. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8955. }
  8956. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8957. {
  8958. sendHeartbeatRequest(connectorIdInt);
  8959. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8960. }
  8961. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8962. {
  8963. if(connectorIdIsNULL == FALSE)
  8964. {
  8965. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8966. {
  8967. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  8968. sendMeterValuesRequest(connectorIdInt -1);
  8969. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8970. }
  8971. }
  8972. else
  8973. {
  8974. for(int idx=0;idx< gunTotalNumber;idx++)
  8975. {
  8976. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  8977. sendMeterValuesRequest(idx);
  8978. }
  8979. }
  8980. }
  8981. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8982. {
  8983. if(connectorIdIsNULL == FALSE)
  8984. {
  8985. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8986. {
  8987. sendStatusNotificationRequest(connectorIdInt -1);
  8988. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8989. }
  8990. }
  8991. else
  8992. {
  8993. for(int idx=0;idx< gunTotalNumber;idx++)
  8994. sendStatusNotificationRequest(idx);
  8995. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8996. }
  8997. }
  8998. return result;
  8999. }
  9000. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9001. {
  9002. mtrace();
  9003. int result = FAIL;
  9004. char sstr[6]={0},sstrtemp[50]={ 0 };
  9005. int connectorIdInt =0;
  9006. char comfirmstr[20]={0};
  9007. int c = 0;
  9008. int tempIndex = 0;
  9009. char *loc;
  9010. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9011. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9012. strcpy(sstrtemp, stringtrimspace(payload));
  9013. c = 0;
  9014. loc = strstr(sstrtemp, "connectorId");
  9015. memset(sstr ,0, sizeof(sstr) );
  9016. while (loc[strlen("connectorId")+2+c] != '}')
  9017. {
  9018. sstr[c] = loc[strlen("connectorId")+2+c];
  9019. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9020. c++;
  9021. }
  9022. sstr[c] = '\0';
  9023. connectorIdInt = atoi(sstr);
  9024. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9025. if(gunTotalNumber == 0)
  9026. {
  9027. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9028. goto end;
  9029. }
  9030. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9031. {
  9032. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9033. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9034. goto end;
  9035. }
  9036. else
  9037. {
  9038. //check Transaction active
  9039. if(gunType[connectorIdInt-1] == 'J')
  9040. {
  9041. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9042. {
  9043. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9044. }
  9045. else
  9046. {
  9047. tempIndex = connectorIdInt -1;
  9048. }
  9049. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9050. {
  9051. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9052. {
  9053. //stop Transaction
  9054. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9055. }
  9056. }
  9057. }
  9058. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9059. {
  9060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9061. {
  9062. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9063. }
  9064. else
  9065. {
  9066. tempIndex = connectorIdInt -1;
  9067. }
  9068. for (int index = 0; index < CCS_QUANTITY; index++)
  9069. {
  9070. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9071. {
  9072. //stop Transaction
  9073. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9074. }
  9075. }
  9076. }
  9077. else if(gunType[connectorIdInt-1] == 'G')
  9078. {
  9079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9080. {
  9081. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9082. }
  9083. else
  9084. {
  9085. tempIndex = connectorIdInt -1;
  9086. }
  9087. for (int index = 0; index < GB_QUANTITY; index++)
  9088. {
  9089. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9090. {
  9091. //stop Transaction
  9092. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9093. }
  9094. }
  9095. }
  9096. else
  9097. {
  9098. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9099. {
  9100. tempIndex = 2;
  9101. }
  9102. else
  9103. {
  9104. tempIndex = connectorIdInt-1;
  9105. }
  9106. for (int index = 0; index < AC_QUANTITY; index++)
  9107. {
  9108. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9109. {
  9110. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9111. }
  9112. }
  9113. }
  9114. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9115. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9116. result = TRUE;
  9117. return result;
  9118. }
  9119. end:
  9120. //json_object_put(obj); --- remove temporally
  9121. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9122. return result;
  9123. }
  9124. static char UpdateFirmwarepayloadData[300]={0};
  9125. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9126. {
  9127. mtrace();
  9128. int result = FAIL;
  9129. pthread_t t;
  9130. sendUpdateFirmwareConfirmation(uuid);
  9131. memset(UpdateFirmwarepayloadData, 0, 300);
  9132. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9133. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9134. ////pthread_join(t, NULL); //
  9135. //pthread_detach(t);
  9136. //sendUpdateFirmwareConfirmation(uuid);
  9137. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9138. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9139. return result;
  9140. }
  9141. void *UpdateFirmwareProcess(void *data)
  9142. {
  9143. pthread_detach(pthread_self());
  9144. mtrace();
  9145. int retriesInt =0, retryIntervalInt=0;
  9146. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9147. int port=0;
  9148. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9149. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9150. //char comfirmstr[20];
  9151. int isSuccess = 0;
  9152. char ftpbuf[200];
  9153. char temp[100];
  9154. char * pch;
  9155. int retriesISNULL=FALSE;
  9156. int retryInterval=FALSE;
  9157. int c = 0;
  9158. //int i = 0;
  9159. char *loc;
  9160. char sstr[300]={ 0 };
  9161. char str[300]={ 0 };
  9162. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9163. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9164. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9165. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9166. //***************location **************/
  9167. loc = strstr(str, "location");
  9168. memset(sstr ,0, sizeof(sstr) );
  9169. c = 0;
  9170. while (loc[3+strlen("location")+c] != '\"')
  9171. {
  9172. sstr[c] = loc[3+strlen("location")+c];
  9173. c++;
  9174. }
  9175. sstr[c] = '\0';
  9176. strcpy(locationstr, sstr);
  9177. //***************retries**************/
  9178. c = 0;
  9179. loc = strstr(str, "retries");
  9180. if(loc == NULL)
  9181. {
  9182. retriesISNULL=TRUE;
  9183. }
  9184. else
  9185. {
  9186. memset(sstr ,0, sizeof(sstr) );
  9187. while (loc[strlen("retries")+2+c] != ',')
  9188. {
  9189. sstr[c] = loc[strlen("retries")+2+c];
  9190. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9191. c++;
  9192. }
  9193. sstr[c] = '\0';
  9194. }
  9195. if(retriesISNULL == FALSE)
  9196. {
  9197. retriesInt = atoi(sstr);
  9198. }
  9199. //***************retrieveDate **************/
  9200. loc = strstr(str, "retrieveDate");
  9201. memset(sstr ,0, sizeof(sstr) );
  9202. c = 0;
  9203. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9204. {
  9205. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9206. c++;
  9207. }
  9208. sstr[c] = '\0';
  9209. strcpy(retrieveDatestr, sstr);
  9210. //***************retryInterval **************/
  9211. c = 0;
  9212. loc = strstr(str, "retryInterval");
  9213. memset(sstr ,0, sizeof(sstr) );
  9214. if(loc == NULL)
  9215. {
  9216. retryInterval=TRUE;
  9217. }
  9218. else
  9219. {
  9220. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9221. {
  9222. sstr[c] = loc[strlen("retryInterval")+2+c];
  9223. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9224. c++;
  9225. }
  9226. sstr[c] = '\0';
  9227. }
  9228. if(retryInterval==FALSE)
  9229. {
  9230. retryIntervalInt = atoi(sstr);
  9231. }
  9232. memset(ftppath, 0, sizeof(ftppath));
  9233. memset(path, 0, sizeof(path));
  9234. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9235. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9236. if(strncmp(locationstr,"http", 4) == 0)
  9237. {
  9238. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9239. protocol, host, path);
  9240. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9241. // protocol, user, password, host, path);
  9242. sprintf(ftppath,"/%s", path);
  9243. //DEBUG_INFO("protocol =%s\n",protocol);
  9244. //DEBUG_INFO("host =%s\n",host);
  9245. //DEBUG_INFO("path =%s\n",path);
  9246. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9247. int ftppathlen=strlen(ftppath);
  9248. int i=1;
  9249. char filenametemp[50];
  9250. while(i < ftppathlen)
  9251. {
  9252. int len=ftppathlen-i;
  9253. if(ftppath[len]== 47) // '/' ascll code: 47
  9254. {
  9255. DEBUG_INFO("compare '/' all right\n");
  9256. break;
  9257. }
  9258. i=i+1;
  9259. }
  9260. memset(filenametemp, 0, sizeof(filenametemp));
  9261. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9262. filenametemp[i+1] = 0;
  9263. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9264. do{
  9265. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9266. sleep(retryIntervalInt);
  9267. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9268. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9269. if(!isSuccess)
  9270. {
  9271. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9272. }
  9273. else
  9274. {
  9275. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9276. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9277. //isUpdateRequest = TRUE;
  9278. }
  9279. }
  9280. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9281. {
  9282. memset(ftpbuf, 0, sizeof(ftpbuf));
  9283. memset(temp, 0, sizeof(temp));
  9284. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9285. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9286. int ftppathlen=strlen(ftpbuf);
  9287. int i=1;
  9288. char filenametemp[50];
  9289. while(i < ftppathlen)
  9290. {
  9291. int len=ftppathlen-i;
  9292. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9293. {
  9294. DEBUG_INFO(" compare '/' all right\n");
  9295. break;
  9296. }
  9297. i=i+1;
  9298. }
  9299. memset(filenametemp, 0, sizeof(filenametemp));
  9300. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9301. filenametemp[i+1] = 0;
  9302. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9303. pch=strchr(temp,'@');
  9304. if(pch==NULL)
  9305. {
  9306. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9307. protocol, host, &port, path);
  9308. strcpy(user,"anonymous");
  9309. strcpy(password,"");
  9310. }
  9311. else
  9312. {
  9313. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9314. protocol, user, password, host, &port, path);
  9315. }
  9316. sscanf(host,"%[^/]%s",host1, path1);
  9317. sprintf(ftppath,"%s", path1);
  9318. //DEBUG_INFO("protocol =%s\n",protocol);
  9319. //DEBUG_INFO("user =%s\n",user);
  9320. //DEBUG_INFO("password =%s\n",password);
  9321. //DEBUG_INFO("host1 =%s\n",host1);
  9322. //DEBUG_INFO("port =%d\n",port);
  9323. //DEBUG_INFO("path1 =%s\n",path1);
  9324. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9325. //ftpFile(host, user, password, port, ftppath, fname);
  9326. //download firmware pthred
  9327. if(port == 0)
  9328. {
  9329. port = 21;
  9330. }
  9331. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9332. do{
  9333. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9334. sleep(retryIntervalInt);
  9335. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9336. if(!isSuccess)
  9337. {
  9338. //BulldogUtil.sleepMs(interval*1000);
  9339. DEBUG_INFO("Update firmware request and download file fail.\n");
  9340. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9341. }
  9342. else
  9343. {
  9344. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9345. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9346. //isUpdateRequest = TRUE;
  9347. }
  9348. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9349. }
  9350. else
  9351. {
  9352. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9353. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9354. }
  9355. pthread_exit(NULL);
  9356. }
  9357. //==========================================
  9358. // Handle server response routine
  9359. //==========================================
  9360. void handleAuthorizeResponse(char *payload, int gun_index)
  9361. {
  9362. mtrace();
  9363. char expiryDatestr[30]={0};
  9364. char parentIdTagstr[20]={0};
  9365. char statusstr[20]={0};
  9366. char expiryDatestrtemp[30]={0};
  9367. char parentIdTagstrtemp[20]={0};
  9368. char IdTagstrtemp[20]={0};
  9369. char statusstrtemp[20]={0};
  9370. int expiryDateISNULL=FALSE;
  9371. int parentIdTagISNULL=FALSE;
  9372. char sstr[160]={0};
  9373. char* filename = AuthorizationCache_JSON;
  9374. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9375. char *loc;
  9376. int resultRename=0;
  9377. int responseIdTagInfoAsZero= 0;
  9378. char rmFileCmd[50]={0};
  9379. DEBUG_INFO("handleAuthorizeResponse...\n");
  9380. json_object *Authorize;
  9381. Authorize = json_tokener_parse(payload);
  9382. if(!is_error(Authorize))
  9383. {
  9384. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9385. {
  9386. // Required data
  9387. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9388. // Optional data
  9389. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9390. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9391. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9392. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9393. }
  9394. }
  9395. json_object_put(Authorize);
  9396. if(expiryDateISNULL == FALSE)
  9397. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9398. if(parentIdTagISNULL == FALSE)
  9399. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9400. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9401. //Update idTag information to authorization cache if supproted
  9402. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9403. {
  9404. if((access(filename,F_OK))!=-1)
  9405. {
  9406. printf("AuthorizationCache exist.\n");
  9407. }
  9408. else
  9409. {
  9410. printf("AuthorizationCache not exist\n");
  9411. FILE *log = fopen(filename, "w+");
  9412. if(log == NULL)
  9413. {
  9414. printf("log is NULL\n");
  9415. goto out;
  9416. }
  9417. else
  9418. {
  9419. fclose(log);
  9420. }
  9421. }
  9422. FILE *infile;
  9423. FILE *outfile;
  9424. // open file for writing
  9425. infile = fopen (filename, "r");
  9426. outfile = fopen (tempfile, "w");
  9427. int c;
  9428. c = fgetc(infile);
  9429. //DEBUG_INFO("c:%d\n",c);
  9430. rewind(infile);
  9431. if(c == EOF)
  9432. {
  9433. DEBUG_INFO("Orignal File is NULL\n");
  9434. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9435. {
  9436. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9437. }
  9438. else
  9439. {
  9440. strcpy(expiryDatestrtemp, "");
  9441. }
  9442. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9443. {
  9444. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9445. }
  9446. else
  9447. {
  9448. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9449. }
  9450. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9451. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9452. fclose(infile);
  9453. fclose(outfile);
  9454. sprintf(rmFileCmd,"rm -f %s",filename);
  9455. system(rmFileCmd);
  9456. resultRename = rename(tempfile, filename);
  9457. if(resultRename == 0)
  9458. {
  9459. printf("File renamed successfully");
  9460. }
  9461. else
  9462. {
  9463. printf("Error: unable to rename the file");
  9464. }
  9465. }
  9466. else
  9467. {
  9468. char buf[160]={0};
  9469. while (fgets(buf, sizeof(buf), infile) != NULL)
  9470. {
  9471. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9472. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9473. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9474. memset(statusstr, 0, sizeof(statusstrtemp));
  9475. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9476. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9477. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9478. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9479. //------------------IdTag-----------------------
  9480. loc = strstr(buf, "idTag");
  9481. memset(sstr ,0, sizeof(sstr) );
  9482. c = 0;
  9483. while (loc[3+strlen("idTag")+c] != '\"')
  9484. {
  9485. sstr[c] = loc[3+strlen("idTag")+c];
  9486. c++;
  9487. }
  9488. sstr[c] = '\0';
  9489. strcpy(IdTagstrtemp,sstr);
  9490. //*********************expiryDate***************/
  9491. loc = strstr(buf, "expiryDate");
  9492. memset(sstr ,0, sizeof(sstr) );
  9493. c = 0;
  9494. while (loc[3+strlen("expiryDate")+c] != '\"')
  9495. {
  9496. sstr[c] = loc[3+strlen("expiryDate")+c];
  9497. c++;
  9498. }
  9499. sstr[c] = '\0';
  9500. strcpy(expiryDatestr,sstr);
  9501. //*********************parentIdTag***************/
  9502. loc = strstr(buf, "parentIdTag");
  9503. memset(sstr ,0, sizeof(sstr) );
  9504. c = 0;
  9505. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9506. {
  9507. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9508. c++;
  9509. }
  9510. sstr[c] = '\0';
  9511. strcpy(parentIdTagstr,sstr);
  9512. //*********************status***************/
  9513. loc = strstr(buf, "status");
  9514. memset(sstr ,0, sizeof(sstr) );
  9515. c = 0;
  9516. while (loc[3+strlen("status")+c] != '\"')
  9517. {
  9518. sstr[c] = loc[3+strlen("status")+c];
  9519. c++;
  9520. }
  9521. sstr[c] = '\0';
  9522. strcpy(statusstr,sstr);
  9523. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9524. {
  9525. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9526. responseIdTagInfoAsZero = 1;
  9527. }
  9528. else
  9529. {
  9530. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9531. }
  9532. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9533. {
  9534. //modify item
  9535. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9536. {
  9537. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9538. }
  9539. else
  9540. {
  9541. strcpy(expiryDatestrtemp, "");
  9542. }
  9543. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9544. {
  9545. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9546. }
  9547. else
  9548. {
  9549. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9550. }
  9551. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9552. }
  9553. else
  9554. {
  9555. //wrie original item
  9556. strcpy(expiryDatestrtemp, expiryDatestr);
  9557. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9558. strcpy(statusstrtemp, statusstr);
  9559. }
  9560. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9561. }
  9562. fclose(infile);
  9563. fclose(outfile);
  9564. sprintf(rmFileCmd,"rm -f %s",filename);
  9565. system(rmFileCmd);
  9566. resultRename = rename(tempfile, filename);
  9567. if(resultRename == 0)
  9568. {
  9569. DEBUG_INFO("File renamed successfully");
  9570. }
  9571. else
  9572. {
  9573. DEBUG_INFO("Error: unable to rename the file");
  9574. }
  9575. }
  9576. }
  9577. out:
  9578. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9579. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9580. authorizeRetryTimes = 0;
  9581. }
  9582. char * strtrimc( char * s )
  9583. {
  9584. char * p1 = s;
  9585. char * p2 = s;
  9586. while(*p1 != '\0')
  9587. {
  9588. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9589. {
  9590. if(*p1 != ',')
  9591. {
  9592. p1 ++;
  9593. }
  9594. else
  9595. {
  9596. break;
  9597. }
  9598. }
  9599. if(*p1 != ',')
  9600. {
  9601. * p2 ++ = *p1 ++;
  9602. //printf("p2=%s\n",p2);
  9603. }
  9604. else
  9605. {
  9606. break;
  9607. }
  9608. }
  9609. *p2 = '\0';
  9610. return (s);
  9611. }
  9612. void handleBootNotificationResponse(char *payload, int gun_index)
  9613. {
  9614. mtrace();
  9615. char statusStr[12]={0};
  9616. char currentTimeStr[30]={0};
  9617. int intervalInt = 0;
  9618. struct tm tp;
  9619. char buf[28]={0};
  9620. char timebuf[50]={0};
  9621. DEBUG_INFO("handleBootNotificationResponse...\n");
  9622. json_object *BootNotification;
  9623. BootNotification = json_tokener_parse(payload);
  9624. if(!is_error(BootNotification))
  9625. {
  9626. // Required data
  9627. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9628. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9629. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9630. }
  9631. json_object_put(BootNotification);
  9632. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9633. BootNotificationInterval = intervalInt;
  9634. HeartBeatWaitTime = intervalInt;
  9635. //write back to ShmOCPP16Data->BootNotification
  9636. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9637. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9638. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9639. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9640. {
  9641. server_sign = TRUE;
  9642. server_pending =FALSE;
  9643. }
  9644. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9645. {
  9646. server_pending = TRUE;
  9647. }
  9648. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9649. tp.tm_isdst = -1;
  9650. //time_t utc = mktime(&tp);
  9651. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9652. memset(timebuf, 0, sizeof timebuf);
  9653. sprintf(timebuf,"date -s '%s'",buf);
  9654. system(timebuf);
  9655. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-5);
  9656. //==============================================
  9657. // RTC sync
  9658. //==============================================
  9659. system("/sbin/hwclock -w --systohc");
  9660. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9661. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9662. sendFirmwareVersionByDataTransfer();
  9663. }
  9664. void handleDataTransferResponse(char *payload, int gun_index)
  9665. {
  9666. char sstr[160]={0};//sstr[200]={ 0 };
  9667. int c = 0;
  9668. char *loc;
  9669. DEBUG_INFO("handleDataTransferResponse ...\n");
  9670. loc = strstr(payload, "status");
  9671. printf("loc=%s\n",loc);
  9672. c = 0;
  9673. while (loc[3+strlen("status")+c] != '\"')
  9674. {
  9675. sstr[c] = loc[3+strlen("status")+c];
  9676. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9677. c++;
  9678. }
  9679. sstr[c] = '\0';
  9680. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9681. }
  9682. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9683. {
  9684. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9685. //struct json_object *obj;
  9686. // obj = json_tokener_parse(payload);
  9687. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9688. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9689. //No fields are defined.
  9690. }
  9691. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9692. {
  9693. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9694. //struct json_object *obj;
  9695. // obj = json_tokener_parse(payload);
  9696. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9697. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9698. //No fields are defined.
  9699. }
  9700. void handleHeartbeatResponse(char *payload, int gun_index)
  9701. {
  9702. mtrace();
  9703. struct tm tp;
  9704. char buf[28]={0};
  9705. char timebuf[50]={0};
  9706. DEBUG_INFO("handleHeartbeatResponse...\n");
  9707. json_object *Heartbeat;
  9708. Heartbeat = json_tokener_parse(payload);
  9709. if(!is_error(Heartbeat))
  9710. {
  9711. // Required data
  9712. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9713. }
  9714. json_object_put(BootNotification);
  9715. if(FirstHeartBeat == 0)
  9716. {
  9717. FirstHeartBeat = 1;
  9718. DEBUG_INFO("FirstHeartBeat \n");
  9719. }
  9720. HeartBeatWithNOResponse = 0;
  9721. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9722. tp.tm_isdst = -1;
  9723. //time_t utc = mktime(&tp);
  9724. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9725. memset(timebuf, 0, sizeof timebuf);
  9726. sprintf(timebuf,"date -s '%s'",buf);
  9727. system(timebuf);
  9728. //==============================================
  9729. // RTC sync
  9730. //==============================================
  9731. system("/sbin/hwclock -w --systohc");
  9732. //===============================================
  9733. //Print Out HeartBeat log
  9734. //===============================================
  9735. {
  9736. double diff_t;
  9737. struct tm tp,tp1;
  9738. // BootNotification Receive Time
  9739. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9740. tp.tm_isdst = -1;
  9741. time_t BootNotificationReceiveTime = mktime(&tp);
  9742. //HeartBeat Receive Time
  9743. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9744. tp1.tm_isdst = -1;
  9745. time_t HeartBeatReceiveTime = mktime(&tp1);
  9746. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9747. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9748. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9749. {
  9750. HeartBeatCountPerHour = (int)diff_t / 3600;
  9751. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9752. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9753. }
  9754. }
  9755. }
  9756. void handleMeterValuesResponse(char *payload, int gun_index)
  9757. {
  9758. mtrace();
  9759. DEBUG_INFO("handleMeterValuesResponse...\n");
  9760. }
  9761. void handleStartTransactionResponse(char *payload, int gun_index)
  9762. {
  9763. mtrace();
  9764. //int transactionIdInt = 0;
  9765. FILE *outfile;
  9766. char data[100]={0};
  9767. DEBUG_INFO("handleStartTransactionResponse...\n");
  9768. json_object *StartTransaction;
  9769. StartTransaction = json_tokener_parse(payload);
  9770. if(!is_error(StartTransaction))
  9771. {
  9772. // Required data
  9773. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9774. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9775. // Optional data
  9776. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9777. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9778. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9779. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9780. }
  9781. json_object_put(StartTransaction);
  9782. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9783. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9784. //-----------Start : write to the Queue TransactionId file -----------------//
  9785. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9786. {}
  9787. else
  9788. {
  9789. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9790. if(log == NULL)
  9791. {
  9792. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9793. return ;
  9794. }
  9795. else
  9796. {
  9797. fclose(log);
  9798. }
  9799. }
  9800. // open file for writing
  9801. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9802. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9803. {
  9804. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9805. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9806. fputs(data, outfile);
  9807. fclose (outfile);
  9808. }
  9809. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9810. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9811. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9812. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9813. }
  9814. void handleStatusNotificationResponse(char *payload, int gun_index)
  9815. {
  9816. mtrace();
  9817. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9818. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9819. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9820. }
  9821. void handleStopTransactionnResponse(char *payload, int gun_index)
  9822. {
  9823. mtrace();
  9824. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9825. json_object *StopTransaction;
  9826. StopTransaction = json_tokener_parse(payload);
  9827. if(!is_error(StopTransaction))
  9828. {
  9829. // Optional data
  9830. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9831. {
  9832. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9833. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9834. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9835. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9836. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9837. }
  9838. }
  9839. json_object_put(StopTransaction);
  9840. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9841. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9842. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9843. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9844. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9845. }
  9846. //==========================================
  9847. // Handle Error routine
  9848. //==========================================
  9849. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9850. {
  9851. mtrace();
  9852. #ifdef SystemLogMessage
  9853. DEBUG_INFO("errorCode: %s\n", errorCode);
  9854. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9855. DEBUG_INFO("errorDetails: %s\n", payload);
  9856. #endif
  9857. }
  9858. //===============================================
  9859. // Common routine
  9860. //===============================================
  9861. int initialConfigurationTable(void)
  9862. {
  9863. //clock_t start_t, end_t, total_t;
  9864. FILE *fp;
  9865. FILE *outfile;
  9866. char str[200]={0};
  9867. char sstr[100]={0};
  9868. int c = 0;
  9869. char *loc;
  9870. DEBUG_INFO("initialConfigurationTable...\n");
  9871. //start_t = clock();
  9872. //printf("Starting of the program, start_t = %ld\n", start_t);
  9873. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9874. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9875. {
  9876. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9877. if(outfile == NULL)
  9878. {
  9879. DEBUG_INFO("Error opening file\n");
  9880. return FALSE;
  9881. }
  9882. /*Core Profile*/
  9883. //AllowOfflineTxForUnknownId
  9884. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9885. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  9886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  9889. //AuthorizationCacheEnabled
  9890. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9891. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  9894. //AuthorizeRemoteTxRequests
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  9899. //BlinkRepeat
  9900. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9903. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  9904. //ClockAlignedDataInterval
  9905. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  9909. //ConnectionTimeOut
  9910. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9912. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  9914. //GetConfigurationMaxKeys
  9915. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  9918. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  9919. // HeartbeatInterval
  9920. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9922. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  9923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  9924. // LightIntensity
  9925. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9928. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  9929. // LocalAuthorizeOffline
  9930. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9933. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  9934. // LocalPreAuthorize
  9935. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9937. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9938. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  9939. // MaxEnergyOnInvalidId
  9940. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9943. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  9945. // MeterValuesAlignedData
  9946. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9947. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "" );
  9949. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "");
  9950. // MeterValuesAlignedDataMaxLength
  9951. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9952. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9953. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9954. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  9955. // MeterValuesSampledData
  9956. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9957. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9959. 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");
  9960. // MeterValuesSampledDataMaxLength
  9961. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9964. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  9965. // MeterValueSampleInterval
  9966. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  9969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  9970. // MinimumStatusDuration
  9971. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9974. server_cycle_Status = 120; //StatusNotification cycle
  9975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  9976. // NumberOfConnectors
  9977. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9979. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9980. {
  9981. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9982. }
  9983. else
  9984. {
  9985. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9986. }
  9987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9988. // ResetRetries
  9989. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9992. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  9993. // ConnectorPhaseRotation
  9994. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9996. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9997. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  9998. // ConnectorPhaseRotationMaxLength
  9999. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10003. // StopTransactionOnEVSideDisconnect
  10004. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10008. // StopTransactionOnInvalidId
  10009. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10013. // StopTxnAlignedData
  10014. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10018. // StopTxnAlignedDataMaxLength
  10019. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10023. // StopTxnSampledData
  10024. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10025. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10027. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10028. // StopTxnSampledDataMaxLength
  10029. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10032. {
  10033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10034. }
  10035. else
  10036. {
  10037. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10038. }
  10039. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10040. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10041. // SupportedFeatureProfiles
  10042. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10044. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10045. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10046. // SupportedFeatureProfilesMaxLength
  10047. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10049. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10050. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10051. // TransactionMessageAttempts
  10052. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10054. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10055. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10056. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10057. // TransactionMessageRetryInterval
  10058. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10059. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10061. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10063. // UnlockConnectorOnEVSideDisconnect
  10064. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10068. // WebSocketPingInterval
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10073. //* Local Auth List Management Profile*/
  10074. #if 0
  10075. //For OCTT Test Case
  10076. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10079. #endif
  10080. #if 1
  10081. //LocalAuthListEnabled
  10082. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10086. #endif
  10087. //LocalAuthListMaxLength
  10088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10092. //SendLocalListMaxLength
  10093. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10097. //ReserveConnectorZeroSupported
  10098. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10102. //* Smart Charging Profile */
  10103. //ChargeProfileMaxStackLevel
  10104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10108. // ChargingScheduleAllowedChargingRateUnit
  10109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10113. // ChargingScheduleMaxPeriods
  10114. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10118. // ConnectorSwitch3to1PhaseSupported
  10119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10123. // MaxChargingProfilesInstalled
  10124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10128. fclose(outfile);
  10129. }
  10130. else
  10131. {
  10132. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10133. char keystr[60]={0};
  10134. char readonlystr[10]={0};
  10135. char valuestr[100]={0};
  10136. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10137. if(fp == NULL) {
  10138. DEBUG_INFO("Error opening file");
  10139. return FALSE;
  10140. }
  10141. while( fgets (str, sizeof(str), fp)!=NULL )
  10142. {
  10143. //DEBUG_INFO("Get Configuration \n");
  10144. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10145. //*************************key*********************************/
  10146. loc = strstr(str, "key");
  10147. c = 0;
  10148. memset(sstr ,0, sizeof(sstr) );
  10149. while (loc[strlen("key")+3+c] != '\"')
  10150. {
  10151. sstr[c] = loc[strlen("key")+3+c];
  10152. c++;
  10153. }
  10154. sstr[c] = '\0';
  10155. strcpy(keystr,sstr);
  10156. //*************************readonly*********************************/
  10157. loc = strstr(str, "readonly");
  10158. c = 0;
  10159. memset(sstr ,0, sizeof(sstr) );
  10160. while (loc[strlen("readonly")+2+c] != ',')
  10161. {
  10162. sstr[c] = loc[strlen("readonly")+2+c];
  10163. c++;
  10164. }
  10165. sstr[c] = '\0';
  10166. strcpy(readonlystr,sstr);
  10167. //*************************value*********************************/
  10168. loc = strstr(str, "value");
  10169. c = 0;
  10170. memset(sstr ,0, sizeof(sstr) );
  10171. while (loc[strlen("value")+3+c] != '\"')
  10172. {
  10173. sstr[c] = loc[strlen("value")+3+c];
  10174. c++;
  10175. }
  10176. sstr[c] = '\0';
  10177. strcpy(valuestr,sstr);
  10178. // DEBUG_INFO("keystr=%s\n",keystr);
  10179. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10180. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10181. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10182. {
  10183. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10186. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10187. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10188. }
  10189. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10190. {
  10191. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10194. }
  10195. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "BlinkRepeat") == 0)
  10201. {
  10202. //Charger.BlinkRepeat = Integer.parseInt(value);
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10205. }
  10206. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10207. {
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10210. }
  10211. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10212. {
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10215. }
  10216. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10217. {
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10220. }
  10221. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10222. {
  10223. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10225. HeartBeatWaitTime = atoi(valuestr);
  10226. }
  10227. if(strcmp(keystr, "LightIntensity") == 0)
  10228. {
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10231. }
  10232. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10233. {
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10236. }
  10237. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10238. {
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10241. }
  10242. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10243. {
  10244. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10246. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10247. }
  10248. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10249. {
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10252. }
  10253. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10254. {
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10257. }
  10258. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10259. {
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10262. }
  10263. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10264. {
  10265. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10267. }
  10268. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10269. {
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10272. }
  10273. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10274. {
  10275. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10277. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10278. }
  10279. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10280. {
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10283. }
  10284. if(strcmp(keystr, "ResetRetries") == 0)
  10285. {
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10288. }
  10289. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10290. {
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10293. }
  10294. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10295. {
  10296. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10298. }
  10299. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10300. {
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10303. }
  10304. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10305. {
  10306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10308. }
  10309. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10310. {
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10313. }
  10314. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10315. {
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10318. }
  10319. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10320. {
  10321. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10323. }
  10324. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10325. {
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10328. }
  10329. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10330. {
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10333. }
  10334. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10335. {
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10338. }
  10339. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10340. {
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10343. TransactionMessageAttemptsValue = atoi(valuestr);
  10344. }
  10345. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10346. {
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10349. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10350. }
  10351. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10352. {
  10353. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10355. }
  10356. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10357. {
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10360. }
  10361. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10362. {
  10363. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10365. }
  10366. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10370. }
  10371. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10375. }
  10376. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10380. }
  10381. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10385. }
  10386. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10390. }
  10391. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10392. {
  10393. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10395. }
  10396. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10397. {
  10398. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10400. }
  10401. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10402. {
  10403. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10405. }
  10406. }
  10407. fclose(fp);
  10408. }
  10409. return 0;
  10410. }
  10411. void StoreConfigurationTable(void)
  10412. {
  10413. FILE *outfile;
  10414. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10415. if(outfile == NULL)
  10416. {
  10417. DEBUG_INFO("Error opening file");
  10418. return ;
  10419. }
  10420. /*Core Profile*/
  10421. //AllowOfflineTxForUnknownId
  10422. /*
  10423. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10424. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10425. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10426. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10427. */
  10428. //DEBUG_INFO("data=%s\n",data);
  10429. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10430. //AuthorizationCacheEnabled
  10431. /*
  10432. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10433. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10434. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10435. */
  10436. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10437. //AuthorizeRemoteTxRequests
  10438. /*
  10439. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10440. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10441. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10442. */
  10443. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10444. //BlinkRepeat
  10445. /*
  10446. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10447. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10448. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10449. */
  10450. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10451. //ClockAlignedDataInterval
  10452. /*
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10454. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10456. */
  10457. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10458. //ConnectionTimeOut
  10459. /*
  10460. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10461. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10462. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10463. */
  10464. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10465. //GetConfigurationMaxKeys
  10466. /*
  10467. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10468. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10469. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10470. */
  10471. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10472. // HeartbeatInterval
  10473. /*
  10474. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10475. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10476. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10477. */
  10478. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10479. // LightIntensity
  10480. /*
  10481. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10482. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10483. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10484. */
  10485. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10486. // LocalAuthorizeOffline
  10487. /*
  10488. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10489. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10490. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10491. */
  10492. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10493. // LocalPreAuthorize
  10494. /*
  10495. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10496. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10497. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10498. */
  10499. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10500. // MaxEnergyOnInvalidId
  10501. /*
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10503. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10504. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10505. */
  10506. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10507. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10508. // MeterValuesAlignedData
  10509. /*
  10510. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10511. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10513. */
  10514. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10515. // MeterValuesAlignedDataMaxLength
  10516. /*
  10517. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10518. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10520. */
  10521. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10522. // MeterValuesSampledData
  10523. /*
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10525. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10527. */
  10528. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10529. // MeterValuesSampledDataMaxLength
  10530. /*
  10531. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10532. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10534. */
  10535. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10536. // MeterValueSampleInterval
  10537. /*
  10538. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10539. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10540. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10541. */
  10542. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10543. // MinimumStatusDuration
  10544. /*
  10545. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10546. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10547. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10548. */
  10549. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10550. // NumberOfConnectors
  10551. /*
  10552. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10553. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10554. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10555. {
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10557. }
  10558. else
  10559. {
  10560. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10561. }
  10562. */
  10563. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10564. // ResetRetries
  10565. /*
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10567. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10568. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10569. */
  10570. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10571. // ConnectorPhaseRotation
  10572. /*
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10574. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10575. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10576. */
  10577. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10578. // ConnectorPhaseRotationMaxLength
  10579. /*
  10580. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10581. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10582. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10583. */
  10584. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10585. // StopTransactionOnEVSideDisconnect
  10586. /*
  10587. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10588. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10589. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10590. */
  10591. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10592. // StopTransactionOnInvalidId
  10593. /*
  10594. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10595. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10596. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10597. */
  10598. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10599. // StopTxnAlignedData
  10600. /*
  10601. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10602. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10603. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10604. */
  10605. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10606. // StopTxnAlignedDataMaxLength
  10607. /*
  10608. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10609. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10610. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10611. */
  10612. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10613. // StopTxnSampledData
  10614. /*
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10616. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10617. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10618. */
  10619. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10620. // StopTxnSampledDataMaxLength
  10621. /*
  10622. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10623. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10624. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10625. */
  10626. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10627. // SupportedFeatureProfiles
  10628. /*
  10629. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10630. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10631. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10632. */
  10633. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10634. // SupportedFeatureProfilesMaxLength
  10635. /*
  10636. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10637. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10638. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10639. */
  10640. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10641. // TransactionMessageAttempts
  10642. /*
  10643. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10644. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10645. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10646. */
  10647. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10648. // TransactionMessageRetryInterval
  10649. /*
  10650. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10651. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10652. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10653. */
  10654. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10655. // UnlockConnectorOnEVSideDisconnect
  10656. /*
  10657. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10658. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10659. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10660. */
  10661. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10662. // WebSocketPingInterval
  10663. /*
  10664. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10665. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10666. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10667. */
  10668. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10669. //* Local Auth List Management Profile*/
  10670. //LocalAuthListEnabled
  10671. /*
  10672. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10673. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10675. */
  10676. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10677. //LocalAuthListMaxLength
  10678. /*
  10679. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10680. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10682. */
  10683. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10684. //SendLocalListMaxLength
  10685. /*
  10686. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10689. */
  10690. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10691. //ReserveConnectorZeroSupported
  10692. /*
  10693. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10694. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10696. */
  10697. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10698. //* Smart Charging Profile */
  10699. //ChargeProfileMaxStackLevel
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10706. // ChargingScheduleAllowedChargingRateUnit
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10713. // ChargingScheduleMaxPeriods
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10720. // ConnectorSwitch3to1PhaseSupported
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10725. */
  10726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10727. // MaxChargingProfilesInstalled
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10734. fclose(outfile);
  10735. }
  10736. void getKeyValue(char *keyReq)
  10737. {
  10738. int isEmpty = FALSE;
  10739. int isKnowKey = FALSE;
  10740. DEBUG_INFO("keyReq = %s\n", keyReq);
  10741. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10742. isEmpty = TRUE;
  10743. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10744. {
  10745. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10747. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10748. {
  10749. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10750. }
  10751. else
  10752. {
  10753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10754. }
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10756. isKnowKey = TRUE;
  10757. }
  10758. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10759. {
  10760. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10762. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10763. {
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10765. }
  10766. else
  10767. {
  10768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10769. }
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10771. isKnowKey = TRUE;
  10772. }
  10773. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10774. {
  10775. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10777. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10778. {
  10779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10780. }
  10781. else
  10782. {
  10783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10784. }
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10786. isKnowKey = TRUE;
  10787. }
  10788. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10789. {
  10790. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10792. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10793. {
  10794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10795. }
  10796. else
  10797. {
  10798. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10799. }
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10801. isKnowKey = TRUE;
  10802. }
  10803. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10804. {
  10805. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10807. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10808. {
  10809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10810. }
  10811. else
  10812. {
  10813. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10814. }
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10816. isKnowKey = TRUE;
  10817. }
  10818. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10819. {
  10820. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10822. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10823. {
  10824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10825. }
  10826. else
  10827. {
  10828. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10829. }
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10831. isKnowKey = TRUE;
  10832. }
  10833. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10834. {
  10835. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10837. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10838. {
  10839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10840. }
  10841. else
  10842. {
  10843. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10844. }
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10846. isKnowKey = TRUE;
  10847. }
  10848. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10849. {
  10850. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10852. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10853. {
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10855. }
  10856. else
  10857. {
  10858. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10859. }
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10861. isKnowKey = TRUE;
  10862. }
  10863. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10864. {
  10865. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10867. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10868. {
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10870. }
  10871. else
  10872. {
  10873. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10874. }
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10876. isKnowKey = TRUE;
  10877. }
  10878. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10879. {
  10880. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10882. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10883. {
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10885. }
  10886. else
  10887. {
  10888. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10889. }
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10891. isKnowKey = TRUE;
  10892. }
  10893. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10894. {
  10895. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10897. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10898. {
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10900. }
  10901. else
  10902. {
  10903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10904. }
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10906. isKnowKey = TRUE;
  10907. }
  10908. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10909. {
  10910. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10912. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10913. {
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10915. }
  10916. else
  10917. {
  10918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10919. }
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10921. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10922. isKnowKey = TRUE;
  10923. }
  10924. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10931. }
  10932. else
  10933. {
  10934. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10935. }
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10937. isKnowKey = TRUE;
  10938. }
  10939. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10943. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10946. }
  10947. else
  10948. {
  10949. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10950. }
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10952. isKnowKey = TRUE;
  10953. }
  10954. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10958. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10961. }
  10962. else
  10963. {
  10964. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10965. }
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10967. isKnowKey = TRUE;
  10968. }
  10969. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10976. }
  10977. else
  10978. {
  10979. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10980. }
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10982. isKnowKey = TRUE;
  10983. }
  10984. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10988. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10991. }
  10992. else
  10993. {
  10994. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10995. }
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10997. isKnowKey = TRUE;
  10998. }
  10999. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11000. {
  11001. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11004. {
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11006. }
  11007. else
  11008. {
  11009. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11010. }
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11012. isKnowKey = TRUE;
  11013. }
  11014. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11015. {
  11016. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11018. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11019. {
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11021. }
  11022. else
  11023. {
  11024. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11025. }
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11027. isKnowKey = TRUE;
  11028. }
  11029. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11030. {
  11031. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11033. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11034. {
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11036. }
  11037. else
  11038. {
  11039. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11040. }
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11042. isKnowKey = TRUE;
  11043. }
  11044. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11045. {
  11046. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11049. {
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11051. }
  11052. else
  11053. {
  11054. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11055. }
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11057. isKnowKey = TRUE;
  11058. }
  11059. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11060. {
  11061. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11063. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11064. {
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11066. }
  11067. else
  11068. {
  11069. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11070. }
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11072. isKnowKey = TRUE;
  11073. }
  11074. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11075. {
  11076. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11079. {
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11081. }
  11082. else
  11083. {
  11084. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11085. }
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11087. isKnowKey = TRUE;
  11088. }
  11089. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11090. {
  11091. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11093. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11094. {
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11096. }
  11097. else
  11098. {
  11099. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11100. }
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11102. isKnowKey = TRUE;
  11103. }
  11104. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11105. {
  11106. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11108. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11109. {
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11111. }
  11112. else
  11113. {
  11114. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11115. }
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11117. isKnowKey = TRUE;
  11118. }
  11119. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11120. {
  11121. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11123. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11124. {
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11126. }
  11127. else
  11128. {
  11129. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11130. }
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11132. isKnowKey = TRUE;
  11133. }
  11134. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11135. {
  11136. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11138. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11139. {
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11141. }
  11142. else
  11143. {
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11145. }
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11147. isKnowKey = TRUE;
  11148. }
  11149. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11150. {
  11151. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11154. {
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11156. }
  11157. else
  11158. {
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11160. }
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11162. isKnowKey = TRUE;
  11163. }
  11164. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11165. {
  11166. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11168. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11169. {
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11171. }
  11172. else
  11173. {
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11175. }
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11177. isKnowKey = TRUE;
  11178. }
  11179. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11180. {
  11181. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11183. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11184. {
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11186. }
  11187. else
  11188. {
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11190. }
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11192. isKnowKey = TRUE;
  11193. }
  11194. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11195. {
  11196. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11198. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11199. {
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11201. }
  11202. else
  11203. {
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11205. }
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11207. isKnowKey = TRUE;
  11208. }
  11209. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11210. {
  11211. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11214. {
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11216. }
  11217. else
  11218. {
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11220. }
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11222. isKnowKey = TRUE;
  11223. }
  11224. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11225. {
  11226. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11228. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11231. }
  11232. else
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11235. }
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11237. isKnowKey = TRUE;
  11238. }
  11239. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11240. {
  11241. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11243. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11246. }
  11247. else
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11250. }
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11252. isKnowKey = TRUE;
  11253. }
  11254. #if 1
  11255. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11259. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11262. }
  11263. else
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11266. }
  11267. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11268. isKnowKey = TRUE;
  11269. }
  11270. #endif
  11271. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11274. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11275. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11278. }
  11279. else
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11282. }
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11284. isKnowKey = TRUE;
  11285. }
  11286. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11290. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11293. }
  11294. else
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11297. }
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11299. isKnowKey = TRUE;
  11300. }
  11301. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11305. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11308. }
  11309. else
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11312. }
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11314. isKnowKey = TRUE;
  11315. }
  11316. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11320. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11323. }
  11324. else
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11327. }
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11329. isKnowKey = TRUE;
  11330. }
  11331. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11335. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11338. }
  11339. else
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11342. }
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11344. isKnowKey = TRUE;
  11345. }
  11346. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11350. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11353. }
  11354. else
  11355. {
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11357. }
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11359. isKnowKey = TRUE;
  11360. }
  11361. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11364. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11365. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11368. }
  11369. else
  11370. {
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11372. }
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11374. isKnowKey = TRUE;
  11375. }
  11376. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11379. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11380. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11383. }
  11384. else
  11385. {
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11387. }
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11389. isKnowKey = TRUE;
  11390. }
  11391. //=========================================================
  11392. if(!isEmpty && !isKnowKey)
  11393. {
  11394. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11395. strcpy(unknownkey[UnknownKeynum], keyReq);
  11396. UnknownKeynum = UnknownKeynum + 1;
  11397. }
  11398. }
  11399. void processUnkownKey(void)
  11400. {
  11401. DEBUG_INFO("processUnkownKey...\n");
  11402. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11403. for(int index=0; index < UnknownKeynum; index++)
  11404. {
  11405. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11406. {
  11407. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11408. }
  11409. }
  11410. }
  11411. int setKeyValue(char *key, char *value)
  11412. {
  11413. int isSuccess = NotSupported;
  11414. int check_ascii=0;
  11415. char str[10]={0};
  11416. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11417. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11418. {
  11419. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11420. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11421. {
  11422. strcpy(str, (const char*)value);
  11423. for(int i = 0; str[i]; i++){
  11424. str[i] = tolower(str[i]);
  11425. }
  11426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11427. isSuccess = ConfigurationStatus_Accepted;
  11428. }
  11429. else
  11430. {
  11431. isSuccess = ConfigurationStatus_Rejected;
  11432. }
  11433. }
  11434. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11435. {
  11436. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11438. {
  11439. strcpy(str, (const char*)value);
  11440. for(int i = 0; str[i]; i++){
  11441. str[i] = tolower(str[i]);
  11442. }
  11443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11444. isSuccess = ConfigurationStatus_Accepted;
  11445. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11446. }
  11447. else
  11448. {
  11449. isSuccess = ConfigurationStatus_Rejected;
  11450. }
  11451. }
  11452. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11453. {
  11454. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11455. {
  11456. strcpy(str, (const char*)value);
  11457. for(int i = 0; str[i]; i++)
  11458. {
  11459. str[i] = tolower(str[i]);
  11460. }
  11461. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11463. isSuccess = ConfigurationStatus_Accepted;
  11464. }
  11465. else
  11466. {
  11467. isSuccess = ConfigurationStatus_Rejected;
  11468. }
  11469. }
  11470. if(strcmp(key, "BlinkRepeat") == 0)
  11471. {
  11472. //Charger.BlinkRepeat = Integer.parseInt(value);
  11473. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11474. {
  11475. check_ascii = value[0];
  11476. if( (check_ascii < 48) || (check_ascii > 57) )
  11477. {
  11478. isSuccess = ConfigurationStatus_Rejected;
  11479. }
  11480. else
  11481. {
  11482. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11483. isSuccess = ConfigurationStatus_Accepted;
  11484. }
  11485. }
  11486. else
  11487. {
  11488. isSuccess = ConfigurationStatus_Rejected;
  11489. }
  11490. }
  11491. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11492. {
  11493. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11494. {
  11495. check_ascii = value[0];
  11496. if( (check_ascii < 48) || (check_ascii > 57) )
  11497. {
  11498. isSuccess = ConfigurationStatus_Rejected;
  11499. }
  11500. else
  11501. {
  11502. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11504. isSuccess = ConfigurationStatus_Accepted;
  11505. }
  11506. }
  11507. else
  11508. {
  11509. isSuccess = ConfigurationStatus_Rejected;
  11510. }
  11511. }
  11512. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11513. {
  11514. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11515. {
  11516. check_ascii = value[0];
  11517. if( (check_ascii < 48) || (check_ascii > 57) )
  11518. {
  11519. isSuccess = ConfigurationStatus_Rejected;
  11520. }
  11521. else
  11522. {
  11523. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11525. isSuccess = ConfigurationStatus_Accepted;
  11526. }
  11527. }
  11528. else
  11529. {
  11530. isSuccess = ConfigurationStatus_Rejected;
  11531. }
  11532. }
  11533. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11534. {
  11535. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11536. {
  11537. check_ascii = value[0];
  11538. if( (check_ascii < 48) || (check_ascii > 57) )
  11539. {
  11540. isSuccess = ConfigurationStatus_Rejected;
  11541. }
  11542. else
  11543. {
  11544. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11546. isSuccess = ConfigurationStatus_Accepted;
  11547. }
  11548. }
  11549. else
  11550. {
  11551. isSuccess = ConfigurationStatus_Rejected;
  11552. }
  11553. }
  11554. if(strcmp(key, "HeartbeatInterval") == 0)
  11555. {
  11556. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11557. {
  11558. check_ascii = value[0];
  11559. if( (check_ascii < 48) || (check_ascii > 57) )
  11560. {
  11561. isSuccess = ConfigurationStatus_Rejected;
  11562. }
  11563. else
  11564. {
  11565. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11566. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11567. HeartBeatWaitTime = atoi(value);
  11568. isSuccess = ConfigurationStatus_Accepted;
  11569. }
  11570. }
  11571. else
  11572. {
  11573. isSuccess = ConfigurationStatus_Rejected;
  11574. }
  11575. }
  11576. if(strcmp(key, "LightIntensity") == 0)
  11577. {
  11578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11579. {
  11580. check_ascii = value[0];
  11581. if( (check_ascii < 48) || (check_ascii > 57) )
  11582. {
  11583. isSuccess = ConfigurationStatus_Rejected;
  11584. }
  11585. else
  11586. {
  11587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11588. isSuccess = ConfigurationStatus_Accepted;
  11589. }
  11590. }
  11591. else
  11592. {
  11593. isSuccess = ConfigurationStatus_Rejected;
  11594. }
  11595. }
  11596. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11597. {
  11598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11599. {
  11600. strcpy(str, (const char*)value);
  11601. for(int i = 0; str[i]; i++)
  11602. {
  11603. str[i] = tolower(str[i]);
  11604. }
  11605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11606. isSuccess = ConfigurationStatus_Accepted;
  11607. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11608. }
  11609. else
  11610. {
  11611. isSuccess = ConfigurationStatus_Rejected;
  11612. }
  11613. }
  11614. if(strcmp(key, "LocalPreAuthorize") == 0)
  11615. {
  11616. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11617. {
  11618. strcpy(str, (const char*)value);
  11619. for(int i = 0; str[i]; i++)
  11620. {
  11621. str[i] = tolower(str[i]);
  11622. }
  11623. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11624. isSuccess = ConfigurationStatus_Accepted;
  11625. }
  11626. else
  11627. {
  11628. isSuccess = ConfigurationStatus_Rejected;
  11629. }
  11630. }
  11631. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11632. {
  11633. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11634. {
  11635. check_ascii = value[0];
  11636. if( (check_ascii < 48) || (check_ascii > 57) )
  11637. {
  11638. isSuccess = ConfigurationStatus_Rejected;
  11639. }
  11640. else
  11641. {
  11642. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11643. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11644. isSuccess = ConfigurationStatus_Accepted;
  11645. }
  11646. }
  11647. else
  11648. {
  11649. isSuccess = ConfigurationStatus_Rejected;
  11650. }
  11651. }
  11652. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11653. {
  11654. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11655. {
  11656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11657. isSuccess = ConfigurationStatus_Accepted;
  11658. }
  11659. else
  11660. {
  11661. isSuccess = ConfigurationStatus_Rejected;
  11662. }
  11663. }
  11664. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11665. {
  11666. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11667. {
  11668. check_ascii = value[0];
  11669. if( (check_ascii < 48) || (check_ascii > 57) )
  11670. {
  11671. isSuccess = ConfigurationStatus_Rejected;
  11672. }
  11673. else
  11674. {
  11675. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11676. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11677. isSuccess = ConfigurationStatus_Accepted;
  11678. }
  11679. }
  11680. else
  11681. {
  11682. isSuccess = ConfigurationStatus_Rejected;
  11683. }
  11684. }
  11685. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11686. {
  11687. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11688. {
  11689. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11690. isSuccess = ConfigurationStatus_Accepted;
  11691. }
  11692. else
  11693. {
  11694. isSuccess = ConfigurationStatus_Rejected;
  11695. }
  11696. }
  11697. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11698. {
  11699. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11700. {
  11701. check_ascii = value[0];
  11702. if( (check_ascii < 48) || (check_ascii > 57) )
  11703. {
  11704. isSuccess = ConfigurationStatus_Rejected;
  11705. }
  11706. else
  11707. {
  11708. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11709. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11710. isSuccess = ConfigurationStatus_Accepted;
  11711. }
  11712. }
  11713. else
  11714. {
  11715. isSuccess = ConfigurationStatus_Rejected;
  11716. }
  11717. }
  11718. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11719. {
  11720. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11721. {
  11722. check_ascii = value[0];
  11723. if( (check_ascii < 48) || (check_ascii > 57) )
  11724. {
  11725. isSuccess = ConfigurationStatus_Rejected;
  11726. }
  11727. else
  11728. {
  11729. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11731. isSuccess = ConfigurationStatus_Accepted;
  11732. }
  11733. }
  11734. else
  11735. {
  11736. isSuccess = ConfigurationStatus_Rejected;
  11737. }
  11738. }
  11739. if(strcmp(key, "MinimumStatusDuration") == 0)
  11740. {
  11741. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11742. {
  11743. check_ascii = value[0];
  11744. if( (check_ascii < 48) || (check_ascii > 57) )
  11745. {
  11746. isSuccess = ConfigurationStatus_Rejected;
  11747. }
  11748. else
  11749. {
  11750. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. else
  11755. {
  11756. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11757. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11758. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11759. isSuccess = ConfigurationStatus_Accepted;
  11760. }
  11761. }
  11762. }
  11763. else
  11764. {
  11765. isSuccess = ConfigurationStatus_Rejected;
  11766. }
  11767. }
  11768. if(strcmp(key, "NumberOfConnectors") == 0)
  11769. {
  11770. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11771. {
  11772. check_ascii = value[0];
  11773. if( (check_ascii < 48) || (check_ascii > 57) )
  11774. {
  11775. isSuccess = ConfigurationStatus_Rejected;
  11776. }
  11777. else
  11778. {
  11779. //Charger.ResetRetries = Integer.parseInt(value);
  11780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11781. isSuccess = ConfigurationStatus_Accepted;
  11782. }
  11783. }
  11784. else
  11785. {
  11786. isSuccess = ConfigurationStatus_Rejected;
  11787. }
  11788. }
  11789. if(strcmp(key, "ResetRetries") == 0)
  11790. {
  11791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11792. {
  11793. check_ascii = value[0];
  11794. if( (check_ascii < 48) || (check_ascii > 57) )
  11795. {
  11796. isSuccess = ConfigurationStatus_Rejected;
  11797. }
  11798. else
  11799. {
  11800. //Charger.ResetRetries = Integer.parseInt(value);
  11801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11802. isSuccess = ConfigurationStatus_Accepted;
  11803. }
  11804. }
  11805. else
  11806. {
  11807. isSuccess = ConfigurationStatus_Rejected;
  11808. }
  11809. }
  11810. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11811. {
  11812. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11813. {
  11814. strcpy(str, (const char*)value);
  11815. for(int i = 0; str[i]; i++)
  11816. {
  11817. str[i] = tolower(str[i]);
  11818. }
  11819. if(strcmp(str, "notapplicable")== 0)
  11820. {
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. else if(strcmp(str, "unknown")== 0)
  11825. {
  11826. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11827. isSuccess = ConfigurationStatus_Accepted;
  11828. }
  11829. else if(strcmp(str, "rst")== 0)
  11830. {
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. else if(strcmp(str, "rts")== 0)
  11835. {
  11836. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11837. isSuccess = ConfigurationStatus_Accepted;
  11838. }
  11839. else if(strcmp(str, "srt")== 0)
  11840. {
  11841. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11842. isSuccess = ConfigurationStatus_Accepted;
  11843. }
  11844. else if(strcmp(str, "str")== 0)
  11845. {
  11846. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11847. isSuccess = ConfigurationStatus_Accepted;
  11848. }
  11849. else if(strcmp(str, "trs")== 0)
  11850. {
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. else if(strcmp(str, "tsr")== 0)
  11855. {
  11856. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11857. isSuccess = ConfigurationStatus_Accepted;
  11858. }
  11859. else
  11860. {
  11861. isSuccess = ConfigurationStatus_Rejected;
  11862. }
  11863. }
  11864. else
  11865. {
  11866. isSuccess = ConfigurationStatus_Rejected;
  11867. }
  11868. }
  11869. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11870. {
  11871. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11872. {
  11873. check_ascii = value[0];
  11874. if( (check_ascii < 48) || (check_ascii > 57) )
  11875. {
  11876. isSuccess = ConfigurationStatus_Rejected;
  11877. }
  11878. else
  11879. {
  11880. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11881. isSuccess = ConfigurationStatus_Accepted;
  11882. }
  11883. }
  11884. else
  11885. {
  11886. isSuccess = ConfigurationStatus_Rejected;
  11887. }
  11888. }
  11889. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11890. {
  11891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11892. {
  11893. strcpy(str, (const char*)value);
  11894. for(int i = 0; str[i]; i++)
  11895. {
  11896. str[i] = tolower(str[i]);
  11897. }
  11898. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11900. isSuccess = ConfigurationStatus_Accepted;
  11901. }
  11902. else
  11903. {
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11908. {
  11909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11910. {
  11911. strcpy(str, (const char*)value);
  11912. for(int i = 0; str[i]; i++)
  11913. {
  11914. str[i] = tolower(str[i]);
  11915. }
  11916. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11918. isSuccess = ConfigurationStatus_Accepted;
  11919. }
  11920. else
  11921. {
  11922. isSuccess = ConfigurationStatus_Rejected;
  11923. }
  11924. }
  11925. if(strcmp(key, "StopTxnAlignedData") == 0)
  11926. {
  11927. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11928. {
  11929. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  11930. isSuccess = ConfigurationStatus_Accepted;
  11931. }
  11932. else
  11933. {
  11934. isSuccess = ConfigurationStatus_Rejected;
  11935. }
  11936. }
  11937. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  11938. {
  11939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11940. {
  11941. check_ascii = value[0];
  11942. if( (check_ascii < 48) || (check_ascii > 57) )
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. else
  11947. {
  11948. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  11949. isSuccess = ConfigurationStatus_Accepted;
  11950. }
  11951. }
  11952. else
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. }
  11957. if(strcmp(key, "StopTxnSampledData") == 0)
  11958. {
  11959. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11960. {
  11961. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  11962. isSuccess = ConfigurationStatus_Accepted;
  11963. }
  11964. else
  11965. {
  11966. isSuccess = ConfigurationStatus_Rejected;
  11967. }
  11968. }
  11969. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  11970. {
  11971. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11972. {
  11973. check_ascii = value[0];
  11974. if( (check_ascii < 48) || (check_ascii > 57) )
  11975. {
  11976. isSuccess = ConfigurationStatus_Rejected;
  11977. }
  11978. else
  11979. {
  11980. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  11981. isSuccess = ConfigurationStatus_Accepted;
  11982. }
  11983. }
  11984. else
  11985. {
  11986. isSuccess = ConfigurationStatus_Rejected;
  11987. }
  11988. }
  11989. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  11990. {
  11991. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11992. {
  11993. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  11994. isSuccess = ConfigurationStatus_Accepted;
  11995. }
  11996. else
  11997. {
  11998. isSuccess = ConfigurationStatus_Rejected;
  11999. }
  12000. }
  12001. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12002. {
  12003. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12004. {
  12005. check_ascii = value[0];
  12006. if( (check_ascii < 48) || (check_ascii > 57) )
  12007. {
  12008. isSuccess = ConfigurationStatus_Rejected;
  12009. }
  12010. else
  12011. {
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. }
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12022. {
  12023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12024. {
  12025. check_ascii = value[0];
  12026. if( (check_ascii < 48) || (check_ascii > 57) )
  12027. {
  12028. isSuccess = ConfigurationStatus_Rejected;
  12029. }
  12030. else
  12031. {
  12032. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12034. TransactionMessageAttemptsValue = atoi(value);
  12035. isSuccess = ConfigurationStatus_Accepted;
  12036. }
  12037. }
  12038. else
  12039. {
  12040. isSuccess = ConfigurationStatus_Rejected;
  12041. }
  12042. }
  12043. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12044. {
  12045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12046. {
  12047. check_ascii = value[0];
  12048. if( (check_ascii < 48) || (check_ascii > 57) )
  12049. {
  12050. isSuccess = ConfigurationStatus_Rejected;
  12051. }
  12052. else
  12053. {
  12054. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12055. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12056. TransactionMessageRetryIntervalValue = atoi(value);
  12057. isSuccess = ConfigurationStatus_Accepted;
  12058. }
  12059. }
  12060. else
  12061. {
  12062. isSuccess = ConfigurationStatus_Rejected;
  12063. }
  12064. }
  12065. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12066. {
  12067. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12068. {
  12069. strcpy(str, (const char*)value);
  12070. for(int i = 0; str[i]; i++)
  12071. {
  12072. str[i] = tolower(str[i]);
  12073. }
  12074. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12075. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12076. isSuccess = ConfigurationStatus_Accepted;
  12077. }
  12078. else
  12079. {
  12080. isSuccess = ConfigurationStatus_Rejected;
  12081. }
  12082. }
  12083. if(strcmp(key, "WebSocketPingInterval") == 0)
  12084. {
  12085. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12086. {
  12087. check_ascii = value[0];
  12088. if( (check_ascii < 48) || (check_ascii > 57) )
  12089. {
  12090. isSuccess = ConfigurationStatus_Rejected;
  12091. }
  12092. else
  12093. {
  12094. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12095. isSuccess = ConfigurationStatus_Accepted;
  12096. }
  12097. }
  12098. else
  12099. {
  12100. isSuccess = ConfigurationStatus_Rejected;
  12101. }
  12102. }
  12103. #if 0
  12104. //For OCPP Test Case
  12105. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12106. {
  12107. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12108. {
  12109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12110. isSuccess = ConfigurationStatus_Accepted;
  12111. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12112. }
  12113. else
  12114. {
  12115. isSuccess = ConfigurationStatus_Rejected;
  12116. }
  12117. }
  12118. #endif
  12119. #if 1
  12120. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12121. {
  12122. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12123. {
  12124. strcpy(str, (const char*)value);
  12125. for(int i = 0; str[i]; i++)
  12126. {
  12127. str[i] = tolower(str[i]);
  12128. }
  12129. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12130. isSuccess = ConfigurationStatus_Accepted;
  12131. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12132. }
  12133. else
  12134. {
  12135. isSuccess = ConfigurationStatus_Rejected;
  12136. }
  12137. }
  12138. #endif
  12139. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12140. {
  12141. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12142. {
  12143. check_ascii = value[0];
  12144. if( (check_ascii < 48) || (check_ascii > 57) )
  12145. {
  12146. isSuccess = ConfigurationStatus_Rejected;
  12147. }
  12148. else
  12149. {
  12150. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12151. isSuccess = ConfigurationStatus_Accepted;
  12152. }
  12153. }
  12154. else
  12155. {
  12156. isSuccess = ConfigurationStatus_Rejected;
  12157. }
  12158. }
  12159. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12160. {
  12161. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12162. {
  12163. check_ascii = value[0];
  12164. if( (check_ascii < 48) || (check_ascii > 57) )
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. else
  12169. {
  12170. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12171. isSuccess = ConfigurationStatus_Accepted;
  12172. }
  12173. }
  12174. else
  12175. {
  12176. isSuccess = ConfigurationStatus_Rejected;
  12177. }
  12178. }
  12179. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12180. {
  12181. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12182. {
  12183. strcpy(str, (const char*)value);
  12184. for(int i = 0; str[i]; i++)
  12185. {
  12186. str[i] = tolower(str[i]);
  12187. }
  12188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12189. isSuccess = ConfigurationStatus_Accepted;
  12190. }
  12191. else
  12192. {
  12193. isSuccess = ConfigurationStatus_Rejected;
  12194. }
  12195. }
  12196. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12197. {
  12198. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12199. {
  12200. check_ascii = value[0];
  12201. if( (check_ascii < 48) || (check_ascii > 57) )
  12202. {
  12203. isSuccess = ConfigurationStatus_Rejected;
  12204. }
  12205. else
  12206. {
  12207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12208. isSuccess = ConfigurationStatus_Accepted;
  12209. }
  12210. }
  12211. else
  12212. {
  12213. isSuccess = ConfigurationStatus_Rejected;
  12214. }
  12215. }
  12216. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12217. {
  12218. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12219. {
  12220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12221. isSuccess = ConfigurationStatus_Accepted;
  12222. }
  12223. else
  12224. {
  12225. isSuccess = ConfigurationStatus_Rejected;
  12226. }
  12227. }
  12228. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12229. {
  12230. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12231. {
  12232. check_ascii = value[0];
  12233. if( (check_ascii < 48) || (check_ascii > 57) )
  12234. {
  12235. isSuccess = ConfigurationStatus_Rejected;
  12236. }
  12237. else
  12238. {
  12239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12240. isSuccess = ConfigurationStatus_Accepted;
  12241. }
  12242. }
  12243. else
  12244. {
  12245. isSuccess = ConfigurationStatus_Rejected;
  12246. }
  12247. }
  12248. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12249. {
  12250. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12251. {
  12252. strcpy(str, (const char*)value);
  12253. for(int i = 0; str[i]; i++)
  12254. {
  12255. str[i] = tolower(str[i]);
  12256. }
  12257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. else
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. }
  12265. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12266. {
  12267. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12268. {
  12269. check_ascii = value[0];
  12270. if( (check_ascii < 48) || (check_ascii > 57) )
  12271. {
  12272. isSuccess = ConfigurationStatus_Rejected;
  12273. }
  12274. else
  12275. {
  12276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12277. isSuccess = ConfigurationStatus_Accepted;
  12278. }
  12279. }
  12280. else
  12281. {
  12282. isSuccess = ConfigurationStatus_Rejected;
  12283. }
  12284. }
  12285. return isSuccess;
  12286. }
  12287. int TransactionMessageAttemptsGet(void)
  12288. {
  12289. return TransactionMessageAttemptsValue;
  12290. }
  12291. int FirstHeartBeatResponse(void)
  12292. {
  12293. return FirstHeartBeat;
  12294. }
  12295. int TransactionMessageRetryIntervalGet(void)
  12296. {
  12297. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12298. }
  12299. int ReadHttpStatus(int sock)
  12300. {
  12301. //char c;
  12302. char buff[1024]="",*ptr=buff+1;
  12303. int bytes_received, status;
  12304. DEBUG_INFO("Begin Response ..\n");
  12305. while((bytes_received = recv(sock, ptr, 1, 0))){
  12306. if(bytes_received==-1){
  12307. perror("ReadHttpStatus");
  12308. exit(1);
  12309. }
  12310. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12311. ptr++;
  12312. }
  12313. *ptr=0;
  12314. ptr=buff+1;
  12315. sscanf(ptr,"%*s %d ", &status);
  12316. DEBUG_INFO("%s\n",ptr);
  12317. DEBUG_INFO("status=%d\n",status);
  12318. DEBUG_INFO("End Response ..\n");
  12319. return (bytes_received>0)?status:0;
  12320. }
  12321. //the only filed that it parsed is 'Content-Length'
  12322. int ParseHeader(int sock)
  12323. {
  12324. //char c;
  12325. char buff[1024]="",*ptr=buff+4;
  12326. int bytes_received;
  12327. DEBUG_INFO("Begin HEADER ..\n");
  12328. while((bytes_received = recv(sock, ptr, 1, 0))){
  12329. if(bytes_received==-1){
  12330. perror("Parse Header");
  12331. exit(1);
  12332. }
  12333. if(
  12334. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12335. (ptr[-1]=='\r') && (*ptr=='\n' )
  12336. ) break;
  12337. ptr++;
  12338. }
  12339. *ptr=0;
  12340. ptr=buff+4;
  12341. //printf("%s",ptr);
  12342. if(bytes_received){
  12343. ptr=strstr(ptr,"Content-Length:");
  12344. if(ptr){
  12345. sscanf(ptr,"%*s %d",&bytes_received);
  12346. }else
  12347. bytes_received=-1; //unknown size
  12348. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12349. }
  12350. DEBUG_INFO("End HEADER ..\n");
  12351. return bytes_received ;
  12352. }
  12353. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12354. {
  12355. char rmFileCmd[100]={0};
  12356. char FilePath[100]={0};
  12357. char ftpbuf[200];
  12358. int systemresult;
  12359. //DEBUG_INFO("filename=%s\n",filename);
  12360. //DEBUG_INFO("url=%s\n",url);
  12361. sprintf(FilePath,"/mnt/%s",filename);
  12362. if((access(FilePath,F_OK))!=-1)
  12363. {
  12364. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12365. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12366. system(rmFileCmd);
  12367. }
  12368. memset(ftpbuf, 0, sizeof(ftpbuf));
  12369. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12370. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12371. systemresult = system(ftpbuf);
  12372. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12373. if(systemresult != 0)
  12374. {
  12375. DEBUG_INFO("http DownLoad error!\n");
  12376. return FALSE;
  12377. }
  12378. return TRUE;
  12379. }
  12380. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12381. {
  12382. char rmFileCmd[100]={0};
  12383. char FilePath[100]={0};
  12384. char ftpbuf[200];
  12385. int systemresult;
  12386. //char temp[100];
  12387. sprintf(FilePath,"/mnt/%s",filename);
  12388. if((access(FilePath,F_OK))!=-1)
  12389. {
  12390. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12391. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12392. system(rmFileCmd);
  12393. }
  12394. memset(ftpbuf, 0, sizeof(ftpbuf));
  12395. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12396. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12397. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12398. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12399. systemresult = system(ftpbuf);
  12400. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12401. if(systemresult != 0)
  12402. {
  12403. printf("wget error!\n");
  12404. return FALSE;
  12405. }
  12406. return TRUE;
  12407. }
  12408. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12409. {
  12410. char rmFileCmd[100]={0};
  12411. char FilePath[100]={0};
  12412. char ftpbuf[200];
  12413. int systemresult;
  12414. //DEBUG_INFO("filename=%s\n",filename);
  12415. //DEBUG_INFO("url=%s\n",url);
  12416. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12417. if((access(FilePath,F_OK))!=-1)
  12418. {
  12419. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12420. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12421. system(rmFileCmd);
  12422. }
  12423. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12424. if(fp == NULL)
  12425. {
  12426. DEBUG_INFO("log is NULL\n");
  12427. return FALSE;
  12428. }
  12429. else
  12430. {
  12431. fprintf(fp, "%s\n", url);
  12432. fprintf(fp, "%s\n", filename);
  12433. fclose(fp);
  12434. }
  12435. memset(ftpbuf, 0, sizeof(ftpbuf));
  12436. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12437. systemresult = system(ftpbuf);
  12438. DEBUG_INFO("systemresult = %d\n",systemresult);
  12439. if(systemresult != 0)
  12440. {
  12441. DEBUG_INFO("http upload error!\n");
  12442. return FALSE;
  12443. }
  12444. return TRUE;
  12445. }
  12446. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12447. {
  12448. struct hostent* server;
  12449. char *IPbuffer;
  12450. char ftpbuf[200];
  12451. int systemresult;
  12452. // To retrieve host information
  12453. server = gethostbyname(location);
  12454. // To convert an Internet network
  12455. // address into ASCII string
  12456. IPbuffer = inet_ntoa(*((struct in_addr*)
  12457. server->h_addr_list[0]));
  12458. memset(ftpbuf, 0, sizeof(ftpbuf));
  12459. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12460. /* format : ftpput -u username -p passwd IP target source*/
  12461. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12462. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12463. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12464. systemresult = system(ftpbuf);
  12465. DEBUG_INFO("systemresult=%d\n",systemresult);
  12466. if(systemresult != 0)
  12467. {
  12468. DEBUG_INFO("ftpput error!\n");
  12469. return FALSE;
  12470. }
  12471. return TRUE;
  12472. }
  12473. /**
  12474. * Place the contents of the specified file into a memory buffer
  12475. *
  12476. * @param[in] filename The path and name of the file to read
  12477. * @param[out] filebuffer A pointer to the contents in memory
  12478. * @return status 0 success, 1 on failure
  12479. */
  12480. int get_file_contents(const char* filename, char** outbuffer) {
  12481. FILE* file = NULL;
  12482. long filesize;
  12483. const int blocksize = 1;
  12484. size_t readsize;
  12485. char* filebuffer;
  12486. // Open the file
  12487. file = fopen(filename, "r");
  12488. if (NULL == file)
  12489. {
  12490. printf("'%s' not opened\n", filename);
  12491. exit(EXIT_FAILURE);
  12492. }
  12493. // Determine the file size
  12494. fseek(file, 0, SEEK_END);
  12495. filesize = ftell(file);
  12496. rewind (file);
  12497. // Allocate memory for the file contents
  12498. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12499. *outbuffer = filebuffer;
  12500. if (filebuffer == NULL)
  12501. {
  12502. fputs ("malloc out-of-memory", stderr);
  12503. exit(EXIT_FAILURE);
  12504. }
  12505. // Read in the file
  12506. readsize = fread(filebuffer, blocksize, filesize, file);
  12507. if (readsize != filesize)
  12508. {
  12509. fputs ("didn't read file completely",stderr);
  12510. exit(EXIT_FAILURE);
  12511. }
  12512. // Clean exit
  12513. fclose(file);
  12514. return EXIT_SUCCESS;
  12515. }
  12516. static int selectSqlCount = 0;
  12517. static int callback(void *data, int argc, char **argv, char **azColName){
  12518. int i;
  12519. //printf("%s: ", (const char*)data);
  12520. selectSqlCount = argc;
  12521. for(i = 0; i<argc; i++){
  12522. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12523. }
  12524. //printf("\n");
  12525. return 0;
  12526. }
  12527. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12528. //int i;
  12529. //printf("%s:\n", (const char*)data);
  12530. localversion = argv[5] ? atoi(argv[5]) : 0;
  12531. //printf("localversion=%d\n", localversion);
  12532. return 0;
  12533. }
  12534. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12535. //int i;
  12536. //printf("%s:\n", (const char*)data);
  12537. //idTag
  12538. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12539. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12540. //parentIdTag
  12541. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12542. //expir_date
  12543. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12544. //status
  12545. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12546. //version
  12547. idTagQuery.listVersionInt = atoi(argv[5]);
  12548. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12549. return 0;
  12550. }
  12551. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12552. {
  12553. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12554. // printf("localversion=%d\n", localversion);
  12555. return 0;
  12556. }
  12557. //=========================================
  12558. // Sqlite3 related function
  12559. //=========================================
  12560. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12561. {
  12562. for (int i = 0; i < n_columns; i++)
  12563. {
  12564. DEBUG_INFO("%s/t", col_values[i]);
  12565. }
  12566. DEBUG_INFO("/n");
  12567. return 0;
  12568. }
  12569. void OCPP_getListVerion()
  12570. {
  12571. int rc = 0;
  12572. // const char* data = "Callback function called";
  12573. char sql[100];
  12574. char zErrMsg[100];
  12575. memset(sql, 0, 100);
  12576. memset(zErrMsg, 0, 100);
  12577. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12578. /* Execute SQL statement */
  12579. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12580. if( rc != SQLITE_OK )
  12581. {
  12582. DEBUG_INFO("SQL error: %s", zErrMsg);
  12583. }
  12584. }
  12585. void OCPP_getIdTag(char idTag[])
  12586. {
  12587. int rc = 0;
  12588. // const char* data = "Callback function called";
  12589. char sql[100];
  12590. char zErrMsg[100];
  12591. memset(sql, 0, 100);
  12592. memset(zErrMsg, 0, 100);
  12593. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12594. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12595. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12596. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12597. /* Execute SQL statement */
  12598. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12599. if( rc != SQLITE_OK )
  12600. {
  12601. DEBUG_INFO("SQL error: %s", zErrMsg);
  12602. }
  12603. //return ver;
  12604. }
  12605. void OCPP_get_TableAuthlocalAllData(void)
  12606. {
  12607. int rc = 0;
  12608. char sql[100];
  12609. char zErrMsg[100];
  12610. memset(sql, 0, 100);
  12611. memset(zErrMsg, 0, 100);
  12612. sprintf(sql,"select * from ocpp_auth_local ");
  12613. /* Execute SQL statement */
  12614. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12615. if( rc != SQLITE_OK )
  12616. {
  12617. DEBUG_INFO("SQL error: %s", zErrMsg);
  12618. }
  12619. //return ver;
  12620. }
  12621. int OCPP_cleanLocalList()
  12622. {
  12623. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12624. char *errMsg = 0;
  12625. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12626. if (SQLITE_OK != rc)
  12627. {
  12628. DEBUG_INFO("%s\n",errMsg);
  12629. return FALSE;
  12630. }
  12631. return TRUE;
  12632. }
  12633. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12634. {
  12635. int isSuccess = FALSE;
  12636. int ret = 0;
  12637. //const char* data = "Callback function called";
  12638. char sql[300];
  12639. char zErrMsg[200];
  12640. memset(sql, 0, 300);
  12641. memset(zErrMsg, 0, 200);
  12642. 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);
  12643. //* Execute SQL statement */
  12644. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12645. if( ret != SQLITE_OK )
  12646. {
  12647. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12648. return isSuccess;
  12649. }
  12650. memset(sql, 0, 300);
  12651. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12652. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12653. if( ret != SQLITE_OK )
  12654. {
  12655. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12656. return isSuccess;
  12657. }
  12658. isSuccess = TRUE;
  12659. return isSuccess;
  12660. }
  12661. void OCPP_deleteIdTag(char idTag[])
  12662. {
  12663. //int ver = 0;
  12664. //int isSuccess = FALSE;
  12665. int rc = 0;
  12666. char sql[100];
  12667. char zErrMsg[100];
  12668. memset(sql, 0, 100);
  12669. memset(zErrMsg, 0, 100);
  12670. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12671. //* Execute SQL statement */
  12672. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12673. if( rc != SQLITE_OK )
  12674. {
  12675. DEBUG_INFO("SQL error: %s", zErrMsg);
  12676. }
  12677. }
  12678. int GetOcppServerURL()
  12679. {
  12680. int result = FALSE;
  12681. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12682. memset(OcppHost, 0, sizeof(OcppHost));
  12683. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12684. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12685. {
  12686. #if 1
  12687. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12688. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12689. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12690. #endif
  12691. result = TRUE;
  12692. goto End;
  12693. }
  12694. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12695. {
  12696. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12697. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12698. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12699. result = TRUE;
  12700. goto End;
  12701. }
  12702. else
  12703. {
  12704. strcpy(OcppHost,"");
  12705. }
  12706. End:
  12707. return result;
  12708. }
  12709. int GetOcppPath()
  12710. {
  12711. int result = FALSE;
  12712. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12713. {
  12714. if(OcppTempPath == NULL)
  12715. {
  12716. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12717. }
  12718. else
  12719. {
  12720. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12721. }
  12722. result = TRUE;
  12723. goto End;
  12724. }
  12725. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12726. {
  12727. if(OcppTempPath == NULL)
  12728. {
  12729. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12730. }
  12731. else
  12732. {
  12733. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12734. }
  12735. result = TRUE;
  12736. goto End;
  12737. }
  12738. else
  12739. {
  12740. strcpy(OcppPath,"");
  12741. }
  12742. End:
  12743. return result;
  12744. }
  12745. int GetOcppPort()
  12746. {
  12747. return OcppPort;
  12748. }
  12749. int GetOcppConnStatus(void)
  12750. {
  12751. return ShmOCPP16Data->OcppConnStatus;
  12752. }
  12753. void SetOcppConnStatus(uint8_t status)
  12754. {
  12755. ShmOCPP16Data->OcppConnStatus = status;
  12756. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12757. }
  12758. int GetHeartBeatWithNOResponse(void)
  12759. {
  12760. return HeartBeatWithNOResponse;
  12761. }
  12762. void SetHeartBeatWithNOResponse(void)
  12763. {
  12764. HeartBeatWithNOResponse = 0;
  12765. }
  12766. void GetStartTransactionIdTag(int gun_index)
  12767. {
  12768. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  12769. strcpy(StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12770. }
  12771. int GetTransactionId(int gunindex, char idTag[])
  12772. {
  12773. char ch;
  12774. FILE *fptr1;
  12775. int temptransactionId;
  12776. char str[100]={0};
  12777. temptransactionId = 0;
  12778. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12779. {
  12780. return temptransactionId;
  12781. }
  12782. /*------ Read the file ----------------*/
  12783. fptr1=fopen("/Storage/OCPP/QueueTransactionId", "r");
  12784. if (!fptr1)
  12785. {
  12786. return temptransactionId;
  12787. }
  12788. ch=fgetc(fptr1);
  12789. rewind(fptr1);
  12790. if(ch!=EOF)
  12791. {
  12792. while (fgets(str, 100, fptr1) != NULL)
  12793. {
  12794. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12795. if(str[0]=='\0')
  12796. {
  12797. break;
  12798. }
  12799. char *revbuf[8] = {0};
  12800. int num = 0;
  12801. splitstring(str,",",revbuf,&num);
  12802. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12803. {
  12804. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  12805. {
  12806. temptransactionId = atoi(revbuf[2]);
  12807. break;
  12808. }
  12809. }
  12810. }
  12811. }
  12812. fclose(fptr1);
  12813. /*------- End of reading ---------------*/
  12814. return temptransactionId;
  12815. }
  12816. void SetTransactionIdZero(int transactionId)
  12817. {
  12818. char ch;
  12819. FILE *fptr1, *fptr2;
  12820. int temptransactionId = 0;
  12821. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  12822. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  12823. if (!fptr1)
  12824. {
  12825. //printf(" File not found or unable to open the input file!!\n");
  12826. return ;
  12827. }
  12828. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  12829. if (!fptr2)
  12830. {
  12831. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  12832. fclose(fptr1);
  12833. return ;
  12834. }
  12835. ch=fgetc(fptr1);
  12836. rewind(fptr1);
  12837. if(ch!=EOF)
  12838. {
  12839. // copy all contents to the temporary file except the specific line
  12840. while (fgets(str, 100, fptr1) != NULL)
  12841. {
  12842. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12843. if(str[0]=='\0')
  12844. {
  12845. break;
  12846. }
  12847. char *revbuf[8] = {0};
  12848. int num = 0;
  12849. strcpy(strtemp, str);
  12850. splitstring(str,",",revbuf,&num);
  12851. if(revbuf[2][0] != '\0')
  12852. {
  12853. temptransactionId = atoi(revbuf[2]);
  12854. if(transactionId != temptransactionId)
  12855. {
  12856. fprintf(fptr2, "%s\n", strtemp);
  12857. }
  12858. }
  12859. }
  12860. }
  12861. fclose(fptr1);
  12862. fclose(fptr2);
  12863. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  12864. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  12865. /*------ Read the file ----------------*/
  12866. }
  12867. int InternetDisconnect(void)
  12868. {
  12869. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  12870. }
  12871. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  12872. void storeTempStopTransaction(int gun_index)
  12873. {
  12874. char guid[37]={0};
  12875. int tempIndex = 0;
  12876. DEBUG_INFO("storeTempStopTransaction...\n");
  12877. memset(queuedata, 0, sizeof(queuedata));
  12878. //ENERGY_ACTIVE_IMPORT_REGISTER
  12879. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  12880. if(gunType[gun_index] == 'J')
  12881. {
  12882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12883. {
  12884. tempIndex = ((gun_index==2) ? 1: 0);
  12885. }
  12886. else
  12887. {
  12888. tempIndex = gun_index;
  12889. }
  12890. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12891. {
  12892. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12893. {
  12894. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  12895. }
  12896. }// END OF CHAdeMO_QUANTITY
  12897. }
  12898. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  12899. {
  12900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12901. {
  12902. tempIndex = ((gun_index==2) ? 1: 0);
  12903. }
  12904. else
  12905. {
  12906. tempIndex = gun_index;
  12907. }
  12908. for (int index = 0; index < CCS_QUANTITY; index++)
  12909. {
  12910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12911. {
  12912. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  12913. }
  12914. }// END OF CCS_QUANTITY
  12915. }
  12916. else if(gunType[gun_index] == 'G')
  12917. {
  12918. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12919. {
  12920. tempIndex = ((gun_index==2) ? 1: 0);
  12921. }
  12922. else
  12923. {
  12924. tempIndex = gun_index;
  12925. }
  12926. for (int index = 0; index < GB_QUANTITY; index++)
  12927. {
  12928. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12929. {
  12930. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  12931. }
  12932. }// END OF GB_QUANTITY
  12933. }
  12934. else
  12935. {
  12936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  12937. {
  12938. tempIndex = 2;
  12939. }
  12940. else
  12941. {
  12942. tempIndex = gun_index;
  12943. }
  12944. for (int index = 0; index < AC_QUANTITY; index++)
  12945. {
  12946. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12947. {
  12948. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  12949. }
  12950. }// END OF AC_QUANTITY
  12951. }
  12952. //Stop Transaction Time
  12953. struct timeval tmnow;
  12954. struct tm *tm;
  12955. char buf[28];//, usec_buf[6];
  12956. gettimeofday(&tmnow, NULL);
  12957. time_t t;
  12958. t = time(NULL);
  12959. /*UTC time and date*/
  12960. tm = gmtime(&t);
  12961. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  12962. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  12963. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  12964. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12965. random_uuid(guid);
  12966. /***********************************transactionData******************************************************/
  12967. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  12968. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  12969. //=================================
  12970. //1. Transaction_Begin
  12971. //=================================
  12972. // Energy.Active.Export.Interval
  12973. //idx_sample=0;
  12974. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  12975. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  12976. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  12977. 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*/]);
  12978. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  12979. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  12980. {
  12981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  12982. }
  12983. else
  12984. {
  12985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  12986. }
  12987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  12988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  12989. //=================================
  12990. //2. Transaction_End
  12991. //=================================
  12992. //2.1 Current.Export
  12993. //idx_sample=1;
  12994. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  12995. if(gunType[gun_index] == 'J')
  12996. {
  12997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12998. {
  12999. tempIndex = ((gun_index==2) ? 1: 0);
  13000. }
  13001. else
  13002. {
  13003. tempIndex = gun_index;
  13004. }
  13005. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13006. {
  13007. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13008. {
  13009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13010. }
  13011. }// End of for CHAdeMO_QUANTITY
  13012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13013. }
  13014. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13015. {
  13016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13017. {
  13018. tempIndex = ((gun_index==2) ? 1: 0);
  13019. }
  13020. else
  13021. {
  13022. tempIndex = gun_index;
  13023. }
  13024. for (int index = 0; index < CCS_QUANTITY; index++)
  13025. {
  13026. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13027. {
  13028. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13029. }
  13030. }// End of for CCS_QUANTITY
  13031. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13032. }
  13033. else if(gunType[gun_index] == 'G')
  13034. {
  13035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13036. {
  13037. tempIndex = ((gun_index==2) ? 1: 0);
  13038. }
  13039. else
  13040. {
  13041. tempIndex = gun_index;
  13042. }
  13043. for (int index = 0; index < GB_QUANTITY; index++)
  13044. {
  13045. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13046. {
  13047. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13048. }
  13049. }// End of for GB_QUANTITY
  13050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13051. }
  13052. else
  13053. {
  13054. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13055. {
  13056. tempIndex = 2;
  13057. }
  13058. else
  13059. {
  13060. tempIndex = gun_index;
  13061. }
  13062. for (int index = 0; index < AC_QUANTITY; index++)
  13063. {
  13064. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13065. {
  13066. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13067. }
  13068. }// End of for AC_QUANTITY
  13069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13070. }
  13071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13074. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13077. //2.2 Energy.Active.Export.Interval
  13078. //idx_sample=2;
  13079. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13080. if(gunType[gun_index] == 'J')
  13081. {
  13082. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13083. {
  13084. tempIndex = ((gun_index==2) ? 1: 0);
  13085. }
  13086. else
  13087. {
  13088. tempIndex = gun_index;
  13089. }
  13090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13091. {
  13092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13093. {
  13094. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13095. }
  13096. }// END OF CHAdeMO_QUANTITY
  13097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13098. }
  13099. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13100. {
  13101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13102. {
  13103. tempIndex = ((gun_index==2) ? 1: 0);
  13104. }
  13105. else
  13106. {
  13107. tempIndex = gun_index;
  13108. }
  13109. for (int index = 0; index < CCS_QUANTITY; index++)
  13110. {
  13111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13112. {
  13113. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13114. }
  13115. }// END OF CCS_QUANTITY
  13116. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13117. }
  13118. else if(gunType[gun_index] == 'G')
  13119. {
  13120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13121. {
  13122. tempIndex = ((gun_index==2) ? 1: 0);
  13123. }
  13124. else
  13125. {
  13126. tempIndex = gun_index;
  13127. }
  13128. for (int index = 0; index < GB_QUANTITY; index++)
  13129. {
  13130. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13131. {
  13132. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13133. }
  13134. }// END OF GB_QUANTITY
  13135. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13136. }
  13137. else
  13138. {
  13139. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13140. {
  13141. tempIndex = 2;
  13142. }
  13143. else
  13144. {
  13145. tempIndex = gun_index;
  13146. }
  13147. for (int index = 0; index < AC_QUANTITY; index++)
  13148. {
  13149. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13150. {
  13151. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13152. }
  13153. }// END OF AC_QUANTITY
  13154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13155. }
  13156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13159. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13160. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13161. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13162. //2.3 Power.Active.Export
  13163. //idx_sample=3;
  13164. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13165. if(gunType[gun_index] == 'J')
  13166. {
  13167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13168. {
  13169. tempIndex = ((gun_index==2) ? 1: 0);
  13170. }
  13171. else
  13172. {
  13173. tempIndex = gun_index;
  13174. }
  13175. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13176. {
  13177. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13178. {
  13179. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13180. }
  13181. } // End for CHAdeMO_QUANTITY
  13182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  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. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13199. }
  13200. } // END for CCS_QUANTITY
  13201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13202. }
  13203. else if(gunType[gun_index] == 'G')
  13204. {
  13205. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13206. {
  13207. tempIndex = ((gun_index==2) ? 1: 0);
  13208. }
  13209. else
  13210. {
  13211. tempIndex = gun_index;
  13212. }
  13213. for (int index = 0; index < GB_QUANTITY; index++)
  13214. {
  13215. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13216. {
  13217. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13218. }
  13219. }// END for GB_QUANTITY
  13220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13221. }
  13222. else
  13223. {
  13224. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13225. {
  13226. tempIndex = 2;
  13227. }
  13228. else
  13229. {
  13230. tempIndex = gun_index;
  13231. }
  13232. for (int index = 0; index < AC_QUANTITY; index++)
  13233. {
  13234. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13235. {
  13236. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13237. }
  13238. } // END for AC_QUANTITY
  13239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13240. }
  13241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13242. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13243. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13244. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13246. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13247. //2.4 Voltage
  13248. //idx_sample=4;
  13249. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13250. if(gunType[gun_index] == 'J')
  13251. {
  13252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13253. {
  13254. tempIndex = ((gun_index==2) ? 1: 0);
  13255. }
  13256. else
  13257. {
  13258. tempIndex = gun_index;
  13259. }
  13260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13261. {
  13262. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13263. {
  13264. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13265. }
  13266. } // END OF FOR CHAdeMO_QUANTITY
  13267. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13268. }
  13269. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13270. {
  13271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13272. {
  13273. tempIndex = ((gun_index==2) ? 1: 0);
  13274. }
  13275. else
  13276. {
  13277. tempIndex = gun_index;
  13278. }
  13279. for (int index = 0; index < CCS_QUANTITY; index++)
  13280. {
  13281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13282. {
  13283. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13284. }
  13285. } // END OF FOR CCS_QUANTITY
  13286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13287. }
  13288. else if(gunType[gun_index] == 'G')
  13289. {
  13290. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13291. {
  13292. tempIndex = ((gun_index==2) ? 1: 0);
  13293. }
  13294. else
  13295. {
  13296. tempIndex = gun_index;
  13297. }
  13298. for (int index = 0; index < GB_QUANTITY; index++)
  13299. {
  13300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13301. {
  13302. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13303. }
  13304. } // END OF FOR GB_QUANTITY
  13305. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13306. }
  13307. else
  13308. {
  13309. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13310. {
  13311. tempIndex = 2;
  13312. }
  13313. else
  13314. {
  13315. tempIndex = gun_index;
  13316. }
  13317. for (int index = 0; index < AC_QUANTITY; index++)
  13318. {
  13319. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13320. {
  13321. 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
  13322. }
  13323. } // END OF FOR AC_QUANTITY
  13324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13325. }
  13326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13329. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13331. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13332. //2.5 SoC
  13333. //idx_sample=5;
  13334. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13335. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13336. {
  13337. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13338. {
  13339. tempIndex = ((gun_index==2) ? 1: 0);
  13340. }
  13341. else
  13342. {
  13343. tempIndex = gun_index;
  13344. }
  13345. if(gunType[gun_index] == 'J')
  13346. {
  13347. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13348. {
  13349. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13350. {
  13351. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13352. }
  13353. }
  13354. }
  13355. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13356. {
  13357. for (int index = 0; index < CCS_QUANTITY; index++)
  13358. {
  13359. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13360. {
  13361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13362. }
  13363. }
  13364. }
  13365. else if(gunType[gun_index] == 'G')
  13366. {
  13367. for (int index = 0; index < GB_QUANTITY; index++)
  13368. {
  13369. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13370. {
  13371. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13372. }
  13373. }
  13374. }
  13375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13376. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13377. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13378. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13380. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13381. } // END FOR DC CASE
  13382. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13383. {
  13384. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13385. ,MESSAGE_TYPE_CALL
  13386. ,guid
  13387. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13388. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13389. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13390. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13391. ,"PowerLoss"
  13392. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13393. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13394. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13395. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13396. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13397. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13398. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13399. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13400. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13401. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13402. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13403. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13404. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13405. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13406. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13407. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13408. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13409. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13410. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13411. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13412. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13413. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13414. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13415. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13416. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13417. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13418. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13419. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13420. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13421. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13422. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13423. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13424. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13425. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13426. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13427. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13428. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13429. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13430. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13431. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13432. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13433. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13434. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13435. );
  13436. }
  13437. else
  13438. {
  13439. sprintf(queuedata,"[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13440. ,MESSAGE_TYPE_CALL
  13441. ,guid
  13442. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13443. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13444. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13445. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13446. ,"PowerLoss"
  13447. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13448. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13449. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13450. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13451. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13452. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13453. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13454. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13455. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13456. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13457. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13458. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13459. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13460. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13461. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13462. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13463. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13464. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13465. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13466. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13467. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13468. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13469. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13470. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13471. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13472. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13473. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13474. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13475. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13476. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13477. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13478. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13479. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13480. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13481. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13482. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13483. );
  13484. }
  13485. // Check File "TempStopTransaction" Exist
  13486. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13487. {
  13488. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13489. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13490. }
  13491. else
  13492. {
  13493. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13494. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13495. if(log == NULL)
  13496. {
  13497. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13498. return ;
  13499. }
  13500. else
  13501. {
  13502. fclose(log);
  13503. }
  13504. }
  13505. //Add TempStopTransaction | Update TempStopTransaction
  13506. // open file for writing
  13507. FILE *outfile;
  13508. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13509. //DEBUG_INFO("data = %s\n", queuedata);
  13510. fputs(queuedata, outfile);
  13511. fputs("\n", outfile);
  13512. fclose (outfile);
  13513. }
  13514. void checkTempStopTransaction(int gun_index)
  13515. {
  13516. FILE *fptr1;
  13517. char ch;
  13518. char str[1200]={0};
  13519. char guid[37]={0};
  13520. char tempdata[65]={0};
  13521. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13522. if (!fptr1)
  13523. {
  13524. //printf(" File not found or unable to open the input file!!\n");
  13525. return ;
  13526. }
  13527. ch=fgetc(fptr1);
  13528. //printf(" Now the content of the file %s is : \n",fname);
  13529. rewind(fptr1);
  13530. if(ch!=EOF)
  13531. {
  13532. // copy all contents to the temporary file except the specific line
  13533. while (fgets(str, 1200, fptr1) != NULL)
  13534. {
  13535. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13536. if(str[0]=='\0')
  13537. {
  13538. break;
  13539. }
  13540. //random_uuid(guid);
  13541. strncpy(guid, str+4, 36); //skip 4 bytes( [2," ),copy guid
  13542. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13543. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13544. {
  13545. DEBUG_INFO("StopTransaction mapitem pass\n");
  13546. }
  13547. queue_operation(QUEUE_OPERATION_ADD, guid, str );//addq(guid, queuedata); ---> remove temporally
  13548. memset(str,0,sizeof str);
  13549. }
  13550. }
  13551. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13552. fclose(fptr1);
  13553. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13554. }
  13555. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13556. {
  13557. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13558. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13559. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13560. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13561. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13562. }
  13563. int GetWebSocketPingInterval(void)
  13564. {
  13565. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13566. }
  13567. int GetServerSign(void)
  13568. {
  13569. return server_sign;
  13570. }
  13571. void SetServerSign(int value)
  13572. {
  13573. server_sign = value;
  13574. }
  13575. int GetBootNotificationInterval(void)
  13576. {
  13577. return BootNotificationInterval;
  13578. }
  13579. int GetInternetConn(void)
  13580. {
  13581. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13582. }
  13583. void InitialSystemValue(void)
  13584. {
  13585. int connectorIndex = 0;
  13586. //int valueASCII = 0;
  13587. server_cycle_Status = 120;
  13588. gunTotalNumber=0;
  13589. SystemInitial = 0;
  13590. localversion=0;
  13591. BootNotificationInterval = 0;
  13592. authorizeRetryTimes = 0;
  13593. GunStatusInterval = 10;
  13594. TransactionMessageAttemptsValue = 0;
  13595. TransactionMessageRetryIntervalValue = 0;
  13596. //Hear Beat
  13597. HeartBeatWithNOResponse = 0;
  13598. HeartBeatCountPerHour = 0;
  13599. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  13600. FirstHeartBeat = 0;
  13601. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  13602. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  13603. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  13604. memset(statusModeChage, 0, sizeof(statusModeChage));
  13605. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13606. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13607. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13608. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13609. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13610. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13611. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13612. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13613. memset(gunType, 0, sizeof(gunType));
  13614. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13615. {
  13616. //check connector / socket type (index: 8, 9, 10)
  13617. for(int index=7; index <10 ; index++)
  13618. {
  13619. if(index != 8)
  13620. {
  13621. // DC Connector
  13622. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13623. {
  13624. SystemInitial = SystemInitial + 1;
  13625. gunTotalNumber = gunTotalNumber + 1;
  13626. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13627. connectorIndex = connectorIndex + 1;
  13628. }
  13629. }
  13630. else
  13631. {
  13632. // AC Connector
  13633. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13634. {
  13635. SystemInitial = SystemInitial + 1;
  13636. gunTotalNumber = gunTotalNumber + 1;
  13637. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13638. connectorIndex = connectorIndex + 1;
  13639. }
  13640. }
  13641. }
  13642. //DEBUG_INFO("DC ...\n");
  13643. }
  13644. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13645. {
  13646. //check connector / socket type (index: 8, 9, 10)
  13647. for(int index=7; index <10 ; index++)
  13648. {
  13649. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13650. {
  13651. SystemInitial = SystemInitial + 1;
  13652. gunTotalNumber = gunTotalNumber + 1;
  13653. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13654. connectorIndex = connectorIndex + 1;
  13655. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13656. }
  13657. }
  13658. }
  13659. //Status && ConnectorPlugIn Setting
  13660. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13661. {
  13662. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13663. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13664. }
  13665. for (int index = 0; index < CCS_QUANTITY; index++)
  13666. {
  13667. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13668. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13669. }
  13670. for (int index = 0; index < GB_QUANTITY; index++)
  13671. {
  13672. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13673. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13674. }
  13675. for (int index = 0; index < AC_QUANTITY; index++)
  13676. {
  13677. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13678. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13679. }
  13680. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13681. {
  13682. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13683. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13684. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13685. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13686. }
  13687. // Charger PRE_SYS_MODE
  13688. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13689. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13690. clientTime.Heartbeat=time((time_t*)NULL);
  13691. sleep(1);
  13692. }
  13693. void LWS_Send(char * str)
  13694. {
  13695. //=====================================================
  13696. // Check InternetConn 0: disconnected, 1: connected
  13697. //====================================================
  13698. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13699. {
  13700. DEBUG_INFO("\n offline now !!!\n");
  13701. return;
  13702. }
  13703. pthread_mutex_lock(&lock);
  13704. memset(SendBuffer, 0, SendBufLen);
  13705. sprintf((char *)SendBuffer, "%s", str);
  13706. pthread_mutex_unlock(&lock);
  13707. lws_callback_on_writable(wsi_client);
  13708. lws_service(context, 100);//timeout_ms
  13709. }