MessageHandler.c 623 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. //===================================
  18. // Define CP State constant
  19. //===================================
  20. #define CP_STATE_UNKNOWN 0
  21. #define CP_STATE_A 1
  22. #define CP_STATE_B 2
  23. #define CP_STATE_C 3
  24. #define CP_STATE_D 4
  25. #define CP_STATE_E 5
  26. #define CP_STATE_F 6
  27. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  28. struct StatusCodeData *ShmStatusCodeData;
  29. struct PsuData *ShmPsuData ;
  30. struct OCPP16Data *ShmOCPP16Data;
  31. #define MACROSTR(k) #k
  32. //ConfigurationMaxKeys
  33. #define GetConfigurationMaxKeysNUM 43
  34. pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
  35. char queuedata[2600] = {0};
  36. //=================================
  37. // StatusNotification cycle
  38. //=================================
  39. static int server_cycle_Status = 120;
  40. //===============================
  41. // Configuration: unknownkey
  42. //===============================
  43. static char unknownkey[10][20] = {0};
  44. static int UnknownKeynum = 0;
  45. //===============================
  46. // Gun Total Numbers
  47. //===============================
  48. static int gunTotalNumber = 0;
  49. static unsigned char gunType[4] = {0};
  50. //===============================
  51. // Local List Version
  52. //===============================
  53. static int localversion=0;
  54. static char idTagAuthorization[32] = {0};
  55. //===============================
  56. // OCPP sign variable
  57. //===============================
  58. static int server_sign = FALSE;
  59. int server_pending = FALSE;
  60. int PRE_SYS_MODE[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  61. static int BootNotificationInterval = 0;
  62. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  63. //===============================
  64. // OCPP auth variable
  65. //===============================
  66. static int authorizeRetryTimes = 0; //number of Retry times
  67. //===============================
  68. // OCPP other variables
  69. //===============================
  70. //int isUpdateRequest = FALSE;
  71. static int HeartBeatWaitTime = 10;
  72. static int FirstHeartBeat = 0;
  73. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  74. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  75. static char CurrentChargingProfileScheduleStr[30] = {0};
  76. //========================================
  77. // OCPP status/previous related variables
  78. //========================================
  79. static int GunStatusInterval = 10;
  80. static int statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  81. static int ChademoPreviousSystemStatus[CHAdeMO_QUANTITY];
  82. static int CcsPreviousSystemStatus[CCS_QUANTITY];
  83. static int GbPreviousSystemStatus[GB_QUANTITY];
  84. static int AcPreviousSystemStatus[AC_QUANTITY];
  85. static int ChademoPreviousConnectorPlugIn[CHAdeMO_QUANTITY];
  86. static int CcsPreviousConnectorPlugIn[CCS_QUANTITY];
  87. static int GbPreviousConnectorPlugIn[GB_QUANTITY];
  88. static int AcPreviousConnectorPlugIn[AC_QUANTITY];
  89. static int TransactionMessageAttemptsValue = 0;
  90. static int TransactionMessageRetryIntervalValue = 0;
  91. static int TempMeterValueInterval = 0;
  92. static struct OCPPAuthLocalElemet
  93. {
  94. int listVersionInt;
  95. char idTagstr[20];
  96. char parentIdTag[20];
  97. char expiryDate[30];
  98. char idTagstatus[16];
  99. }idTagQuery;
  100. //=============================================
  101. // OCPP HeartBeat Response Not Receive Counts
  102. //============================================
  103. static int HeartBeatWithNOResponse = 0;
  104. static int HeartBeatCountPerHour = 0;
  105. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  106. extern int GetTransactionQueueNum(void);
  107. extern pthread_mutex_t mutex1;
  108. extern struct Charger_Info Charger;
  109. extern sqlite3 *db;
  110. int TransactionMessageAttemptsGet(void);
  111. int TransactionMessageRetryIntervalGet(void);
  112. int GetOcppConnStatus(void);
  113. void SetOcppConnStatus(uint8_t status);
  114. int setKeyValue(char *key, char *value);
  115. void OCPP_get_TableAuthlocalAllData(void);
  116. void processUnkownKey(void);
  117. struct StructOCPPMeterValue
  118. {
  119. unsigned char TimeStamp[28];
  120. struct StructSampledValue SampledValue[10];
  121. };
  122. struct ClientTime
  123. {
  124. unsigned int Heartbeat;
  125. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  126. unsigned int StartTransaction;
  127. unsigned int StopTransaction;
  128. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  129. }clientTime;
  130. typedef union
  131. {
  132. //Operations Initiated by Central System
  133. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  134. struct
  135. {
  136. //CsMsgValue[0]
  137. unsigned char StatusNotificationReq :1; //bit 0,
  138. unsigned char StatusNotificationConf :1; //bit 0,
  139. unsigned char :6; //bit 2~7
  140. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  141. }CpinitiateMsg;
  142. CpinitiateMsg cpinitateMsg;
  143. //==========================================
  144. // Init all Enumeration & Mapping String
  145. //==========================================
  146. /*ChargePointErrorCode*/
  147. typedef enum {
  148. ConnectorLockFailure,
  149. EVCommunicationError,
  150. GroundFailure,
  151. HighTemperature,
  152. InternalError,
  153. LocalListConflict,
  154. NoError,
  155. OtherError,
  156. OverCurrentFailure,
  157. OverVoltage,
  158. PowerMeterFailure,
  159. PowerSwitchFailure,
  160. ReaderFailure,
  161. ResetFailure,
  162. UnderVoltage,
  163. WeakSignal
  164. } ChargePointErrorCode;
  165. #if 0
  166. static char *ChargePointErrorCodeStr[] = {
  167. MACROSTR(ConnectorLockFailure),
  168. MACROSTR(EVCommunicationError),
  169. MACROSTR(GroundFailure),
  170. MACROSTR(HighTemperature),
  171. MACROSTR(InternalError),
  172. MACROSTR(LocalListConflict),
  173. MACROSTR(NoError),
  174. MACROSTR(OtherError),
  175. MACROSTR(OverCurrentFailure),
  176. MACROSTR(OverVoltage),
  177. MACROSTR(PowerMeterFailure),
  178. MACROSTR(PowerSwitchFailure),
  179. MACROSTR(ReaderFailure),
  180. MACROSTR(ResetFailure),
  181. MACROSTR(UnderVoltage),
  182. MACROSTR(WeakSignal)
  183. };
  184. #endif
  185. /*ChargePointStatus*/
  186. typedef enum {
  187. Available =0,
  188. Preparing,
  189. Charging,
  190. SuspendedEVSE,
  191. SuspendedEV,
  192. Finishing,
  193. Reserved,
  194. Unavailable,
  195. Faulted
  196. } ChargePointStatus;
  197. static char * ChargePointStatusStr[] = {
  198. MACROSTR(Available),
  199. MACROSTR(Preparing),
  200. MACROSTR(Charging),
  201. MACROSTR(SuspendedEVSE),
  202. MACROSTR(SuspendedEV),
  203. MACROSTR(Finishing),
  204. MACROSTR(Reserved),
  205. MACROSTR(Unavailable),
  206. MACROSTR(Faulted)
  207. };
  208. /*AvailabilityType*/
  209. typedef enum {
  210. RegistrationStatus_Accepted,
  211. RegistrationStatus_Pending,
  212. RegistrationStatus_Rejected
  213. } RegistrationStatus;
  214. static char *RegistrationStatusStr[] = {
  215. MACROSTR(Accepted),
  216. MACROSTR(Pending),
  217. MACROSTR(Rejected)
  218. };
  219. /*AvailabilityType*/
  220. typedef enum {
  221. Inoperative,
  222. Operative
  223. } AvailabilityType;
  224. static char *AvailabilityTypeStr[] = {
  225. MACROSTR(Inoperative),
  226. MACROSTR(Operative)
  227. };
  228. /*AvailabilityStatus*/
  229. typedef enum {
  230. Accepted,
  231. Rejected,
  232. Scheduled
  233. } AvailabilityStatus;
  234. static char *AvailabilityStatusStr[] = {
  235. MACROSTR(Accepted),
  236. MACROSTR(Rejected),
  237. MACROSTR(Scheduled)
  238. };
  239. /*ConfigurationStatus*/
  240. typedef enum {
  241. ConfigurationStatus_Accepted,
  242. ConfigurationStatus_Rejected,
  243. RebootRequired,
  244. NotSupported
  245. } ConfigurationStatus;
  246. static char *ConfigurationStatusStr[] = {
  247. MACROSTR(Accepted),
  248. MACROSTR(Rejected),
  249. MACROSTR(RebootRequired),
  250. MACROSTR(NotSupported)
  251. };
  252. /*ClearCacheStatus*/
  253. typedef enum {
  254. ClearCacheStatus_Accepted,
  255. ClearCacheStatus_Rejected
  256. } ClearCacheStatus;
  257. static char *ClearCacheStatusStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(Rejected)
  260. };
  261. /*ChargingProfilePurposeType*/
  262. typedef enum {
  263. ChargePointMaxProfile,
  264. TxDefaultProfile,
  265. TxProfile
  266. } ChargingProfilePurposeType;
  267. static char *ChargingProfilePurposeTypeStr[] = {
  268. MACROSTR(ChargePointMaxProfile),
  269. MACROSTR(TxDefaultProfile),
  270. MACROSTR(TxProfile)
  271. };
  272. /*ChargingProfileStatus*/
  273. typedef enum {
  274. ChargingProfileStatus_Accepted,
  275. ChargingProfileStatus_Rejected,
  276. ChargingProfileStatus_NotSupported
  277. } ChargingProfileStatus;
  278. static char *ChargingProfileStatusStr[] = {
  279. MACROSTR(Accepted),
  280. MACROSTR(Rejected),
  281. MACROSTR(NotSupported)
  282. };
  283. /*ClearChargingProfileStatus*/
  284. typedef enum {
  285. ClearChargingProfileStatus_Accepted,
  286. ClearChargingProfileStatus_Unknown
  287. } ClearChargingProfileStatus;
  288. static char *ClearChargingProfileStatusStr[] = {
  289. MACROSTR(Accepted),
  290. MACROSTR(Unknown)
  291. };
  292. /*GetCompositeScheduleStatus*/
  293. typedef enum {
  294. GetCompositeScheduleStatus_Accepted,
  295. GetCompositeScheduleStatus_Rejected
  296. } GetCompositeScheduleStatus;
  297. static char *GetCompositeScheduleStatusStr[] = {
  298. MACROSTR(Accepted),
  299. MACROSTR(Rejected)
  300. };
  301. /*ChargingRateUnitType*/
  302. typedef enum {
  303. ChargingRateUnitType_W,
  304. ChargingRateUnitType_A
  305. } ChargingRateUnitType;
  306. /*AuthorizationStatus*/
  307. typedef enum {
  308. AuthorizationStatus_Accepted ,
  309. AuthorizationStatus_Blocked ,
  310. AuthorizationStatus_Expired ,
  311. AuthorizationStatus_Invalid ,
  312. AuthorizationStatus_ConcurrentTx
  313. } AuthorizationStatus;
  314. /*UpdateType*/
  315. typedef enum {
  316. Differential ,
  317. Full
  318. } UpdateType;
  319. static char *UpdateTypeStr[] = {
  320. MACROSTR(Differential),
  321. MACROSTR(Full)
  322. };
  323. /*UpdateStatus*/
  324. typedef enum {
  325. UpdateStatus_Accepted ,
  326. UpdateStatus_Failed ,
  327. UpdateStatus_NotSupported ,
  328. UpdateStatus_VersionMismatch
  329. } UpdateStatus;
  330. static char *UpdateStatusStr[] = {
  331. MACROSTR(Accepted),
  332. MACROSTR(Failed),
  333. MACROSTR(NotSupported),
  334. MACROSTR(VersionMismatch)
  335. };
  336. /*RemoteStartStopStatus*/
  337. typedef enum {
  338. RemoteStartStopStatus_Accepted,
  339. RemoteStartStopStatus_Rejected
  340. } RemoteStartStopStatus;
  341. static char *RemoteStartStopStatusStr[] = {
  342. MACROSTR(Accepted),
  343. MACROSTR(Rejected)
  344. };
  345. /*ReservationStatus*/
  346. typedef enum {
  347. ReservationStatus_Accepted,
  348. ReservationStatus_Faulted,
  349. ReservationStatus_Occupied,
  350. ReservationStatus_Rejected,
  351. ReservationStatus_Unavailable
  352. } ReservationStatus;
  353. static char *ReservationStatusStr[] = {
  354. MACROSTR(Accepted),
  355. MACROSTR(Faulted),
  356. MACROSTR(Occupied),
  357. MACROSTR(Rejected),
  358. MACROSTR(Unavailable)
  359. };
  360. /*ResetType*/
  361. typedef enum {
  362. Hard,
  363. Soft
  364. } ResetType;
  365. static char *ResetTypeStr[] = {
  366. MACROSTR(Hard),
  367. MACROSTR(Soft)
  368. };
  369. /*ResetStatus*/
  370. typedef enum {
  371. ResetStatus_Accepted,
  372. ResetStatus_Rejected
  373. } ResetStatus;
  374. static char *ResetStatusStr[] = {
  375. MACROSTR(Accepted),
  376. MACROSTR(Rejected)
  377. };
  378. /*DiagnosticsStatus*/
  379. typedef enum {
  380. DiagnosticsStatus_Idle,
  381. DiagnosticsStatus_Uploaded,
  382. DiagnosticsStatus_UploadFailed,
  383. DiagnosticsStatus_Uploading
  384. } DiagnosticsStatus;
  385. static char * DiagnosticsStatusStr[] = {
  386. MACROSTR(Idle),
  387. MACROSTR(Uploaded),
  388. MACROSTR(UploadFailed),
  389. MACROSTR(Uploading)
  390. };
  391. /*FirmwareStatus*/
  392. typedef enum {
  393. FirmwareStatus_Downloaded,
  394. FirmwareStatus_DownloadFailed,
  395. FirmwareStatus_Downloading,
  396. FirmwareStatus_Idle,
  397. FirmwareStatus_InstallationFailed,
  398. FirmwareStatus_Installing,
  399. FirmwareStatus_Installed
  400. } FirmwareStatus;
  401. static char * FirmwareStatusStr[] = {
  402. MACROSTR(Downloaded),
  403. MACROSTR(DownloadFailed),
  404. MACROSTR(Downloading),
  405. MACROSTR(Idle),
  406. MACROSTR(InstallationFailed),
  407. MACROSTR(Installing),
  408. MACROSTR(Installed)
  409. };
  410. /*MessageTrigger*/
  411. typedef enum {
  412. BootNotification,
  413. DiagnosticsStatusNotification,
  414. FirmwareStatusNotification,
  415. Heartbeat,
  416. MeterValues,
  417. StatusNotification
  418. } MessageTrigger;
  419. static char * MessageTriggerStr[] = {
  420. MACROSTR(BootNotification),
  421. MACROSTR(DiagnosticsStatusNotification),
  422. MACROSTR(FirmwareStatusNotification),
  423. MACROSTR(Heartbeat),
  424. MACROSTR(MeterValues),
  425. MACROSTR(StatusNotification)
  426. };
  427. /*TriggerMessageStatus*/
  428. typedef enum {
  429. TriggerMessageStatus_Accepted ,
  430. TriggerMessageStatus_Rejected ,
  431. TriggerMessageStatus_NotImplemented
  432. } TriggerMessageStatus;
  433. static char * TriggerMessageStatusStr[] = {
  434. MACROSTR(Accepted),
  435. MACROSTR(Rejected),
  436. MACROSTR(NotImplemented)
  437. };
  438. /*UnlockStatus*/
  439. typedef enum {
  440. Unlocked,
  441. UnlockFailed,
  442. UnlockStatus_NotSupported
  443. } UnlockStatus;
  444. static char * UnlockStatusStr[] = {
  445. MACROSTR(Unlocked),
  446. MACROSTR(UnlockFailed),
  447. MACROSTR(NotSupported)
  448. };
  449. /*StopTransactionReason*/
  450. typedef enum {
  451. EmergencyStop,
  452. EVDisconnected,
  453. HardReset,
  454. Local,
  455. Other,
  456. PowerLoss,
  457. Reboot,
  458. Remote,
  459. SoftReset,
  460. UnlockCommand,
  461. DeAuthorized
  462. } StopTransactionReason;
  463. #if 0
  464. static char * StopTransactionReasonStr[] = {
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EVDisconnected),
  467. MACROSTR(HardReset),
  468. MACROSTR(Local),
  469. MACROSTR(Other),
  470. MACROSTR(PowerLoss),
  471. MACROSTR(Reboot),
  472. MACROSTR(Remote),
  473. MACROSTR(SoftReset),
  474. MACROSTR(UnlockCommand),
  475. MACROSTR(DeAuthorized)
  476. };
  477. #endif
  478. /*CancelReservationStatus*/
  479. typedef enum {
  480. CancelReservationStatus_Accepted,
  481. CancelReservationStatus_Rejected
  482. } CancelReservationStatus;
  483. static char * CancelReservationStatusStr[] = {
  484. MACROSTR(Accepted),
  485. MACROSTR(Rejected)
  486. };
  487. /*ReadingContext*/
  488. typedef enum {
  489. ReadingContext_Interruption_Begin,
  490. ReadingContext_Interruption_End,
  491. ReadingContext_Other,
  492. ReadingContext_Sample_Clock,
  493. ReadingContext_Sample_Periodic ,
  494. ReadingContext_Transaction_Begin ,
  495. ReadingContext_Transaction_End,
  496. ReadingContext_Trigger
  497. } ReadingContext;
  498. static char * ReadingContextStr[] = {
  499. MACROSTR(Interruption.Begin),
  500. MACROSTR(Interruption.End),
  501. MACROSTR(Other),
  502. MACROSTR(Sample.Clock),
  503. MACROSTR(Sample.Periodic),
  504. MACROSTR(Transaction.Begin),
  505. MACROSTR(Transaction.End),
  506. MACROSTR(Trigger)
  507. };
  508. /*ValueFormat*/
  509. typedef enum {
  510. Raw,
  511. SignedData
  512. } ValueFormat;
  513. static char * ValueFormatStr[] = {
  514. MACROSTR(Raw),
  515. MACROSTR(SignedData)
  516. };
  517. /*Measurand*/
  518. typedef enum {
  519. Current_Export ,
  520. Current_Import,
  521. Current_Offered,
  522. Energy_Active_Export_Register,
  523. Energy_Active_Import_Register,
  524. Energy_Reactive_Export_Register,
  525. Energy_Reactive_Import_Register,
  526. Energy_Active_Export_Interval,
  527. Energy_Active_Import_Interval,
  528. Energy_Reactive_Export_Interval,
  529. Energy_Reactive_Import_Interval,
  530. Frequency,
  531. Power_Active_Export ,
  532. Power_Active_Import,
  533. Power_Factor,
  534. Power_Offered,
  535. Power_Reactive_Export,
  536. Power_Reactive_Import,
  537. RPM,
  538. SoC,
  539. Temperature ,
  540. Voltage
  541. } Measurand;
  542. static char * MeasurandStr[] = {
  543. MACROSTR(Current.Export),
  544. MACROSTR(Current.Import),
  545. MACROSTR(Current.Offered),
  546. MACROSTR(Energy.Active.Export.Register),
  547. MACROSTR(Energy.Active.Import.Register),
  548. MACROSTR(Energy.Reactive.Export.Register),
  549. MACROSTR(Energy.Reactive.Import.Register),
  550. MACROSTR(Energy.Active.Export.Interval),
  551. MACROSTR(Energy.Active.Import.Interval),
  552. MACROSTR(Energy.Reactive.Export.Interval),
  553. MACROSTR(Energy.Reactive.Import.Interval),
  554. MACROSTR(Frequency),
  555. MACROSTR(Power.Active.Export),
  556. MACROSTR(Power.Active.Import),
  557. MACROSTR(Power.Factor),
  558. MACROSTR(Power.Offered),
  559. MACROSTR(Power.Reactive.ExportMACROSTR),
  560. MACROSTR(Power.Reactive.Import),
  561. MACROSTR(RPM),
  562. MACROSTR(SoC),
  563. MACROSTR(Temperature),
  564. MACROSTR(Voltage)
  565. };
  566. /*Location*/
  567. typedef enum {
  568. Location_Body,
  569. Location_Cable,
  570. Location_EV,
  571. Location_Inlet ,
  572. Location_Outlet
  573. } Location;
  574. static char * LocationStr[] = {
  575. MACROSTR(Body),
  576. MACROSTR(Cable),
  577. MACROSTR(EV),
  578. MACROSTR(Inlet),
  579. MACROSTR(Outlet)
  580. };
  581. /*Phase*/
  582. typedef enum {
  583. L1,
  584. L2,
  585. L3,
  586. N,
  587. L1_N,
  588. L2_N,
  589. L3_N,
  590. L1_L2,
  591. L2_L3,
  592. L3_L1
  593. } Phase;
  594. static char * PhaseStr[] = {
  595. MACROSTR(L1),
  596. MACROSTR(L2),
  597. MACROSTR(L3),
  598. MACROSTR(N),
  599. MACROSTR(L1-N),
  600. MACROSTR(L2-N),
  601. MACROSTR(L3-N),
  602. MACROSTR(L1-L2),
  603. MACROSTR(L2-L3),
  604. MACROSTR(L3-L1)
  605. };
  606. /*UnitOfMeasure*/
  607. typedef enum {
  608. UnitOfMeasure_Wh,
  609. UnitOfMeasure_kWh ,
  610. UnitOfMeasure_varh ,
  611. UnitOfMeasure_kvarh ,
  612. UnitOfMeasure_W ,
  613. UnitOfMeasure_kW ,
  614. UnitOfMeasure_VA ,
  615. UnitOfMeasure_kVA ,
  616. UnitOfMeasure_var ,
  617. UnitOfMeasure_kvar ,
  618. UnitOfMeasure_A ,
  619. UnitOfMeasure_V ,
  620. UnitOfMeasure_Celsius ,
  621. UnitOfMeasure_Fahrenheit ,
  622. UnitOfMeasure_K ,
  623. UnitOfMeasure_Percent
  624. } UnitOfMeasure;
  625. static char * UnitOfMeasureStr[] = {
  626. MACROSTR(Wh),
  627. MACROSTR(kWh),
  628. MACROSTR(varh),
  629. MACROSTR(kvarh),
  630. MACROSTR(W),
  631. MACROSTR(kW),
  632. MACROSTR(VA),
  633. MACROSTR(kVA),
  634. MACROSTR(var),
  635. MACROSTR(kvar),
  636. MACROSTR(A),
  637. MACROSTR(V),
  638. MACROSTR(Celsius),
  639. MACROSTR(Fahrenheit),
  640. MACROSTR(K),
  641. MACROSTR(Percent)
  642. };
  643. enum LocalAuthListManagementProfile{
  644. LocalAuthListEnabled=0,
  645. LocalAuthListMaxLength,
  646. SendLocalListMaxLength,
  647. _LocalAuthListManagementProfile_CNT
  648. };
  649. enum ReservationProfile{
  650. ReserveConnectorZeroSupported
  651. };
  652. enum SmartChargingProfile{
  653. ChargeProfileMaxStackLevel,
  654. ChargingScheduleAllowedChargingRateUnit,
  655. ChargingScheduleMaxPeriods,
  656. ConnectorSwitch3to1PhaseSupported,
  657. MaxChargingProfilesInstalled
  658. };
  659. enum ChargerSystemStatus{
  660. ChargerSystemStatus_Booting,
  661. ChargerSystemStatus_Idle,
  662. ChargerSystemStatus_Authorizing,
  663. ChargerSystemStatus_Preparing,
  664. ChargerSystemStatus_Charging,
  665. ChargerSystemStatus_Terminating,
  666. ChargerSystemStatus_Alarm,
  667. ChargerSystemStatus_Fault
  668. };
  669. enum GetConfigurationKey {
  670. GetConfiguration_AllowOfflineTxForUnknownId=0,
  671. GetConfiguration_AuthorizationCacheEnabled,
  672. GetConfiguration_AuthorizeRemoteTxRequests,
  673. GetConfiguration_BlinkRepeat,
  674. GetConfiguration_ClockAlignedDataInterval,
  675. GetConfiguration_ConnectionTimeOut,
  676. GetConfiguration_GetConfigurationMaxKeys,
  677. GetConfiguration_HeartbeatInterval,
  678. GetConfiguration_LightIntensity,
  679. GetConfiguration_LocalAuthorizeOffline,
  680. GetConfiguration_LocalPreAuthorize,
  681. GetConfiguration_MaxEnergyOnInvalidId,
  682. GetConfiguration_MeterValuesAlignedData,
  683. GetConfiguration_MeterValuesAlignedDataMaxLength,
  684. GetConfiguration_MeterValuesSampledData,
  685. GetConfiguration_MeterValuesSampledDataMaxLength,
  686. GetConfiguration_MeterValueSampleInterval,
  687. GetConfiguration_MinimumStatusDuration,
  688. GetConfiguration_NumberOfConnectors,
  689. GetConfiguration_ResetRetries,
  690. GetConfiguration_ConnectorPhaseRotation,
  691. GetConfiguration_ConnectorPhaseRotationMaxLength,
  692. GetConfiguration_StopTransactionOnEVSideDisconnect,
  693. GetConfiguration_StopTransactionOnInvalidId,
  694. GetConfiguration_StopTxnAlignedData,
  695. GetConfiguration_StopTxnAlignedDataMaxLength,
  696. GetConfiguration_StopTxnSampledData,
  697. GetConfiguration_StopTxnSampledDataMaxLength,
  698. GetConfiguration_SupportedFeatureProfiles,
  699. GetConfiguration_SupportedFeatureProfilesMaxLength,
  700. GetConfiguration_TransactionMessageAttempts,
  701. GetConfiguration_TransactionMessageRetryInterval,
  702. GetConfiguration_UnlockConnectorOnEVSideDisconnect,
  703. GetConfiguration_WebSocketPingInterval,
  704. GetConfiguration_LocalAuthListEnabled,
  705. GetConfiguration_LocalAuthListMaxLength,
  706. GetConfiguration_SendLocalListMaxLength,
  707. GetConfiguration_ReserveConnectorZeroSupported,
  708. GetConfiguration_ChargeProfileMaxStackLevel,
  709. GetConfiguration_ChargingScheduleAllowedChargingRateUnit,
  710. GetConfiguration_ChargingScheduleMaxPeriods,
  711. GetConfiguration_ConnectorSwitch3to1PhaseSupported,
  712. GetConfiguration_MaxChargingProfilesInstalled,
  713. };
  714. //GetConfiguration Array
  715. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  716. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  717. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  718. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  719. //==========================================
  720. // GetCompositeSchedule logic related function
  721. //==========================================
  722. int DiffTimebSec(struct timeb ST, struct timeb ET)
  723. {
  724. //return milli-second
  725. unsigned int StartTime,StopTime;
  726. StartTime=(unsigned int)ST.time;
  727. StopTime=(unsigned int)ET.time;
  728. return (StopTime-StartTime);
  729. }
  730. int DiffTimebWithNowSec(struct timeb ST)
  731. {
  732. //return milli-second
  733. struct timeb ET;
  734. unsigned int StartTime,StopTime;
  735. ftime(&ET);
  736. StartTime=(unsigned int)ST.time;
  737. StopTime=(unsigned int)ET.time;
  738. return (StopTime-StartTime);
  739. }
  740. int getStartStop(uint8_t *start, uint8_t *stop)
  741. {
  742. int result = -1;
  743. struct tm tmStart;
  744. struct timeb tbStart;
  745. struct tm tmStop;
  746. struct timeb tbStop;
  747. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  748. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  749. {
  750. tmStart.tm_year -= 1900;
  751. tmStart.tm_mon -= 1;
  752. tbStart.time = mktime(&tmStart);
  753. tbStart.millitm = 0;
  754. tmStop.tm_year -= 1900;
  755. tmStop.tm_mon -= 1;
  756. tbStop.time = mktime(&tmStop);
  757. tbStop.millitm = 0;
  758. result = DiffTimebSec(tbStart, tbStop);
  759. }
  760. else
  761. {
  762. DEBUG_WARN("Start or stop date parsing error.\r\n");
  763. }
  764. return result;
  765. }
  766. int getStartSinceToday(uint8_t *stop)
  767. {
  768. int result = -1;
  769. time_t t;
  770. struct tm *tmStartToday;
  771. struct timeb tbStartToday;
  772. struct tm tmStop;
  773. struct timeb tbStop;
  774. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  775. {
  776. t=time(NULL);
  777. tmStartToday=localtime(&t);
  778. tmStartToday->tm_hour = 0;
  779. tmStartToday->tm_min = 0;
  780. tmStartToday->tm_sec = 0;
  781. tbStartToday.time = mktime(tmStartToday);
  782. tmStop.tm_year -= 1900;
  783. tmStop.tm_mon -= 1;
  784. tbStop.time = mktime(&tmStop);
  785. tbStop.millitm = 0;
  786. result = DiffTimebSec(tbStartToday, tbStop);
  787. }
  788. return result;
  789. }
  790. int getStartSinceWeek(uint8_t *stop)
  791. {
  792. int result = -1;
  793. time_t t;
  794. struct tm *tmStartWeek;
  795. struct timeb tbStartWeek;
  796. struct tm tmStop;
  797. struct timeb tbStop;
  798. if((sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  799. {
  800. t=time(NULL);
  801. tmStartWeek=localtime(&t);
  802. t-=86400*tmStartWeek->tm_wday;
  803. tmStartWeek=localtime(&t);
  804. tmStartWeek->tm_hour = 0;
  805. tmStartWeek->tm_min = 0;
  806. tmStartWeek->tm_sec = 0;
  807. tbStartWeek.time = mktime(tmStartWeek);
  808. tmStop.tm_year -= 1900;
  809. tmStop.tm_mon -= 1;
  810. tbStop.time = mktime(&tmStop);
  811. tbStop.millitm = 0;
  812. result = DiffTimebSec(tbStartWeek, tbStop);
  813. }
  814. return result;
  815. }
  816. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  817. {
  818. FILE *fp;
  819. char profileFileName[128];
  820. char *line = NULL;
  821. size_t len = 0;
  822. time_t CurrentTime;
  823. struct tm *tmComposite;
  824. struct StructChargingProfile maxProfile;
  825. struct StructChargingProfile defaultTxProfile;
  826. struct StructChargingProfile txProfile;
  827. struct StructChargingSchedulePeriod tmpPeriod;
  828. uint8_t limitMax=0;
  829. uint8_t limitDef=0;
  830. uint8_t limitTx=0;
  831. int compositePeriodIdx = 0;
  832. CurrentTime = time(NULL);
  833. tmComposite=localtime(&CurrentTime);
  834. sprintf((char*)compositeProfile->ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec);
  835. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  836. compositeProfile->ChargingSchedule.Duration = durationReq;
  837. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  838. {
  839. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  840. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  841. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  842. }
  843. compositeProfile->ChargingProfileId = 1;
  844. compositeProfile->StackLevel = 99 ;
  845. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  846. maxProfile.ChargingProfileId = -1;
  847. defaultTxProfile.ChargingProfileId = -1;
  848. txProfile.ChargingProfileId = -1;
  849. system("yes|rm /tmp/*.json");
  850. system("cp /Storage/OCPP/*.json /tmp");
  851. /*
  852. * Search valid charging profile
  853. */
  854. //DEBUG_INFO("====================================\n");
  855. // Search max profile
  856. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  857. if((access(profileFileName, F_OK))!=-1)
  858. {
  859. fp = fopen(profileFileName, "r");
  860. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  861. {
  862. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  863. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  864. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  865. }
  866. maxProfile.ChargingProfileId = -1;
  867. maxProfile.StackLevel = -1;
  868. while(getline(&line, &len, fp) != -1)
  869. {
  870. json_object *obj = NULL;
  871. obj = json_tokener_parse(line);
  872. if(is_error(obj))
  873. {
  874. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  875. }
  876. else
  877. {
  878. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  879. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  880. )
  881. {
  882. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  883. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  884. )
  885. {
  886. struct tm tmFrom, tmTo;
  887. struct timeb tbFrom, tbTo;
  888. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  889. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  890. {
  891. tmFrom.tm_year -= 1900;
  892. tmFrom.tm_mon -= 1;
  893. tbFrom.time = mktime(&tmFrom);
  894. tmTo.tm_year -= 1900;
  895. tmTo.tm_mon -= 1;
  896. tbTo.time = mktime(&tmTo);
  897. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  898. {
  899. if(maxProfile.ChargingProfileId == -1)
  900. DEBUG_INFO("MaxProfile found.\n");
  901. else
  902. DEBUG_INFO("MaxProfile updated.\n");
  903. // Required item
  904. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  905. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  906. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  907. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  908. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  909. {
  910. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  911. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  912. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  913. 3:
  914. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  915. }
  916. // Optional item
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  918. {
  919. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  920. }
  921. else
  922. {
  923. sprintf((char*)maxProfile.ValidFrom, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  926. {
  927. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  928. }
  929. else
  930. {
  931. sprintf((char*)maxProfile.ValidTo, " ");
  932. }
  933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  934. {
  935. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  936. }
  937. else
  938. {
  939. sprintf((char*)maxProfile.RecurrencyKind, " ");
  940. }
  941. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  942. {
  943. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  944. }
  945. else
  946. {
  947. maxProfile.TransactionId = -1;
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  950. {
  951. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  952. }
  953. else
  954. {
  955. maxProfile.ChargingSchedule.Duration = -1;
  956. }
  957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  958. {
  959. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  960. }
  961. else
  962. {
  963. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  964. }
  965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  966. {
  967. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  968. }
  969. else
  970. {
  971. maxProfile.ChargingSchedule.MinChargingRate = -1;
  972. }
  973. }
  974. }
  975. }
  976. else
  977. {
  978. if(maxProfile.ChargingProfileId == -1)
  979. DEBUG_INFO("MaxProfile found.\n");
  980. else
  981. DEBUG_INFO("MaxProfile updated.\n");
  982. // Required item
  983. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  984. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  985. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  986. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  987. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  988. {
  989. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  990. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  991. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  992. 3:
  993. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  994. }
  995. // Optional item
  996. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  997. {
  998. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  999. }
  1000. else
  1001. {
  1002. sprintf((char*)maxProfile.ValidFrom, " ");
  1003. }
  1004. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1005. {
  1006. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1007. }
  1008. else
  1009. {
  1010. sprintf((char*)maxProfile.ValidTo, " ");
  1011. }
  1012. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1013. {
  1014. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1015. }
  1016. else
  1017. {
  1018. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1019. }
  1020. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1021. {
  1022. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1023. }
  1024. else
  1025. {
  1026. maxProfile.TransactionId = -1;
  1027. }
  1028. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1029. {
  1030. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1031. }
  1032. else
  1033. {
  1034. maxProfile.ChargingSchedule.Duration = -1;
  1035. }
  1036. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1037. {
  1038. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1039. }
  1040. else
  1041. {
  1042. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, " ");
  1043. }
  1044. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1045. {
  1046. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1047. }
  1048. else
  1049. {
  1050. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1051. }
  1052. }
  1053. }
  1054. }
  1055. json_object_put(obj);
  1056. }
  1057. fclose(fp);
  1058. /*
  1059. if(maxProfile.ChargingProfileId !=-1)
  1060. {
  1061. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1062. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1063. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1064. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1065. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1066. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1067. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1068. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1069. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1070. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1071. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1072. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1073. {
  1074. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1075. {
  1076. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1077. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1078. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1079. }
  1080. }
  1081. }
  1082. else
  1083. DEBUG_INFO("MaxProfile not found.\n");
  1084. DEBUG_INFO("------------------------------------\n");*/
  1085. }
  1086. // Search default tx profile
  1087. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  1088. if((access(profileFileName, F_OK))==-1)
  1089. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  1090. if((access(profileFileName, F_OK))!=-1)
  1091. {
  1092. fp = fopen(profileFileName, "r");
  1093. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1094. {
  1095. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1096. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1097. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1098. }
  1099. defaultTxProfile.ChargingProfileId = -1;
  1100. defaultTxProfile.StackLevel = -1;
  1101. while(getline(&line, &len, fp) != -1)
  1102. {
  1103. json_object *obj = NULL;
  1104. obj = json_tokener_parse(line);
  1105. if(is_error(obj))
  1106. {
  1107. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  1108. }
  1109. else
  1110. {
  1111. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  1112. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  1113. )
  1114. {
  1115. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1116. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1117. )
  1118. {
  1119. struct tm tmFrom, tmTo;
  1120. struct timeb tbFrom, tbTo;
  1121. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1122. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1123. {
  1124. tmFrom.tm_year -= 1900;
  1125. tmFrom.tm_mon -= 1;
  1126. tbFrom.time = mktime(&tmFrom);
  1127. tmTo.tm_year -= 1900;
  1128. tmTo.tm_mon -= 1;
  1129. tbTo.time = mktime(&tmTo);
  1130. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1131. {
  1132. if(defaultTxProfile.ChargingProfileId == -1)
  1133. DEBUG_INFO("TxDefaultProfile found.\n");
  1134. else
  1135. DEBUG_INFO("TxDefaultProfile updated.\n");
  1136. // Required item
  1137. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1138. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1139. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1140. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1141. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1142. {
  1143. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1144. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1145. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1146. 3:
  1147. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1148. }
  1149. // Optional item
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1151. {
  1152. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1153. }
  1154. else
  1155. {
  1156. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1157. }
  1158. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1159. {
  1160. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1161. }
  1162. else
  1163. {
  1164. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1165. }
  1166. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1167. {
  1168. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1169. }
  1170. else
  1171. {
  1172. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1173. }
  1174. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1175. {
  1176. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1177. }
  1178. else
  1179. {
  1180. defaultTxProfile.TransactionId = -1;
  1181. }
  1182. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1183. {
  1184. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1185. }
  1186. else
  1187. {
  1188. defaultTxProfile.ChargingSchedule.Duration = -1;
  1189. }
  1190. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1191. {
  1192. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1193. }
  1194. else
  1195. {
  1196. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1197. }
  1198. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1199. {
  1200. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1201. }
  1202. else
  1203. {
  1204. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. else
  1210. {
  1211. if(defaultTxProfile.ChargingProfileId == -1)
  1212. DEBUG_INFO("TxDefaultProfile found.\n");
  1213. else
  1214. DEBUG_INFO("TxDefaultProfile updated.\n");
  1215. // Required item
  1216. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1217. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1218. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1219. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1220. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1221. {
  1222. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1223. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1224. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1225. 3:
  1226. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1227. }
  1228. // Optional item
  1229. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1230. {
  1231. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1232. }
  1233. else
  1234. {
  1235. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  1236. }
  1237. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1238. {
  1239. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1240. }
  1241. else
  1242. {
  1243. sprintf((char*)defaultTxProfile.ValidTo, " ");
  1244. }
  1245. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1246. {
  1247. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1248. }
  1249. else
  1250. {
  1251. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  1252. }
  1253. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1254. {
  1255. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1256. }
  1257. else
  1258. {
  1259. defaultTxProfile.TransactionId = -1;
  1260. }
  1261. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1262. {
  1263. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1264. }
  1265. else
  1266. {
  1267. defaultTxProfile.ChargingSchedule.Duration = -1;
  1268. }
  1269. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1270. {
  1271. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1272. }
  1273. else
  1274. {
  1275. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, " ");
  1276. }
  1277. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1278. {
  1279. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1280. }
  1281. else
  1282. {
  1283. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. json_object_put(obj);
  1289. }
  1290. fclose(fp);
  1291. /*
  1292. if(defaultTxProfile.ChargingProfileId != -1)
  1293. {
  1294. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1295. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1296. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1297. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1298. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1299. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1300. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1301. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  1302. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1303. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1304. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1305. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1306. {
  1307. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1308. {
  1309. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1310. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1311. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1312. }
  1313. }
  1314. }
  1315. else
  1316. DEBUG_INFO("TxDefaultProfile not found.\n");
  1317. DEBUG_INFO("------------------------------------\n");*/
  1318. }
  1319. // Search tx profile
  1320. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  1321. if((access(profileFileName, F_OK))!=-1)
  1322. {
  1323. fp = fopen(profileFileName, "r");
  1324. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1325. {
  1326. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  1327. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1329. }
  1330. txProfile.ChargingProfileId = -1;
  1331. txProfile.StackLevel = -1;
  1332. while(getline(&line, &len, fp) != -1)
  1333. {
  1334. json_object *obj = NULL;
  1335. obj = json_tokener_parse(line);
  1336. if(is_error(obj))
  1337. {
  1338. DEBUG_ERROR("Parse txProfile from file error.\n");
  1339. }
  1340. else
  1341. {
  1342. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  1343. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  1344. )
  1345. {
  1346. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1347. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1348. )
  1349. {
  1350. struct tm tmFrom, tmTo;
  1351. struct timeb tbFrom, tbTo;
  1352. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  1353. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  1354. {
  1355. tmFrom.tm_year -= 1900;
  1356. tmFrom.tm_mon -= 1;
  1357. tbFrom.time = mktime(&tmFrom);
  1358. tmTo.tm_year -= 1900;
  1359. tmTo.tm_mon -= 1;
  1360. tbTo.time = mktime(&tmTo);
  1361. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1362. {
  1363. if(txProfile.ChargingProfileId == -1)
  1364. DEBUG_INFO("TxProfile found.\n");
  1365. else
  1366. DEBUG_INFO("TxProfile updated.\n");
  1367. // Required item
  1368. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1369. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1370. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1371. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1372. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1373. {
  1374. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1375. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1376. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1377. 3:
  1378. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1379. }
  1380. // Optional item
  1381. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1382. {
  1383. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1384. }
  1385. else
  1386. {
  1387. sprintf((char*)txProfile.ValidFrom, " ");
  1388. }
  1389. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1390. {
  1391. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1392. }
  1393. else
  1394. {
  1395. sprintf((char*)txProfile.ValidTo, " ");
  1396. }
  1397. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1398. {
  1399. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1400. }
  1401. else
  1402. {
  1403. sprintf((char*)txProfile.RecurrencyKind, " ");
  1404. }
  1405. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1406. {
  1407. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1408. }
  1409. else
  1410. {
  1411. txProfile.TransactionId = -1;
  1412. }
  1413. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1414. {
  1415. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1416. }
  1417. else
  1418. {
  1419. txProfile.ChargingSchedule.Duration = -1;
  1420. }
  1421. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1422. {
  1423. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1424. }
  1425. else
  1426. {
  1427. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1428. }
  1429. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1430. {
  1431. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1432. }
  1433. else
  1434. {
  1435. txProfile.ChargingSchedule.MinChargingRate = -1;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. else
  1441. {
  1442. if(txProfile.ChargingProfileId == -1)
  1443. DEBUG_INFO("TxProfile found.\n");
  1444. else
  1445. DEBUG_INFO("TxProfile updated.\n");
  1446. // Required item
  1447. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1448. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1449. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1450. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  1451. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  1452. {
  1453. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  1454. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"W")!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/220:json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  1455. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  1456. 3:
  1457. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  1458. }
  1459. // Optional item
  1460. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1461. {
  1462. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1463. }
  1464. else
  1465. {
  1466. sprintf((char*)txProfile.ValidFrom, " ");
  1467. }
  1468. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1469. {
  1470. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1471. }
  1472. else
  1473. {
  1474. sprintf((char*)txProfile.ValidTo, " ");
  1475. }
  1476. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1477. {
  1478. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1479. }
  1480. else
  1481. {
  1482. sprintf((char*)txProfile.RecurrencyKind, " ");
  1483. }
  1484. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1485. {
  1486. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1487. }
  1488. else
  1489. {
  1490. txProfile.TransactionId = -1;
  1491. }
  1492. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1493. {
  1494. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1495. }
  1496. else
  1497. {
  1498. txProfile.ChargingSchedule.Duration = -1;
  1499. }
  1500. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1501. {
  1502. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1503. }
  1504. else
  1505. {
  1506. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, " ");
  1507. }
  1508. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1509. {
  1510. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1511. }
  1512. else
  1513. {
  1514. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1515. }
  1516. }
  1517. }
  1518. }
  1519. json_object_put(obj);
  1520. }
  1521. fclose(fp);
  1522. /*
  1523. if(defaultTxProfile.ChargingProfileId != -1)
  1524. {
  1525. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1526. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1527. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1528. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1529. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1530. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1531. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1532. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  1533. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1534. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1535. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1536. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1537. {
  1538. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1539. {
  1540. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1541. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1542. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1543. }
  1544. }
  1545. }
  1546. else
  1547. DEBUG_INFO("TxProfile not found.\n");*/
  1548. }
  1549. /*
  1550. * Align found profile start schedule & periods
  1551. */
  1552. //DEBUG_INFO("====================================\n");
  1553. /*
  1554. // For local test usage, force modify found profile start schedule info
  1555. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-10);
  1556. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-5);
  1557. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%04d-%02d-%02dT%02d:%02d:%02dZ", tmComposite->tm_year+1900, tmComposite->tm_mon+1, tmComposite->tm_mday, tmComposite->tm_hour, tmComposite->tm_min, tmComposite->tm_sec-3);
  1558. */
  1559. if(maxProfile.ChargingProfileId != -1)
  1560. {
  1561. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1562. {
  1563. if(maxProfile.ChargingSchedule.Duration != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1568. }
  1569. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1570. {
  1571. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1572. {
  1573. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1574. 0:
  1575. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1576. }
  1577. }
  1578. }
  1579. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1580. {
  1581. if(maxProfile.ChargingSchedule.Duration != -1)
  1582. {
  1583. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1584. 0:
  1585. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1586. }
  1587. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1588. {
  1589. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1590. {
  1591. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1592. 0:
  1593. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1600. {
  1601. if(maxProfile.ChargingSchedule.Duration != -1)
  1602. {
  1603. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1604. 0:
  1605. (maxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1606. }
  1607. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1608. {
  1609. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1610. {
  1611. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1612. 0:
  1613. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1614. }
  1615. }
  1616. }
  1617. else
  1618. {
  1619. if(maxProfile.ChargingSchedule.Duration != -1)
  1620. {
  1621. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1622. 0:
  1623. (maxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1624. }
  1625. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1626. {
  1627. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1628. {
  1629. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1630. 0:
  1631. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1632. }
  1633. }
  1634. }
  1635. }
  1636. /*
  1637. DEBUG_INFO("MaxProfile after align.\n");
  1638. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1639. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1640. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1641. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1642. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1643. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1644. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1645. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1646. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1647. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1648. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1649. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1650. {
  1651. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1652. {
  1653. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1654. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1655. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1656. }
  1657. }
  1658. DEBUG_INFO("------------------------------------\n");*/
  1659. }
  1660. if(defaultTxProfile.ChargingProfileId != -1)
  1661. {
  1662. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1663. {
  1664. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1665. {
  1666. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1667. 0:
  1668. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1669. }
  1670. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1671. {
  1672. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1673. {
  1674. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1675. 0:
  1676. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1677. }
  1678. }
  1679. }
  1680. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1681. {
  1682. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1683. {
  1684. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1685. 0:
  1686. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1687. }
  1688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1689. {
  1690. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1691. {
  1692. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1693. 0:
  1694. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1695. }
  1696. }
  1697. }
  1698. else
  1699. {
  1700. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1701. {
  1702. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1703. {
  1704. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1705. 0:
  1706. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1707. }
  1708. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1709. {
  1710. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1711. {
  1712. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1713. 0:
  1714. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1715. }
  1716. }
  1717. }
  1718. else
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1721. {
  1722. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1723. 0:
  1724. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1725. }
  1726. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1727. {
  1728. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1729. {
  1730. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1731. 0:
  1732. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1733. }
  1734. }
  1735. }
  1736. }
  1737. /*
  1738. DEBUG_INFO("defaultTxProfile after align.\n");
  1739. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1740. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1741. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1742. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1743. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1744. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1745. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1746. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1747. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1748. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1749. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1750. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1753. {
  1754. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1755. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1756. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1757. }
  1758. }
  1759. DEBUG_INFO("------------------------------------\n");*/
  1760. }
  1761. if(txProfile.ChargingProfileId != -1)
  1762. {
  1763. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1764. {
  1765. if(txProfile.ChargingSchedule.Duration != -1)
  1766. {
  1767. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1768. 0:
  1769. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1770. }
  1771. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1772. {
  1773. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1774. {
  1775. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1776. 0:
  1777. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1778. }
  1779. }
  1780. }
  1781. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1782. {
  1783. if(txProfile.ChargingSchedule.Duration != -1)
  1784. {
  1785. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1786. 0:
  1787. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1788. }
  1789. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1790. {
  1791. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1792. {
  1793. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1794. 0:
  1795. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1796. }
  1797. }
  1798. }
  1799. else
  1800. {
  1801. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1802. {
  1803. if(txProfile.ChargingSchedule.Duration != -1)
  1804. {
  1805. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1806. 0:
  1807. (txProfile.ChargingSchedule.Duration-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1808. }
  1809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1810. {
  1811. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1812. {
  1813. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1814. 0:
  1815. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceWeek(compositeProfile->ChargingSchedule.StartSchedule)));
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(txProfile.ChargingSchedule.Duration != -1)
  1822. {
  1823. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1824. 0:
  1825. (txProfile.ChargingSchedule.Duration-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1826. }
  1827. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1828. {
  1829. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1830. {
  1831. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule))<0?
  1832. 0:
  1833. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceToday(compositeProfile->ChargingSchedule.StartSchedule)));
  1834. }
  1835. }
  1836. }
  1837. }
  1838. /*
  1839. DEBUG_INFO("txProfile after align.\n");
  1840. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1841. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1842. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1843. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1844. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1845. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1846. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1847. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1848. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1849. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1850. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1851. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1852. {
  1853. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1854. {
  1855. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1856. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1857. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1858. }
  1859. }*/
  1860. }
  1861. /*
  1862. * Merge to conposite schedule
  1863. */
  1864. //DEBUG_INFO("====================================\n");
  1865. // Find each profile period quantity
  1866. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1867. {
  1868. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1869. limitMax = idx+1;
  1870. }
  1871. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1872. {
  1873. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1874. limitDef = idx+1;
  1875. }
  1876. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1877. {
  1878. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1879. limitTx = idx+1;
  1880. }
  1881. // TxProfile found, composite schedule based on it
  1882. if(txProfile.ChargingProfileId != -1)
  1883. {
  1884. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1885. {
  1886. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1887. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq))
  1888. {
  1889. if(maxProfile.ChargingProfileId != -1)
  1890. {
  1891. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1892. {
  1893. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod) &&
  1894. (maxProfile.ChargingSchedule.Duration > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod))
  1895. {
  1896. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1897. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1898. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1899. }
  1900. if(idxMaxPeriod == (limitMax-1))
  1901. {
  1902. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1903. {
  1904. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1905. {
  1906. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1907. compositePeriodIdx++;
  1908. }
  1909. else
  1910. {
  1911. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. else
  1918. {
  1919. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1920. {
  1921. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1922. compositePeriodIdx++;
  1923. }
  1924. else
  1925. {
  1926. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1927. }
  1928. }
  1929. }
  1930. if(idxTxPeriod == (limitTx-1))
  1931. {
  1932. if(defaultTxProfile.ChargingProfileId != -1)
  1933. {
  1934. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1935. {
  1936. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod > txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod) &&
  1937. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1938. {
  1939. if(maxProfile.ChargingProfileId != -1)
  1940. {
  1941. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1942. {
  1943. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1944. {
  1945. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1946. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1947. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1948. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1949. {
  1950. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1951. {
  1952. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1953. compositePeriodIdx++;
  1954. }
  1955. else
  1956. {
  1957. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1958. }
  1959. }
  1960. break;
  1961. }
  1962. }
  1963. }
  1964. else
  1965. {
  1966. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1967. {
  1968. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1969. compositePeriodIdx++;
  1970. }
  1971. else
  1972. {
  1973. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1974. }
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. }
  1982. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1983. else if(defaultTxProfile.ChargingProfileId != -1)
  1984. {
  1985. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1986. {
  1987. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1988. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq))
  1989. {
  1990. if(maxProfile.ChargingProfileId != -1)
  1991. {
  1992. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1993. {
  1994. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1995. {
  1996. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1997. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1998. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1999. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2000. {
  2001. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2002. {
  2003. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2004. compositePeriodIdx++;
  2005. }
  2006. else
  2007. {
  2008. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2009. }
  2010. }
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. else
  2016. {
  2017. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2018. {
  2019. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2020. compositePeriodIdx++;
  2021. }
  2022. else
  2023. {
  2024. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  2025. }
  2026. }
  2027. }
  2028. }
  2029. }
  2030. // Fill other period by MaxProfile
  2031. if(maxProfile.ChargingProfileId != -1)
  2032. {
  2033. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  2034. {
  2035. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  2036. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq))
  2037. {
  2038. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  2039. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  2040. {
  2041. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  2042. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  2043. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2044. }
  2045. if(idxMaxPeriod == (limitMax-1))
  2046. {
  2047. if(maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod)
  2048. {
  2049. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  2050. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  2051. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  2052. }
  2053. if(tmpPeriod.Limit != -1)
  2054. {
  2055. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  2056. {
  2057. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  2058. {
  2059. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2060. compositePeriodIdx++;
  2061. }
  2062. else
  2063. {
  2064. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. }
  2071. }
  2072. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  2073. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  2074. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  2075. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  2076. {
  2077. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  2078. {
  2079. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  2080. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  2081. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  2082. }
  2083. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  2084. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  2085. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  2086. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  2087. }
  2088. if(line)
  2089. free(line);
  2090. }
  2091. //==========================================
  2092. // Init all share memory
  2093. //==========================================
  2094. int InitShareMemory()
  2095. {
  2096. int result = PASS;
  2097. int MeterSMId;
  2098. //creat ShmSysConfigAndInfo
  2099. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  2100. {
  2101. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  2102. result = FAIL;
  2103. }
  2104. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2105. {
  2106. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  2107. result = FAIL;
  2108. }
  2109. else
  2110. {}
  2111. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  2112. {
  2113. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  2114. result = FAIL;
  2115. }
  2116. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2117. {
  2118. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  2119. result = FAIL;
  2120. }
  2121. else
  2122. {}
  2123. //creat ShmPsuData
  2124. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  2125. {
  2126. DEBUG_ERROR("shmget ShmPsuData NG\n");
  2127. result = FAIL;
  2128. }
  2129. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2130. {
  2131. DEBUG_ERROR("shmat ShmPsuData NG\n");
  2132. result = FAIL;
  2133. }
  2134. else
  2135. {}
  2136. //creat ShmOCPP16Data
  2137. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  2138. {
  2139. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  2140. result = FAIL;
  2141. }
  2142. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  2143. {
  2144. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  2145. result = FAIL;
  2146. }
  2147. else
  2148. {}
  2149. /****************************** For Initial Settings************************************************/
  2150. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  2151. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  2152. // allocate Configuration memory address
  2153. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  2154. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  2155. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  2156. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  2157. //offline MeterValue Interval
  2158. TempMeterValueInterval = 0;
  2159. return result;
  2160. }
  2161. int ProcessShareMemory()
  2162. {
  2163. if(InitShareMemory() == FAIL)
  2164. {
  2165. DEBUG_ERROR("InitShareMemory NG\n");
  2166. if(ShmStatusCodeData!=NULL)
  2167. {
  2168. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2169. }
  2170. sleep(5);
  2171. return FAIL;
  2172. }
  2173. return PASS;
  2174. }
  2175. //---------------------common routine---------------------------//
  2176. int isOFFline(void)
  2177. {
  2178. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  2179. {
  2180. if(TempMeterValueInterval >= 2 )
  2181. {
  2182. TempMeterValueInterval = 0;
  2183. return TRUE;
  2184. }
  2185. else
  2186. {
  2187. TempMeterValueInterval = TempMeterValueInterval+ 1;
  2188. return FALSE;
  2189. }
  2190. }
  2191. else
  2192. {
  2193. return FALSE;
  2194. }
  2195. }
  2196. //---------------------------------------------
  2197. // new:
  2198. // enum SYSTEM_STATUS
  2199. // {
  2200. // SYS_MODE_BOOTING = 0,
  2201. // SYS_MODE_IDLE = 1,
  2202. // SYS_MODE_AUTHORIZING = 2,
  2203. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2204. // SYS_MODE_REASSIGN = 4,
  2205. // SYS_MODE_PREPARING = 5,
  2206. // SYS_MODE_PREPARE_FOR_EV = 6,
  2207. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2208. // SYS_MODE_CHARGING = 8,
  2209. // SYS_MODE_TERMINATING = 9,
  2210. // SYS_MODE_COMPLETE = 10,
  2211. // SYS_MODE_ALARM = 11,
  2212. // SYS_MODE_FAULT = 12,
  2213. // SYS_MODE_RESERVATION = 13,
  2214. // SYS_MODE_BOOKING = 14,
  2215. // SYS_MODE_MAINTAIN = 15,
  2216. // SYS_MODE_DEBUG = 16,
  2217. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2218. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2219. // SYS_MODE_UPDATE = 19
  2220. // };
  2221. //
  2222. //
  2223. //-----------------------------------------
  2224. void CheckSystemValue(void)
  2225. {
  2226. int meterValueSend[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2227. //int IdleModeCnt = 0;
  2228. char filenmae[100]={0};
  2229. char str[100]={0};
  2230. //===============================
  2231. // send Heartbeat
  2232. //===============================
  2233. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2234. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2235. {
  2236. clientTime.Heartbeat=time((time_t*)NULL);
  2237. if(server_sign == TRUE)
  2238. {
  2239. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2240. }
  2241. else
  2242. {
  2243. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2244. }
  2245. }
  2246. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2247. {
  2248. //parameter for test
  2249. sendHeartbeatRequest(0);
  2250. //==============================================
  2251. // Reset Waiting Time
  2252. //==============================================
  2253. clientTime.Heartbeat=time((time_t*)NULL);
  2254. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2255. }
  2256. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2257. {
  2258. //===============================
  2259. // CSU Trigger Reset Conf
  2260. //===============================
  2261. if((server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2262. {
  2263. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2264. }
  2265. //===============================
  2266. // CSU Trigger Authorize Request
  2267. //===============================
  2268. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2269. {
  2270. sendAuthorizeRequest(0);
  2271. authorizeRetryTimes = authorizeRetryTimes + 1;
  2272. if(authorizeRetryTimes < 3)
  2273. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2274. }
  2275. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes >= 3))
  2276. {
  2277. authorizeRetryTimes = 0;
  2278. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2279. server_sign = FALSE;
  2280. }
  2281. else if((server_sign == FALSE) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2282. {
  2283. sendAuthorizeRequest(0);
  2284. }
  2285. //===============================
  2286. // CSU Trigger Smart Charging Profilw
  2287. //===============================
  2288. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2289. {
  2290. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2291. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2292. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2293. }
  2294. //==============================================
  2295. // Charger start transaction
  2296. //==============================================
  2297. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2298. {
  2299. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2300. sendStartTransactionRequest(gun_index);
  2301. clientTime.StartTransaction = time((time_t*)NULL);
  2302. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2303. }
  2304. //==============================================
  2305. // Charger stop transaction
  2306. //==============================================
  2307. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2308. {
  2309. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2310. sendStopTransactionRequest(gun_index);
  2311. clientTime.StopTransaction = time((time_t*)NULL);
  2312. }
  2313. //==============================================
  2314. // Charger status report
  2315. //==============================================
  2316. //--- Check Mode Change ---//
  2317. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2318. if(gunType[gun_index] == 'J')
  2319. {
  2320. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2321. {
  2322. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  2323. {
  2324. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2325. {
  2326. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2327. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2328. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2329. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2330. statusModeChage[gun_index] = TRUE;
  2331. }
  2332. #if 1 // for TempStopTransaction
  2333. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2334. {
  2335. checkTempStopTransaction(gun_index);
  2336. }
  2337. #endif
  2338. }
  2339. }
  2340. }
  2341. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2342. {
  2343. for (int index = 0; index < CCS_QUANTITY; index++)
  2344. {
  2345. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  2346. {
  2347. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2348. {
  2349. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2350. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2351. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2352. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2353. statusModeChage[gun_index] = TRUE;
  2354. }
  2355. #if 1 // for TempStopTransaction
  2356. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2357. {
  2358. checkTempStopTransaction(gun_index);
  2359. }
  2360. #endif
  2361. }
  2362. }
  2363. }
  2364. else if(gunType[gun_index] == 'G')
  2365. {
  2366. for (int index = 0; index < GB_QUANTITY; index++)
  2367. {
  2368. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  2369. {
  2370. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2371. {
  2372. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2373. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2374. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2375. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2376. statusModeChage[gun_index] = TRUE;
  2377. }
  2378. #if 1 // for TempStopTransaction
  2379. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2380. {
  2381. checkTempStopTransaction(gun_index);
  2382. }
  2383. #endif
  2384. }
  2385. }
  2386. }
  2387. else
  2388. {
  2389. for (int index = 0; index < AC_QUANTITY; index++)
  2390. {
  2391. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  2392. {
  2393. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  2394. {
  2395. //PRE_SYS_MODE[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2396. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2397. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2398. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2399. statusModeChage[gun_index] = TRUE;
  2400. }
  2401. #if 1 // for TempStopTransaction
  2402. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2403. {
  2404. checkTempStopTransaction(gun_index);
  2405. }
  2406. #endif
  2407. }
  2408. }// END
  2409. }
  2410. if(((server_sign == TRUE) && (SystemInitial > 0)) ||
  2411. ((server_sign == TRUE) && ((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 30)))) )
  2412. {
  2413. if(SystemInitial > 0)
  2414. SystemInitial = SystemInitial -1;
  2415. sendStatusNotificationRequest(gun_index);
  2416. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2417. statusModeChage[gun_index] = FALSE;
  2418. }
  2419. //==============================================
  2420. // Meter report
  2421. //==============================================
  2422. if(/*(server_sign == TRUE) &&*/(isOFFline() == TRUE) || ((time((time_t*)NULL) - clientTime.MeterValues[gun_index])> (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1 ) ) )
  2423. {
  2424. //check Transaction active
  2425. if(gunType[gun_index] == 'J')
  2426. {
  2427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2428. {
  2429. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2430. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2431. {
  2432. meterValueSend[gun_index] =1;
  2433. }
  2434. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2435. {
  2436. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2437. if((access(filenmae,F_OK))!=-1)
  2438. {
  2439. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2440. sprintf(str,"rm -f %s",filenmae);
  2441. system(str);
  2442. }
  2443. }
  2444. }// End for CHAdeMO
  2445. }
  2446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2447. {
  2448. for (int index = 0; index < CCS_QUANTITY; index++)
  2449. {
  2450. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2451. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2452. {
  2453. meterValueSend[gun_index] =1;
  2454. }
  2455. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2456. {
  2457. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2458. if((access(filenmae,F_OK))!=-1)
  2459. {
  2460. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2461. sprintf(str,"rm -f %s",filenmae);
  2462. system(str);
  2463. }
  2464. }
  2465. } // End for CCS
  2466. }
  2467. else if(gunType[gun_index] == 'G')
  2468. {
  2469. for (int index = 0; index < GB_QUANTITY; index++)
  2470. {
  2471. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2472. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2473. {
  2474. meterValueSend[gun_index] =1;
  2475. }
  2476. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2477. {
  2478. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2479. if((access(filenmae,F_OK))!=-1)
  2480. {
  2481. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2482. sprintf(str,"rm -f %s",filenmae);
  2483. system(str);
  2484. }
  2485. }
  2486. }// End for GB
  2487. }
  2488. else
  2489. {
  2490. for (int index = 0; index < AC_QUANTITY; index++)
  2491. {
  2492. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2493. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING))
  2494. {
  2495. meterValueSend[gun_index] =1;
  2496. }
  2497. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2498. {
  2499. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2500. if((access(filenmae,F_OK))!=-1)
  2501. {
  2502. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2503. sprintf(str,"rm -f %s",filenmae);
  2504. system(str);
  2505. }
  2506. }
  2507. }//End for AC
  2508. }
  2509. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2510. if(meterValueSend[gun_index] == 1)
  2511. {
  2512. sendMeterValuesRequest(gun_index);
  2513. #if 1 // for TempStopTransaction
  2514. storeTempStopTransaction(gun_index);
  2515. #endif
  2516. }
  2517. }
  2518. //==============================================
  2519. // Check Connector reserved
  2520. //==============================================
  2521. //===============================
  2522. // Check if Reserve is expired
  2523. //===============================
  2524. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2525. {
  2526. double diff_t;
  2527. struct tm tp;
  2528. // current time
  2529. time_t t = time(NULL);
  2530. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2531. tp.tm_isdst = -1;
  2532. time_t utc = mktime(&tp);
  2533. diff_t = difftime(utc, t);
  2534. if(diff_t <= 0)
  2535. {
  2536. DEBUG_INFO("reserve expired.\n");
  2537. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,sizeof(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2538. }
  2539. }//END OF Check if Reserve is expired
  2540. //==========================================
  2541. // csu trigger FirmwareStatusNotificationReq
  2542. //==========================================
  2543. if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2544. {
  2545. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2546. }
  2547. //==========================================
  2548. // csu trigger CancelReservationConf
  2549. //==========================================
  2550. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2551. {
  2552. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2553. }
  2554. //==========================================
  2555. // csu trigger ChangeAvailabilityConf
  2556. //==========================================
  2557. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2558. {
  2559. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2560. }
  2561. //==========================================
  2562. // csu trigger UnlockConnectorConf
  2563. //==========================================
  2564. if((server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2565. {
  2566. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2567. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2568. }
  2569. //==========================================
  2570. // csu trigger ReserveNowConf
  2571. //==========================================
  2572. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2573. {
  2574. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2575. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2576. }
  2577. //==========================================
  2578. // csu trigger DataTransferReq
  2579. //==========================================
  2580. if((server_sign == TRUE) &&(ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2581. {
  2582. sendDataTransferRequest(gun_index);
  2583. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2584. }
  2585. }
  2586. }
  2587. //==========================================
  2588. // send request routine
  2589. //==========================================
  2590. int sendAuthorizeRequest(int gun_index)
  2591. {
  2592. mtrace();
  2593. int result = FAIL;
  2594. char message[100]={0};
  2595. char guid[37];
  2596. char tempdata[65]={0};
  2597. DEBUG_INFO("sendAuthorizeRequest...\n");
  2598. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2599. //Local Authorize
  2600. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2601. {
  2602. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2603. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2604. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2605. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2606. result = PASS;
  2607. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2608. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2609. authorizeRetryTimes = 0;
  2610. return result;
  2611. }
  2612. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  2613. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2614. {
  2615. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2616. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2617. {
  2618. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2619. {
  2620. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2621. }
  2622. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2623. {
  2624. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2625. }
  2626. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2627. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2628. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2629. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2630. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2631. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2632. authorizeRetryTimes = 0;
  2633. return result;
  2634. }
  2635. else
  2636. {
  2637. DEBUG_INFO("offline Local Authorization Pass !!!!\n");
  2638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2641. result = PASS;
  2642. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2644. authorizeRetryTimes = 0;
  2645. return result;
  2646. }
  2647. }
  2648. //initailize struct Authorize
  2649. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2650. //get data from shared memory
  2651. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2652. random_uuid(guid);
  2653. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2654. LWS_Send(message);
  2655. sprintf(tempdata, "Authorize,%d", gun_index);
  2656. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2657. {
  2658. result = PASS;
  2659. DEBUG_INFO("Authorize mapItem pass\n");
  2660. }
  2661. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2662. return result;
  2663. }
  2664. int sendBootNotificationRequest(void)
  2665. {
  2666. mtrace();
  2667. int result = FAIL;
  2668. char message[500]={0}, payload[700]={0};
  2669. char guid[37]={0};
  2670. char tempdata[65]={0};
  2671. int IsGunCharging = FALSE;
  2672. //check Transaction active
  2673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2674. {
  2675. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2676. {
  2677. IsGunCharging = TRUE;
  2678. }
  2679. }
  2680. for (int index = 0; index < CCS_QUANTITY; index++)
  2681. {
  2682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2683. {
  2684. IsGunCharging = TRUE;
  2685. }
  2686. }
  2687. for (int index = 0; index < GB_QUANTITY; index++)
  2688. {
  2689. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2690. {
  2691. IsGunCharging = TRUE;
  2692. }
  2693. }
  2694. for (int index = 0; index < AC_QUANTITY; index++)
  2695. {
  2696. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2697. {
  2698. IsGunCharging = TRUE;
  2699. }
  2700. }
  2701. if(IsGunCharging == TRUE)
  2702. {
  2703. server_sign = TRUE;
  2704. return result;
  2705. }
  2706. // Fill BootNotification fields
  2707. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2708. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2709. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2710. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2711. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2712. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2713. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2714. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2715. ShmOCPP16Data->ChargeBoxId
  2716. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2717. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2718. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2719. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2720. ,ShmOCPP16Data->BootNotification.CpIccid
  2721. ,ShmOCPP16Data->BootNotification.CpImsi);
  2722. random_uuid(guid);
  2723. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2724. LWS_Send(message);
  2725. sprintf(tempdata, "BootNotification,0");
  2726. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2727. {
  2728. result = PASS;
  2729. }
  2730. memset(queuedata, 0, sizeof(queuedata));
  2731. strcpy(queuedata,message);
  2732. return result;
  2733. }
  2734. int sendDataTransferRequest(int gun_index)
  2735. {
  2736. mtrace();
  2737. char message[1000]={0};
  2738. char guid[37]={0};
  2739. char tempdata[65]={0};
  2740. int result = FAIL;
  2741. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2742. random_uuid(guid);
  2743. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2744. MESSAGE_TYPE_CALL,
  2745. guid,
  2746. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2747. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2748. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2749. LWS_Send(message);
  2750. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2751. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2752. {
  2753. result = PASS;
  2754. DEBUG_INFO("DataTransfer mapItem pass\n");
  2755. }
  2756. return result;
  2757. }
  2758. int sendFirmwareVersionByDataTransfer(void)
  2759. {
  2760. int8_t result = FAIL;
  2761. json_object *FirmwareDataTransfer = json_object_new_object();
  2762. // AC & DC model
  2763. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  2764. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  2765. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  2766. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  2767. // DC model
  2768. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  2769. {
  2770. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  2771. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  2772. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  2773. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  2774. }
  2775. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  2776. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  2777. {
  2778. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  2779. }
  2780. // 4G model
  2781. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  2782. {
  2783. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  2784. }
  2785. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  2786. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  2787. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  2788. if(sendDataTransferRequest(0))
  2789. {
  2790. result = PASS;
  2791. }
  2792. return result;
  2793. }
  2794. int sendDiagnosticsStatusNotificationRequest(char *status)
  2795. {
  2796. mtrace();
  2797. int result = FAIL;
  2798. char message[110]={0};
  2799. char guid[37]={0};
  2800. char tempdata[65]={0};
  2801. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2802. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2803. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2804. random_uuid(guid);
  2805. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2806. LWS_Send(message);
  2807. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2808. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2809. {
  2810. result = PASS;
  2811. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2812. }
  2813. //#ifdef SystemLogMessage
  2814. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2815. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2816. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2817. //#endif
  2818. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2819. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2820. //record status
  2821. if(strcmp(status,"Idle")==0)
  2822. {
  2823. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2824. }
  2825. else if(strcmp(status,"Uploaded")==0)
  2826. {
  2827. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2828. }
  2829. else if(strcmp(status,"UploadFailed")==0)
  2830. {
  2831. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2832. }
  2833. else if(strcmp(status,"Uploading")==0)
  2834. {
  2835. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2836. }
  2837. return result;
  2838. }
  2839. int sendFirmwareStatusNotificationRequest(char *status)
  2840. {
  2841. mtrace();
  2842. int result = FAIL;
  2843. char message[110]={0};
  2844. char guid[37]={0};
  2845. char tempdata[65]={0};
  2846. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2847. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2848. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2849. random_uuid(guid);
  2850. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2851. LWS_Send(message);
  2852. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2853. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2854. {
  2855. result = PASS;
  2856. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2857. }
  2858. //#ifdef SystemLogMessage
  2859. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2860. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2861. //#endif
  2862. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2863. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2864. //record status
  2865. if(strcmp(status,"Downloaded")==0)
  2866. {
  2867. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2868. }
  2869. else if(strcmp(status,"DownloadFailed")==0)
  2870. {
  2871. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_DAILED;
  2872. }
  2873. else if(strcmp(status,"Downloading")==0)
  2874. {
  2875. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2876. }
  2877. else if(strcmp(status,"Idle")==0)
  2878. {
  2879. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2880. }
  2881. else if(strcmp(status,"InstallationFailed")==0)
  2882. {
  2883. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2884. }
  2885. else if(strcmp(status,"Installing")==0)
  2886. {
  2887. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2888. }
  2889. else if(strcmp(status,"Installed")==0)
  2890. {
  2891. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2892. }
  2893. return result;
  2894. }
  2895. int sendHeartbeatRequest(int gun_index)
  2896. {
  2897. mtrace();
  2898. int result = FAIL;
  2899. char message[80]={0};
  2900. char guid[37]={0};
  2901. char tempdata[65]={0};
  2902. random_uuid(guid);
  2903. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2904. , MESSAGE_TYPE_CALL
  2905. , guid );
  2906. LWS_Send(message);
  2907. sprintf(tempdata, "Heartbeat,%d", 0);
  2908. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2909. {
  2910. result = PASS;
  2911. }
  2912. return result;
  2913. }
  2914. int sendStartTransactionRequest(int gun_index)
  2915. {
  2916. mtrace();
  2917. int result = FAIL;
  2918. char message[250]={0};
  2919. char guid[37]={0};
  2920. struct timeval tmnow;
  2921. struct tm *tm;
  2922. char buf[28];//, usec_buf[6];
  2923. char tempdata[65]={0};
  2924. int tempIndex = 0;
  2925. DEBUG_INFO("sendStartTransactionRequest...");
  2926. gettimeofday(&tmnow, NULL);
  2927. time_t t;
  2928. t = time(NULL);
  2929. /*UTC time and date*/
  2930. tm = gmtime(&t);
  2931. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2932. #if 0 // remove temporally
  2933. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2934. strcat(buf,".");
  2935. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2936. strcat(buf,usec_buf);
  2937. #endif
  2938. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2939. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2940. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2941. // clear StartTransaction Response
  2942. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2943. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2944. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2945. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2946. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2947. if(gunType[gun_index] == 'J')
  2948. {
  2949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2950. {
  2951. tempIndex = ((gun_index==2) ? 1: 0);
  2952. }
  2953. else
  2954. {
  2955. tempIndex = gun_index;
  2956. }
  2957. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2958. {
  2959. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2960. {
  2961. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  2962. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2963. }
  2964. }
  2965. }
  2966. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2967. {
  2968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2969. {
  2970. tempIndex = ((gun_index==2) ? 1: 0);
  2971. }
  2972. else
  2973. {
  2974. tempIndex = gun_index;
  2975. }
  2976. for (int index = 0; index < CCS_QUANTITY; index++)
  2977. {
  2978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2979. {
  2980. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  2981. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2982. }
  2983. }
  2984. }
  2985. else if(gunType[gun_index] == 'G')
  2986. {
  2987. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2988. {
  2989. tempIndex = ((gun_index==2) ? 1: 0);
  2990. }
  2991. else
  2992. {
  2993. tempIndex = gun_index;
  2994. }
  2995. for (int index = 0; index < GB_QUANTITY; index++)
  2996. {
  2997. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2998. {
  2999. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  3000. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  3001. }
  3002. }
  3003. }
  3004. else
  3005. {
  3006. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3007. {
  3008. tempIndex = 2;
  3009. }
  3010. else
  3011. {
  3012. tempIndex = gun_index;
  3013. }
  3014. for (int index = 0; index < AC_QUANTITY; index++)
  3015. {
  3016. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3017. {
  3018. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3019. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3020. }
  3021. }
  3022. }
  3023. random_uuid(guid);
  3024. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3025. {
  3026. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3027. , gun_index +1
  3028. , MESSAGE_TYPE_CALL
  3029. , guid
  3030. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3031. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3032. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3033. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3034. }
  3035. else
  3036. {
  3037. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3038. , gun_index +1
  3039. , MESSAGE_TYPE_CALL
  3040. , guid
  3041. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3042. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3043. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3044. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3045. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3046. }
  3047. #if 1
  3048. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3049. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3050. {
  3051. result = PASS;
  3052. }
  3053. #endif
  3054. strcpy(queuedata, message);
  3055. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3056. if(GetTransactionQueueNum() == 1)
  3057. {
  3058. LWS_Send(message + 2);
  3059. }
  3060. return result;
  3061. }
  3062. int sendStatusNotificationRequest(int gun_index)
  3063. {
  3064. mtrace();
  3065. int result = FAIL;
  3066. char message[600]={0};
  3067. char guid[37];
  3068. int currentStatus = 0;
  3069. struct timeval tmnow;
  3070. struct tm *tm;
  3071. char buf[28];//, usec_buf[6];
  3072. char tempdata[65]={0};
  3073. int tempIndex = 0;
  3074. gettimeofday(&tmnow, NULL);
  3075. time_t t;
  3076. t = time(NULL);
  3077. /*UTC time and date*/
  3078. tm = gmtime(&t);
  3079. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3080. #if 0 // remove temporally
  3081. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3082. strcat(buf,".");
  3083. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3084. strcat(buf,usec_buf);
  3085. #endif
  3086. printf("%s",buf);
  3087. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3088. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3089. // it's option
  3090. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3091. /*
  3092. enum _SYSTEM_STATUS
  3093. {
  3094. S_BOOTING = 0,
  3095. S_IDLE, = 1
  3096. S_AUTHORIZING, =2
  3097. S_REASSIGN_CHECK, =3
  3098. S_REASSIGN, =4
  3099. S_PRECHARGE, =5
  3100. S_PREPARING_FOR_EV, =6
  3101. S_PREPARING_FOR_EVSE, =7
  3102. S_CHARGING, =8
  3103. S_TERMINATING, =9
  3104. S_COMPLETE, =10
  3105. S_ALARM, =11
  3106. S_FAULT =12
  3107. }
  3108. */
  3109. //check Transaction active
  3110. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3111. if(gunType[gun_index] == 'J')
  3112. {
  3113. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3114. {
  3115. tempIndex = ((gun_index==2) ? 1: 0);
  3116. }
  3117. else
  3118. {
  3119. tempIndex = gun_index;
  3120. }
  3121. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3122. {
  3123. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3124. {
  3125. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3126. {
  3127. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3128. {
  3129. currentStatus = 1; //OCPP Status: Preparing
  3130. }
  3131. else
  3132. {
  3133. currentStatus = 0; //OCPP Status: Available
  3134. }
  3135. }
  3136. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3137. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3138. ) //S_PRECHARGE
  3139. {
  3140. currentStatus = 1; //OCPP Status: Preparing
  3141. }
  3142. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3143. {
  3144. currentStatus = 2; //OCPP Status: Charging
  3145. }
  3146. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3147. {
  3148. currentStatus = 5; //OCPP Status: Finishing
  3149. }
  3150. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3151. {
  3152. currentStatus = 4; //OCPP Status: SuspendedEV
  3153. }
  3154. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3155. {
  3156. currentStatus = 7; //OCPP Status: Unavailable
  3157. }
  3158. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3159. {
  3160. currentStatus = 8; //OCPP Status: Faulted
  3161. }
  3162. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3163. {
  3164. currentStatus = 6; //OCPP Status: Reserved
  3165. }
  3166. } //end of the same index
  3167. }//end of for CHAdeMO_QUANTITY
  3168. }
  3169. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3170. {
  3171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3172. {
  3173. tempIndex = ((gun_index==2) ? 1: 0);
  3174. }
  3175. else
  3176. {
  3177. tempIndex = gun_index;
  3178. }
  3179. for (int index = 0; index < CCS_QUANTITY; index++)
  3180. {
  3181. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3182. {
  3183. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3184. {
  3185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3186. {
  3187. currentStatus = 1; //OCPP Status: Preparing
  3188. }
  3189. else
  3190. {
  3191. currentStatus = 0; //OCPP Status: Available
  3192. }
  3193. }
  3194. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3195. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3196. ) //S_PRECHARGE
  3197. {
  3198. currentStatus = 1; //OCPP Status: Preparing
  3199. }
  3200. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3201. {
  3202. currentStatus = 2; //OCPP Status: Charging
  3203. }
  3204. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3205. {
  3206. currentStatus = 5; //OCPP Status: Finishing
  3207. }
  3208. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3209. {
  3210. currentStatus = 4; //OCPP Status: SuspendedEV
  3211. }
  3212. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3213. {
  3214. currentStatus = 7; //OCPP Status : Unavailable
  3215. }
  3216. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3217. {
  3218. currentStatus = 8; //OCPP Status: Faulted
  3219. }
  3220. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3221. {
  3222. currentStatus = 6; //OCPP Status: Reserved
  3223. }
  3224. } //end of the same index
  3225. } // end of for CCS_QUANTITY
  3226. }
  3227. else if(gunType[gun_index] == 'G')
  3228. {
  3229. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3230. {
  3231. tempIndex = ((gun_index==2) ? 1: 0);
  3232. }
  3233. else
  3234. {
  3235. tempIndex = gun_index;
  3236. }
  3237. for (int index = 0; index < GB_QUANTITY; index++)
  3238. {
  3239. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3240. {
  3241. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3242. {
  3243. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3244. {
  3245. currentStatus = 1; //OCPP Status: Preparing
  3246. }
  3247. else
  3248. {
  3249. currentStatus = 0; //OCPP Status: Available
  3250. }
  3251. }
  3252. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3253. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3254. ) //S_PRECHARGE
  3255. {
  3256. currentStatus = 1; //OCPP Status: Preparing
  3257. }
  3258. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3259. {
  3260. currentStatus = 2; //OCPP Status: Charging
  3261. }
  3262. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3263. {
  3264. currentStatus = 5; //OCPP Status: Finishing
  3265. }
  3266. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3267. {
  3268. currentStatus = 4; //OCPP Status: SuspendedEV
  3269. }
  3270. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3271. {
  3272. currentStatus = 7; //OCPP Status: Unavailable
  3273. }
  3274. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3275. {
  3276. currentStatus = 8; //OCPP Status: Faulted
  3277. }
  3278. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3279. {
  3280. currentStatus = 6; //OCPP Status: Reserved
  3281. }
  3282. } //end of the same index
  3283. } // end of for GB_QUANTITY
  3284. }
  3285. else
  3286. {
  3287. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3288. {
  3289. tempIndex = 2;
  3290. }
  3291. else
  3292. {
  3293. tempIndex = gun_index;
  3294. }
  3295. for (int index = 0; index < AC_QUANTITY; index++)
  3296. {
  3297. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3298. {
  3299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3300. {
  3301. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_B) ||(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_C) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState == CP_STATE_D))
  3302. {
  3303. currentStatus = 1; //OCPP Status: Preparing
  3304. }
  3305. else
  3306. {
  3307. currentStatus = 0; //OCPP Status: Available
  3308. }
  3309. }
  3310. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  3311. {
  3312. currentStatus = 1; //OCPP Status: Preparing
  3313. }
  3314. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3315. {
  3316. currentStatus = 2; //OCPP Status: Charging
  3317. }
  3318. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3319. {
  3320. currentStatus = 5; //OCPP Status: Finishing
  3321. }
  3322. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3323. {
  3324. currentStatus = 4; //OCPP Status: SuspendedEV
  3325. }
  3326. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_MAINTAIN)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3327. {
  3328. currentStatus = 7; //OCPP Status: Unavailable
  3329. }
  3330. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3331. {
  3332. currentStatus = 8; //OCPP Status: Faulted
  3333. }
  3334. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3335. {
  3336. currentStatus = 6; //OCPP Status: Reserved
  3337. }
  3338. }//end of the same index
  3339. }//end of for AC_QUANTITY
  3340. }
  3341. //it's option
  3342. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3343. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3344. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3345. random_uuid(guid);
  3346. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3347. , MESSAGE_TYPE_CALL
  3348. , guid
  3349. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3350. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3351. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3352. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3353. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3354. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3355. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3356. LWS_Send(message);
  3357. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3358. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3359. {
  3360. //DEBUG_ERROR("statusNotification mapitem pass");
  3361. result = PASS;
  3362. }
  3363. return result;
  3364. }
  3365. int sendStopTransactionRequest(int gun_index)
  3366. {
  3367. mtrace();
  3368. int result = FAIL;
  3369. //char message[1500]={0};
  3370. char guid[37]={0};
  3371. char tempdata[65]={0};
  3372. int tempIndex = 0;
  3373. //int idx_sample=0;
  3374. DEBUG_ERROR("sendStopTransactionRequest \n");
  3375. memset(queuedata, 0, sizeof(queuedata));
  3376. //ENERGY_ACTIVE_IMPORT_REGISTER
  3377. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3378. if(gunType[gun_index] == 'J')
  3379. {
  3380. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3381. {
  3382. tempIndex = ((gun_index==2) ? 1: 0);
  3383. }
  3384. else
  3385. {
  3386. tempIndex = gun_index;
  3387. }
  3388. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3389. {
  3390. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3391. {
  3392. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  3393. }
  3394. }// END OF CHAdeMO_QUANTITY
  3395. }
  3396. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3397. {
  3398. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3399. {
  3400. tempIndex = ((gun_index==2) ? 1: 0);
  3401. }
  3402. else
  3403. {
  3404. tempIndex = gun_index;
  3405. }
  3406. for (int index = 0; index < CCS_QUANTITY; index++)
  3407. {
  3408. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3409. {
  3410. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  3411. }
  3412. }// END OF CCS_QUANTITY
  3413. }
  3414. else if(gunType[gun_index] == 'G')
  3415. {
  3416. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3417. {
  3418. tempIndex = ((gun_index==2) ? 1: 0);
  3419. }
  3420. else
  3421. {
  3422. tempIndex = gun_index;
  3423. }
  3424. for (int index = 0; index < GB_QUANTITY; index++)
  3425. {
  3426. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3427. {
  3428. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  3429. }
  3430. }// END OF GB_QUANTITY
  3431. }
  3432. else
  3433. {
  3434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3435. {
  3436. tempIndex = 2;
  3437. }
  3438. else
  3439. {
  3440. tempIndex = gun_index;
  3441. }
  3442. for (int index = 0; index < AC_QUANTITY; index++)
  3443. {
  3444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3445. {
  3446. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  3447. }
  3448. }// END OF AC_QUANTITY
  3449. }
  3450. //Stop Transaction Time
  3451. struct timeval tmnow;
  3452. struct tm *tm;
  3453. char buf[28];//, usec_buf[6];
  3454. gettimeofday(&tmnow, NULL);
  3455. time_t t;
  3456. t = time(NULL);
  3457. /*UTC time and date*/
  3458. tm = gmtime(&t);
  3459. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3461. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3462. random_uuid(guid);
  3463. /***********************************transactionData******************************************************/
  3464. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3465. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3466. //=================================
  3467. // Transaction_Begin
  3468. //=================================
  3469. // Energy.Active.Export.Interval
  3470. //idx_sample=0;
  3471. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  3472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  3475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3476. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3477. {
  3478. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3479. }
  3480. else
  3481. {
  3482. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3483. }
  3484. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3486. //=================================
  3487. // Transaction_End
  3488. //=================================
  3489. //Current.Export
  3490. //idx_sample=1;
  3491. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3492. if(gunType[gun_index] == 'J')
  3493. {
  3494. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3495. {
  3496. tempIndex = ((gun_index==2) ? 1: 0);
  3497. }
  3498. else
  3499. {
  3500. tempIndex = gun_index;
  3501. }
  3502. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3503. {
  3504. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3505. {
  3506. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3507. }
  3508. }// End of for CHAdeMO_QUANTITY
  3509. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3510. }
  3511. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3512. {
  3513. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3514. {
  3515. tempIndex = ((gun_index==2) ? 1: 0);
  3516. }
  3517. else
  3518. {
  3519. tempIndex = gun_index;
  3520. }
  3521. for (int index = 0; index < CCS_QUANTITY; index++)
  3522. {
  3523. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3524. {
  3525. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3526. }
  3527. }// End of for CCS_QUANTITY
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3529. }
  3530. else if(gunType[gun_index] == 'G')
  3531. {
  3532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3533. {
  3534. tempIndex = ((gun_index==2) ? 1: 0);
  3535. }
  3536. else
  3537. {
  3538. tempIndex = gun_index;
  3539. }
  3540. for (int index = 0; index < GB_QUANTITY; index++)
  3541. {
  3542. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3543. {
  3544. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3545. }
  3546. }// End of for GB_QUANTITY
  3547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3548. }
  3549. else
  3550. {
  3551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3552. {
  3553. tempIndex = 2;
  3554. }
  3555. else
  3556. {
  3557. tempIndex = gun_index;
  3558. }
  3559. for (int index = 0; index < AC_QUANTITY; index++)
  3560. {
  3561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3562. {
  3563. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3564. }
  3565. }// End of for AC_QUANTITY
  3566. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3567. }
  3568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3571. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3572. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3573. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3574. //Energy.Active.Export.Interval
  3575. //idx_sample=2;
  3576. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3577. if(gunType[gun_index] == 'J')
  3578. {
  3579. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3580. {
  3581. tempIndex = ((gun_index==2) ? 1: 0);
  3582. }
  3583. else
  3584. {
  3585. tempIndex = gun_index;
  3586. }
  3587. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3588. {
  3589. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3590. {
  3591. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3592. }
  3593. }// END OF CHAdeMO_QUANTITY
  3594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3595. }
  3596. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3597. {
  3598. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3599. {
  3600. tempIndex = ((gun_index==2) ? 1: 0);
  3601. }
  3602. else
  3603. {
  3604. tempIndex = gun_index;
  3605. }
  3606. for (int index = 0; index < CCS_QUANTITY; index++)
  3607. {
  3608. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3609. {
  3610. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3611. }
  3612. }// END OF CCS_QUANTITY
  3613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3614. }
  3615. else if(gunType[gun_index] == 'G')
  3616. {
  3617. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3618. {
  3619. tempIndex = ((gun_index==2) ? 1: 0);
  3620. }
  3621. else
  3622. {
  3623. tempIndex = gun_index;
  3624. }
  3625. for (int index = 0; index < GB_QUANTITY; index++)
  3626. {
  3627. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3628. {
  3629. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3630. }
  3631. }// END OF GB_QUANTITY
  3632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3633. }
  3634. else
  3635. {
  3636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3637. {
  3638. tempIndex = 2;
  3639. }
  3640. else
  3641. {
  3642. tempIndex = gun_index;
  3643. }
  3644. for (int index = 0; index < AC_QUANTITY; index++)
  3645. {
  3646. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3647. {
  3648. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3649. }
  3650. }// END OF AC_QUANTITY
  3651. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3652. }
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3656. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3659. //Power.Active.Export
  3660. //idx_sample=3;
  3661. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3662. if(gunType[gun_index] == 'J')
  3663. {
  3664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3665. {
  3666. tempIndex = ((gun_index==2) ? 1: 0);
  3667. }
  3668. else
  3669. {
  3670. tempIndex = gun_index;
  3671. }
  3672. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3673. {
  3674. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3675. {
  3676. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3677. }
  3678. } // End for CHAdeMO_QUANTITY
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3680. }
  3681. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3682. {
  3683. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3684. {
  3685. tempIndex = ((gun_index==2) ? 1: 0);
  3686. }
  3687. else
  3688. {
  3689. tempIndex = gun_index;
  3690. }
  3691. for (int index = 0; index < CCS_QUANTITY; index++)
  3692. {
  3693. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3694. {
  3695. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3696. }
  3697. } // END for CCS_QUANTITY
  3698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3699. }
  3700. else if(gunType[gun_index] == 'G')
  3701. {
  3702. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3703. {
  3704. tempIndex = ((gun_index==2) ? 1: 0);
  3705. }
  3706. else
  3707. {
  3708. tempIndex = gun_index;
  3709. }
  3710. for (int index = 0; index < GB_QUANTITY; index++)
  3711. {
  3712. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3713. {
  3714. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3715. }
  3716. }// END for GB_QUANTITY
  3717. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3718. }
  3719. else
  3720. {
  3721. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3722. {
  3723. tempIndex = 2;
  3724. }
  3725. else
  3726. {
  3727. tempIndex = gun_index;
  3728. }
  3729. for (int index = 0; index < AC_QUANTITY; index++)
  3730. {
  3731. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3732. {
  3733. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3734. }
  3735. } // END for AC_QUANTITY
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3737. }
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3741. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3744. //Voltage
  3745. //idx_sample=4;
  3746. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3747. if(gunType[gun_index] == 'J')
  3748. {
  3749. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3750. {
  3751. tempIndex = ((gun_index==2) ? 1: 0);
  3752. }
  3753. else
  3754. {
  3755. tempIndex = gun_index;
  3756. }
  3757. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3758. {
  3759. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3760. {
  3761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3762. }
  3763. } // END OF FOR CHAdeMO_QUANTITY
  3764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3765. }
  3766. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3767. {
  3768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3769. {
  3770. tempIndex = ((gun_index==2) ? 1: 0);
  3771. }
  3772. else
  3773. {
  3774. tempIndex = gun_index;
  3775. }
  3776. for (int index = 0; index < CCS_QUANTITY; index++)
  3777. {
  3778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3779. {
  3780. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3781. }
  3782. } // END OF FOR CCS_QUANTITY
  3783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3784. }
  3785. else if(gunType[gun_index] == 'G')
  3786. {
  3787. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3788. {
  3789. tempIndex = ((gun_index==2) ? 1: 0);
  3790. }
  3791. else
  3792. {
  3793. tempIndex = gun_index;
  3794. }
  3795. for (int index = 0; index < GB_QUANTITY; index++)
  3796. {
  3797. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3798. {
  3799. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3800. }
  3801. } // END OF FOR GB_QUANTITY
  3802. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3803. }
  3804. else
  3805. {
  3806. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3807. {
  3808. tempIndex = 2;
  3809. }
  3810. else
  3811. {
  3812. tempIndex = gun_index;
  3813. }
  3814. for (int index = 0; index < AC_QUANTITY; index++)
  3815. {
  3816. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3817. {
  3818. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3819. }
  3820. } // END OF FOR AC_QUANTITY
  3821. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3822. }
  3823. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3826. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3829. //SoC
  3830. //idx_sample=5;
  3831. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3832. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3835. {
  3836. tempIndex = ((gun_index==2) ? 1: 0);
  3837. }
  3838. else
  3839. {
  3840. tempIndex = gun_index;
  3841. }
  3842. if(gunType[gun_index] == 'J')
  3843. {
  3844. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3845. {
  3846. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3847. {
  3848. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3849. }
  3850. }
  3851. }
  3852. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3853. {
  3854. for (int index = 0; index < CCS_QUANTITY; index++)
  3855. {
  3856. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3857. {
  3858. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3859. }
  3860. }
  3861. }
  3862. else if(gunType[gun_index] == 'G')
  3863. {
  3864. for (int index = 0; index < GB_QUANTITY; index++)
  3865. {
  3866. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3867. {
  3868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3869. }
  3870. }
  3871. }
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3878. } // END FOR DC CASE
  3879. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3880. {
  3881. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3882. ,gun_index+1
  3883. ,MESSAGE_TYPE_CALL
  3884. ,guid
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3890. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3926. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3933. );
  3934. }
  3935. else
  3936. {
  3937. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3938. ,gun_index+1
  3939. ,MESSAGE_TYPE_CALL
  3940. ,guid
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3946. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3962. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3963. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3964. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3965. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3966. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3967. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3968. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3969. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3975. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3982. );
  3983. }
  3984. #if 1 // for TempStopTransaction
  3985. //Delete TempStopTransaction
  3986. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  3987. {
  3988. remove("/Storage/OCPP/TempStopTransaction"); // remove file "TempStopTransaction"
  3989. }
  3990. #endif
  3991. #if 1
  3992. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  3993. if(hashmap_operation(0, guid, tempdata) == 1)
  3994. {
  3995. result = PASS;
  3996. DEBUG_INFO("StopTransaction mapitem pass\n");
  3997. }
  3998. #endif
  3999. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4000. if(GetTransactionQueueNum() == 1)
  4001. {
  4002. LWS_Send(queuedata+2);
  4003. }
  4004. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4005. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4006. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  4007. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4008. {
  4009. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4010. }
  4011. //for test
  4012. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4013. return result;
  4014. }
  4015. int sendMeterValuesRequest(int gun_index)
  4016. {
  4017. mtrace();
  4018. int result = FAIL;
  4019. // char message[1500]={0};
  4020. char guid[37]={0};
  4021. //int idx_sample=0;
  4022. //int length = 0;
  4023. char tempdata[65]={0};
  4024. int tempIndex = 0;
  4025. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4026. //DEBUG_ERROR("gun_index =%d\n",gun_index);
  4027. if((ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == 0)&&(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 0)) // no TransactionId
  4028. {
  4029. DEBUG_INFO("NOT SENT METER Vlaue\n");
  4030. //DEBUG_ERROR("ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId =%d\n",ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  4031. //DEBUG_ERROR("ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq =%d\n",ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq);
  4032. return result;
  4033. }
  4034. if(ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq == 1)
  4035. {
  4036. ShmOCPP16Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  4037. }
  4038. memset(queuedata, 0, sizeof(queuedata));
  4039. //set value
  4040. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4041. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  4042. random_uuid(guid);
  4043. //UTC Date time
  4044. struct timeval tmnow;
  4045. struct tm *tm;
  4046. char buf[28];//, usec_buf[6];
  4047. gettimeofday(&tmnow, NULL);
  4048. time_t t;
  4049. t = time(NULL);
  4050. /*UTC time and date*/
  4051. tm = gmtime(&t);
  4052. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4053. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4054. DEBUG_INFO( "ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4055. //idx_sample=0;
  4056. //********************************(1)Current.Export************************************************/
  4057. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4058. if(gunType[gun_index] == 'J')
  4059. {
  4060. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4061. {
  4062. tempIndex = ((gun_index==2) ? 1: 0);
  4063. }
  4064. else
  4065. {
  4066. tempIndex = gun_index;
  4067. }
  4068. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4069. {
  4070. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4071. {
  4072. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4073. }
  4074. }
  4075. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4076. }
  4077. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4078. {
  4079. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4080. {
  4081. tempIndex = ((gun_index==2) ? 1: 0);
  4082. }
  4083. else
  4084. {
  4085. tempIndex = gun_index;
  4086. }
  4087. for (int index = 0; index < CCS_QUANTITY; index++)
  4088. {
  4089. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4090. {
  4091. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4092. }
  4093. }
  4094. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4095. }
  4096. else if(gunType[gun_index] == 'G')
  4097. {
  4098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4099. {
  4100. tempIndex = ((gun_index==2) ? 1: 0);
  4101. }
  4102. else
  4103. {
  4104. tempIndex = gun_index;
  4105. }
  4106. for (int index = 0; index < GB_QUANTITY; index++)
  4107. {
  4108. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4109. {
  4110. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4111. }
  4112. }
  4113. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4114. }
  4115. else
  4116. {
  4117. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4118. {
  4119. tempIndex = 2;
  4120. }
  4121. else
  4122. {
  4123. tempIndex = gun_index;
  4124. }
  4125. for (int index = 0; index < AC_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4130. }
  4131. }
  4132. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4133. }
  4134. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4135. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4136. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4137. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4138. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4139. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4140. //idx_sample=1;
  4141. //********************************(2)Energy.Active.Import.Register ************************************************/
  4142. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4143. if(gunType[gun_index] == 'J')
  4144. {
  4145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4146. {
  4147. tempIndex = ((gun_index==2) ? 1: 0);
  4148. }
  4149. else
  4150. {
  4151. tempIndex = gun_index;
  4152. }
  4153. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4154. {
  4155. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4156. {
  4157. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4158. }
  4159. }
  4160. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4161. }
  4162. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4163. {
  4164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4165. {
  4166. tempIndex = ((gun_index==2) ? 1: 0);
  4167. }
  4168. else
  4169. {
  4170. tempIndex = gun_index;
  4171. }
  4172. for (int index = 0; index < CCS_QUANTITY; index++)
  4173. {
  4174. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4175. {
  4176. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4177. }
  4178. }
  4179. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4180. }
  4181. else if(gunType[gun_index] == 'G')
  4182. {
  4183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4184. {
  4185. tempIndex = ((gun_index==2) ? 1: 0);
  4186. }
  4187. else
  4188. {
  4189. tempIndex = gun_index;
  4190. }
  4191. for (int index = 0; index < GB_QUANTITY; index++)
  4192. {
  4193. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4194. {
  4195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4196. }
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4199. }
  4200. else
  4201. {
  4202. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4203. {
  4204. tempIndex = 2;
  4205. }
  4206. else
  4207. {
  4208. tempIndex = gun_index;
  4209. }
  4210. for (int index = 0; index < AC_QUANTITY; index++)
  4211. {
  4212. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4213. {
  4214. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4215. }
  4216. }
  4217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4218. }
  4219. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4220. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4221. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4222. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4223. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4224. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4225. //idx_sample=2;
  4226. //****************************************************(3)Energy.Active.Export.Interval*********************************************/
  4227. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4228. if(gunType[gun_index] == 'J')
  4229. {
  4230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4231. {
  4232. tempIndex = ((gun_index==2) ? 1: 0);
  4233. }
  4234. else
  4235. {
  4236. tempIndex = gun_index;
  4237. }
  4238. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4239. {
  4240. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4241. {
  4242. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4243. }
  4244. } // END OF FOR CHAdeMO_QUANTITY
  4245. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4246. }
  4247. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4248. {
  4249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4250. {
  4251. tempIndex = ((gun_index==2) ? 1: 0);
  4252. }
  4253. else
  4254. {
  4255. tempIndex = gun_index;
  4256. }
  4257. for (int index = 0; index < CCS_QUANTITY; index++)
  4258. {
  4259. // printf("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].Index=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index );
  4260. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4261. {
  4262. //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy = 100.0;
  4263. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4264. }
  4265. } // END OF CCS_QUANTITY
  4266. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4267. }
  4268. else if(gunType[gun_index] == 'G')
  4269. {
  4270. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4271. {
  4272. tempIndex = ((gun_index==2) ? 1: 0);
  4273. }
  4274. else
  4275. {
  4276. tempIndex = gun_index;
  4277. }
  4278. for (int index = 0; index < GB_QUANTITY; index++)
  4279. {
  4280. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4281. {
  4282. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4283. }
  4284. } // END OF GB_QUANTITY
  4285. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4286. }
  4287. else
  4288. {
  4289. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4290. {
  4291. tempIndex = 2;
  4292. }
  4293. else
  4294. {
  4295. tempIndex = gun_index;
  4296. }
  4297. for (int index = 0; index < AC_QUANTITY; index++)
  4298. {
  4299. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4300. {
  4301. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4302. }
  4303. }
  4304. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4305. }
  4306. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4307. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4308. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4309. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4310. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4311. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4312. //idx_sample=3;
  4313. //********************************(4)Power.Active.Export************************************************/
  4314. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4315. if(gunType[gun_index] == 'J')
  4316. {
  4317. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4318. {
  4319. tempIndex = ((gun_index==2) ? 1: 0);
  4320. }
  4321. else
  4322. {
  4323. tempIndex = gun_index;
  4324. }
  4325. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4326. {
  4327. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4328. {
  4329. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4330. }
  4331. } // END OF FOR
  4332. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4333. }
  4334. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4335. {
  4336. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4337. {
  4338. tempIndex = ((gun_index==2) ? 1: 0);
  4339. }
  4340. else
  4341. {
  4342. tempIndex = gun_index;
  4343. }
  4344. for (int index = 0; index < CCS_QUANTITY; index++)
  4345. {
  4346. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4347. {
  4348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4349. }
  4350. }
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4352. }
  4353. else if(gunType[gun_index] == 'G')
  4354. {
  4355. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4356. {
  4357. tempIndex = ((gun_index==2) ? 1: 0);
  4358. }
  4359. else
  4360. {
  4361. tempIndex = gun_index;
  4362. }
  4363. for (int index = 0; index < GB_QUANTITY; index++)
  4364. {
  4365. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4366. {
  4367. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4368. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4369. }
  4370. }
  4371. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4372. }
  4373. else
  4374. {
  4375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4376. {
  4377. tempIndex = 2;
  4378. }
  4379. else
  4380. {
  4381. tempIndex = gun_index;
  4382. }
  4383. for (int index = 0; index < AC_QUANTITY; index++)
  4384. {
  4385. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4386. {
  4387. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4388. }
  4389. }
  4390. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4391. }
  4392. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4394. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4395. //strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4396. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4398. //idx_sample=4;
  4399. //***********************************************(5)VOLTAGE******************************************************/
  4400. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4401. if(gunType[gun_index] == 'J')
  4402. {
  4403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4404. {
  4405. tempIndex = ((gun_index==2) ? 1: 0);
  4406. }
  4407. else
  4408. {
  4409. tempIndex = gun_index;
  4410. }
  4411. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4412. {
  4413. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4414. {
  4415. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4416. }
  4417. }
  4418. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4419. }
  4420. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4421. {
  4422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4423. {
  4424. tempIndex = ((gun_index==2) ? 1: 0);
  4425. }
  4426. else
  4427. {
  4428. tempIndex = gun_index;
  4429. }
  4430. for (int index = 0; index < CCS_QUANTITY; index++)
  4431. {
  4432. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4433. {
  4434. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4435. }
  4436. }
  4437. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4438. }
  4439. else if(gunType[gun_index] == 'G')
  4440. {
  4441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4442. {
  4443. tempIndex = ((gun_index==2) ? 1: 0);
  4444. }
  4445. else
  4446. {
  4447. tempIndex = gun_index;
  4448. }
  4449. for (int index = 0; index < GB_QUANTITY; index++)
  4450. {
  4451. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4452. {
  4453. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4454. }
  4455. }
  4456. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4457. }
  4458. else
  4459. {
  4460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4461. {
  4462. tempIndex = 2;
  4463. }
  4464. else
  4465. {
  4466. tempIndex = gun_index;
  4467. }
  4468. for (int index = 0; index < AC_QUANTITY; index++)
  4469. {
  4470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4471. {
  4472. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4473. }
  4474. }
  4475. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4476. }
  4477. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4478. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4479. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4480. // strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4481. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4482. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4483. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4484. {
  4485. //idx_sample=5;
  4486. //sampledValue = NULL;
  4487. //***********************************************(6)SOC******************************************************/
  4488. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4489. {
  4490. tempIndex = ((gun_index==2) ? 1: 0);
  4491. }
  4492. else
  4493. {
  4494. tempIndex = gun_index;
  4495. }
  4496. if(gunType[gun_index] == 'J')
  4497. {
  4498. //tempIndex = ((gun_index==2) ? 1: 0);
  4499. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4500. {
  4501. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4502. {
  4503. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4504. }
  4505. }
  4506. }
  4507. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4508. {
  4509. //tempIndex = ((gun_index==2) ? 1: 0);
  4510. for (int index = 0; index < CCS_QUANTITY; index++)
  4511. {
  4512. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4513. {
  4514. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4515. }
  4516. }
  4517. }
  4518. else if(gunType[gun_index] == 'G')
  4519. {
  4520. //tempIndex = ((gun_index==2) ? 1: 0);
  4521. for (int index = 0; index < GB_QUANTITY; index++)
  4522. {
  4523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4524. {
  4525. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4526. }
  4527. }
  4528. }
  4529. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4530. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4532. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4533. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4534. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4535. }
  4536. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4537. {
  4538. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4539. ,gun_index + 1
  4540. ,MESSAGE_TYPE_CALL
  4541. ,guid
  4542. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4543. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4544. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4545. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4546. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4547. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4548. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4549. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4550. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4551. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4552. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4553. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4554. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4555. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4556. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4557. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4558. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4559. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4560. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4561. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4562. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4563. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4564. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4565. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4566. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4567. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4568. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4569. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4570. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4571. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4572. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4573. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4574. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4575. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4576. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4577. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4578. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4579. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4580. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4581. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4582. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4583. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4584. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4585. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4586. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4587. );
  4588. }
  4589. else
  4590. {
  4591. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4592. ,gun_index + 1
  4593. ,MESSAGE_TYPE_CALL
  4594. ,guid
  4595. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4596. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4597. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4598. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4599. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4600. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4601. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4602. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4603. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4604. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4605. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4606. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4607. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4608. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4609. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4610. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4611. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4612. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4613. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4614. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4615. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4616. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4617. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4618. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4619. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4620. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4621. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4622. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4623. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4624. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4625. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4626. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4627. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4628. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4629. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4630. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4631. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4632. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4633. );
  4634. }
  4635. // Put request guid to hash map
  4636. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4637. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4638. {
  4639. result = PASS;
  4640. DEBUG_INFO("MeterValues mapitem pass\n");
  4641. }
  4642. queue_operation(4, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4643. if(GetTransactionQueueNum() == 1)
  4644. {
  4645. LWS_Send(queuedata +2);
  4646. }
  4647. return result;
  4648. }
  4649. //==========================================
  4650. // send confirm routine
  4651. //==========================================
  4652. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4653. {
  4654. mtrace();
  4655. int result = FAIL;
  4656. char message[100]={0};
  4657. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4658. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4659. LWS_Send(message);
  4660. result = TRUE;
  4661. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4662. return result;
  4663. }
  4664. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4665. {
  4666. mtrace();
  4667. int result = FAIL;
  4668. char message[100]={0};
  4669. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4670. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4671. LWS_Send(message);
  4672. result = TRUE;
  4673. return result;
  4674. }
  4675. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4676. {
  4677. mtrace();
  4678. int result = FAIL;
  4679. char message[100]={0};
  4680. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4681. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4682. LWS_Send(message);
  4683. result = TRUE;
  4684. return result;
  4685. }
  4686. int sendClearCacheConfirmation(char *uuid,char *payload)
  4687. {
  4688. mtrace();
  4689. int result = FAIL;
  4690. char message[500]={0};
  4691. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4692. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4693. LWS_Send(message);
  4694. return result;
  4695. }
  4696. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4697. {
  4698. mtrace();
  4699. int result = FAIL;
  4700. char message[500]={0};
  4701. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4702. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4703. LWS_Send(message);
  4704. return result;
  4705. }
  4706. int sendDataTransferConfirmation(char *uuid,char *payload)
  4707. {
  4708. mtrace();
  4709. char statusStr[20]={0};
  4710. char dataStr[10]={0};
  4711. char sstr[20]={0};
  4712. int c = 0;
  4713. char *loc;
  4714. int result = FAIL;
  4715. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4716. /**********************status**************************/
  4717. loc = strstr(payload, "status");
  4718. memset(sstr ,0, sizeof(sstr) );
  4719. c = 0;
  4720. while (loc[3+strlen("status")+c] != '\"')
  4721. {
  4722. sstr[c] = loc[3+strlen("status")+c];
  4723. c++;
  4724. }
  4725. sstr[c] = '\0';
  4726. strcpy(statusStr, sstr);
  4727. /**********************data**************************/
  4728. loc = strstr(payload, "data");
  4729. memset(sstr ,0, sizeof(sstr) );
  4730. c = 0;
  4731. while (loc[3+strlen("data")+c] != '\"')
  4732. {
  4733. sstr[c] = loc[3+strlen("data")+c];
  4734. c++;
  4735. }
  4736. sstr[c] = '\0';
  4737. strcpy(dataStr, sstr);
  4738. return result;
  4739. }
  4740. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4741. {
  4742. mtrace();
  4743. int result = FAIL;
  4744. char message[1000]={0};
  4745. int CompositeScheduleIndex = 0;
  4746. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4747. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4748. if(nPeriod == 0)
  4749. {
  4750. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4751. {
  4752. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4753. ,MESSAGE_TYPE_CALLRESULT
  4754. ,uuid
  4755. ,payload
  4756. ,connectorIdInt);
  4757. }
  4758. else
  4759. {
  4760. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":0,\"numberPhases\":3}]}}]"
  4761. ,MESSAGE_TYPE_CALLRESULT
  4762. ,uuid
  4763. ,payload
  4764. ,connectorIdInt
  4765. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4766. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4767. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4768. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4769. }
  4770. }
  4771. else
  4772. {
  4773. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4774. ,MESSAGE_TYPE_CALLRESULT
  4775. ,uuid
  4776. ,payload
  4777. ,connectorIdInt
  4778. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4779. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4780. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4781. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4782. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4783. {
  4784. if (idx_sample == 0)
  4785. {
  4786. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4787. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4788. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4789. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4790. }
  4791. else
  4792. {
  4793. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4794. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  4795. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  4796. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  4797. }
  4798. }
  4799. sprintf(message + strlen(message), "]}}]");
  4800. }
  4801. LWS_Send(message);
  4802. result = TRUE;
  4803. return result;
  4804. }
  4805. int sendGetConfigurationConfirmation(char *uuid)
  4806. {
  4807. mtrace();
  4808. int result = FAIL;
  4809. int MaxKeySupported = 0;
  4810. int sentConfigurationNumber= 0;
  4811. int sentunConfigurationNumber= 0;
  4812. char message[4000]={0};
  4813. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  4814. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  4815. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  4816. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  4817. ,MESSAGE_TYPE_CALLRESULT
  4818. ,uuid );
  4819. //configuration key
  4820. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  4821. {
  4822. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  4823. {
  4824. if (sentConfigurationNumber == 0)
  4825. {
  4826. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4827. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4828. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4829. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4830. }
  4831. else
  4832. {
  4833. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  4834. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  4835. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  4836. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  4837. }
  4838. sentConfigurationNumber = sentConfigurationNumber + 1;
  4839. }
  4840. }
  4841. sprintf(message + strlen(message), "]");
  4842. if(UnknownKeynum != 0)
  4843. {
  4844. sprintf(message + strlen(message), ",\"unknownKey\":[");
  4845. //unkown key
  4846. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  4847. {
  4848. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  4849. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  4850. if(sentunConfigurationNumber == 0)
  4851. {
  4852. sprintf(message + strlen(message), "\"%s\""
  4853. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4854. }
  4855. else
  4856. {
  4857. sprintf(message + strlen(message), ",\"%s\""
  4858. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  4859. }
  4860. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  4861. }
  4862. sprintf(message + strlen(message), "]");
  4863. }
  4864. sprintf(message + strlen(message), "}]");
  4865. LWS_Send(message);
  4866. return result;
  4867. }
  4868. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  4869. {
  4870. mtrace();
  4871. int result = FAIL;
  4872. char message[400]={0};
  4873. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  4874. if(strcmp(payload,"")==0)
  4875. {
  4876. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4877. }
  4878. else
  4879. {
  4880. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4881. }
  4882. LWS_Send(message);
  4883. result = TRUE;
  4884. return result;
  4885. }
  4886. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  4887. {
  4888. mtrace();
  4889. int result = FAIL;
  4890. char message[80]={0};
  4891. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  4892. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  4893. LWS_Send(message);
  4894. result = TRUE;
  4895. return result;
  4896. }
  4897. int sendRemoteStartConfirmation(char *uuid,char *payload)
  4898. {
  4899. mtrace();
  4900. int result = FAIL;
  4901. char message[80]={0};
  4902. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  4903. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4904. LWS_Send(message);
  4905. result = TRUE;
  4906. return result;
  4907. }
  4908. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  4909. {
  4910. mtrace();
  4911. int result = FAIL;
  4912. char message[80]={0};
  4913. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  4914. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4915. LWS_Send(message);
  4916. result = TRUE;
  4917. return result;
  4918. }
  4919. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  4920. {
  4921. mtrace();
  4922. int result = FAIL;
  4923. char message[80]={0};
  4924. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  4925. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  4926. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4927. LWS_Send(message);
  4928. result = TRUE;
  4929. return result;
  4930. }
  4931. int sendResetConfirmation(char *uuid,char *payload)
  4932. {
  4933. mtrace();
  4934. int result = FAIL;
  4935. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  4936. char message[80]={0};
  4937. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  4938. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4939. LWS_Send(message);
  4940. result = TRUE;
  4941. return result;
  4942. }
  4943. int sendSendLocalListConfirmation(char *uuid,char *payload)
  4944. {
  4945. mtrace();
  4946. int result = FAIL;
  4947. char message[500]={0};
  4948. // [ 3, "1571284266109", { "status": "Accepted" } ]
  4949. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4950. LWS_Send(message);
  4951. result = TRUE;
  4952. return result;
  4953. }
  4954. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  4955. {
  4956. mtrace();
  4957. int result = FAIL;
  4958. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  4959. char message[80]={0};
  4960. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  4961. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4962. LWS_Send(message);
  4963. result = TRUE;
  4964. return result;
  4965. }
  4966. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  4967. {
  4968. mtrace();
  4969. int result = FAIL;
  4970. char message[80]={0};
  4971. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  4972. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4973. LWS_Send(message);
  4974. result = TRUE;
  4975. return result;
  4976. }
  4977. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  4978. {
  4979. mtrace();
  4980. int result = FAIL;
  4981. char message[80]={0};
  4982. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4983. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  4984. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  4985. LWS_Send(message);
  4986. result = TRUE;
  4987. return result;
  4988. }
  4989. int sendUpdateFirmwareConfirmation(char *uuid)
  4990. {
  4991. mtrace();
  4992. int result = FAIL;
  4993. char message[60]={0};
  4994. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  4995. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  4996. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  4997. LWS_Send(message);
  4998. result = TRUE;
  4999. return result;
  5000. }
  5001. //==========================================
  5002. // send CallError routine
  5003. //==========================================
  5004. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5005. {
  5006. mtrace();
  5007. char message[220]={0};
  5008. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5009. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5010. LWS_Send(message);
  5011. }
  5012. //==========================================
  5013. // Handle server request routine Start
  5014. //==========================================
  5015. int handleCancelReservationRequest(char *uuid, char *payload)
  5016. {
  5017. mtrace();
  5018. int result = FAIL;
  5019. int gunNO = 0;
  5020. int reservationIdInt =0;
  5021. char comfirmstr[20];
  5022. DEBUG_INFO("handleCancelReservationRequest...\n");
  5023. json_object *CancelReservation;
  5024. CancelReservation = json_tokener_parse(payload);
  5025. if(!is_error(CancelReservation))
  5026. {
  5027. // Required data
  5028. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5029. }
  5030. json_object_put(CancelReservation);
  5031. memset(comfirmstr, 0, sizeof comfirmstr);
  5032. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5033. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5034. //check Transaction active
  5035. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5036. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5037. {
  5038. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5039. {
  5040. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5041. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5042. if(gunType[2] == 'J')
  5043. {
  5044. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5045. }
  5046. else
  5047. {
  5048. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5049. }
  5050. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5051. goto end;
  5052. }
  5053. }
  5054. for (int index = 0; index < CCS_QUANTITY; index++)
  5055. {
  5056. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5057. {
  5058. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5059. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5060. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5061. {
  5062. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5063. }
  5064. else
  5065. {
  5066. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5067. }
  5068. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5069. goto end;
  5070. }
  5071. }
  5072. for (int index = 0; index < GB_QUANTITY; index++)
  5073. {
  5074. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5075. {
  5076. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5077. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5078. if(gunType[2] == 'G')
  5079. {
  5080. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5081. }
  5082. else
  5083. {
  5084. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5085. }
  5086. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5087. goto end;
  5088. }
  5089. }
  5090. for (int index = 0; index < AC_QUANTITY; index++)
  5091. {
  5092. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5093. {
  5094. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5095. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5096. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5097. {
  5098. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5099. }
  5100. else
  5101. {
  5102. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5103. }
  5104. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5105. goto end;
  5106. }
  5107. }
  5108. //The reservationId does NOT match the reservationId
  5109. sendCancelReservationConfirmation(uuid, comfirmstr);
  5110. end:
  5111. // Fill in ocpp packet uuid
  5112. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5113. return result;
  5114. }
  5115. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5116. {
  5117. mtrace();
  5118. int result = FAIL;
  5119. int gunIndex = 0;
  5120. char typeStr[16]={0};
  5121. char comfirmstr[20];
  5122. int specificId = FALSE;
  5123. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5124. json_object *ChangeAvailability;
  5125. ChangeAvailability = json_tokener_parse(payload);
  5126. if(!is_error(ChangeAvailability))
  5127. {
  5128. // Required data
  5129. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5130. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5131. }
  5132. json_object_put(ChangeAvailability);
  5133. if(gunIndex != 0)
  5134. {
  5135. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5136. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5137. }
  5138. else
  5139. {
  5140. for(int i=0; i < gunTotalNumber; i++)
  5141. {
  5142. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5143. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5144. }
  5145. }
  5146. memset(comfirmstr, 0, sizeof comfirmstr);
  5147. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5148. if((gunIndex == 0) || ((gunIndex - 1) < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/))
  5149. {
  5150. specificId = TRUE;
  5151. }
  5152. if(specificId == FALSE)
  5153. goto end;
  5154. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5155. {
  5156. //----------------------gunIndex is 0 ------------------------------------------------//
  5157. if(gunIndex == 0)
  5158. {
  5159. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5160. {
  5161. for(int i=0; i < gunTotalNumber; i++)
  5162. {
  5163. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5164. {
  5165. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5166. {
  5167. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5168. {
  5169. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5170. goto end;
  5171. }
  5172. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5173. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5174. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5175. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5176. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5177. {
  5178. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5179. goto end;
  5180. }
  5181. }
  5182. }//END FOR CHAdeMO_QUANTITY
  5183. for (int index = 0; index < CCS_QUANTITY; index++)
  5184. {
  5185. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5186. {
  5187. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5188. {
  5189. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5190. goto end;
  5191. }
  5192. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5193. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5194. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5195. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5196. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5197. {
  5198. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5199. goto end;
  5200. }
  5201. }
  5202. }//END FOR CCS_QUANTITY
  5203. for (int index = 0; index < GB_QUANTITY; index++)
  5204. {
  5205. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5206. {
  5207. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5208. {
  5209. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5210. goto end;
  5211. }
  5212. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5213. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5214. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5215. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5216. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5217. {
  5218. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5219. goto end;
  5220. }
  5221. }
  5222. }// END FOR GB_QUANTITY
  5223. for (int index = 0; index < AC_QUANTITY; index++)
  5224. {
  5225. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5226. {
  5227. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5228. {
  5229. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5230. goto end;
  5231. }
  5232. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5233. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5234. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5235. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5236. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5237. {
  5238. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5239. goto end;
  5240. }
  5241. }
  5242. }//END FOR AC_QUANTITY
  5243. }// END FOR gunTotalNumber
  5244. }
  5245. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5246. {
  5247. for(int i=0; i < gunTotalNumber; i++)
  5248. {
  5249. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5250. {
  5251. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5252. goto end;
  5253. }
  5254. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5255. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5256. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5257. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5259. {
  5260. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5261. goto end;
  5262. }
  5263. }
  5264. }
  5265. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5266. goto end;
  5267. }
  5268. //----------------------gunIndex is not 0 ------------------------------------------------//
  5269. //check Transaction active
  5270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5271. {
  5272. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5273. {
  5274. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5275. {
  5276. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5277. goto end;
  5278. }
  5279. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5280. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5281. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5282. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5284. {
  5285. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5286. goto end;
  5287. }
  5288. else
  5289. {
  5290. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5291. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5292. goto end;
  5293. }
  5294. }
  5295. }//END FOR CHAdeMO_QUANTITY
  5296. for (int index = 0; index < CCS_QUANTITY; index++)
  5297. {
  5298. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5299. {
  5300. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5301. {
  5302. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5303. goto end;
  5304. }
  5305. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5306. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5307. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5308. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5309. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5310. {
  5311. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5312. goto end;
  5313. }
  5314. else
  5315. {
  5316. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5317. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5318. goto end;
  5319. }
  5320. }
  5321. }//END FOR CCS_QUANTITY
  5322. for (int index = 0; index < GB_QUANTITY; index++)
  5323. {
  5324. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5325. {
  5326. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5327. {
  5328. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5329. goto end;
  5330. }
  5331. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5332. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5333. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5334. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5336. {
  5337. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5338. goto end;
  5339. }
  5340. else
  5341. {
  5342. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5343. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5344. goto end;
  5345. }
  5346. }
  5347. }// END FOR GB_QUANTITY
  5348. for (int index = 0; index < AC_QUANTITY; index++)
  5349. {
  5350. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5351. {
  5352. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5353. {
  5354. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5355. goto end;
  5356. }
  5357. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5358. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5359. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5360. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5361. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5362. {
  5363. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5364. goto end;
  5365. }
  5366. else
  5367. {
  5368. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5369. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5370. goto end;
  5371. }
  5372. }
  5373. }//END FOR AC_QUANTITY
  5374. }//END FOR AvailabilityTypeStr[Inoperative]
  5375. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5376. {
  5377. //----------------------gunIndex is 0 ------------------------------------------------//
  5378. if(gunIndex == 0)
  5379. {
  5380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5381. {
  5382. for(int i=0; i < gunTotalNumber; i++)
  5383. {
  5384. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5385. {
  5386. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5387. {
  5388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5389. goto end;
  5390. }
  5391. }//END FOR CHAdeMO_QUANTITY
  5392. for (int index = 0; index < CCS_QUANTITY; index++)
  5393. {
  5394. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT//(((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5395. {
  5396. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5397. goto end;
  5398. }
  5399. }//END FOR CCS_QUANTITY
  5400. for (int index = 0; index < GB_QUANTITY; index++)
  5401. {
  5402. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5403. {
  5404. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5405. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5406. goto end;
  5407. }
  5408. }// END FOR GB_QUANTITY
  5409. for (int index = 0; index < AC_QUANTITY; index++)
  5410. {
  5411. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5412. {
  5413. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5414. goto end;
  5415. }
  5416. }//END FOR CHAdeMO_QUANTITY
  5417. }// END FOR gunTotalNumber
  5418. }
  5419. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5420. {
  5421. for(int i=0; i < gunTotalNumber; i++)
  5422. {
  5423. for (int index = 0; index < AC_QUANTITY; index++)
  5424. {
  5425. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5426. {
  5427. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5428. goto end;
  5429. }
  5430. }//END FOR CHAdeMO_QUANTITY
  5431. } // END FOR gunTotalNumber
  5432. }
  5433. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5434. goto end;
  5435. }
  5436. //----------------------gunIndex is not 0 ------------------------------------------------//
  5437. //check Transaction active
  5438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5439. {
  5440. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5441. {
  5442. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5443. goto end;
  5444. }
  5445. }//END FOR CHAdeMO_QUANTITY
  5446. for (int index = 0; index < CCS_QUANTITY; index++)
  5447. {
  5448. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5449. {
  5450. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5451. goto end;
  5452. }
  5453. }//END FOR CCS_QUANTITY
  5454. for (int index = 0; index < GB_QUANTITY; index++)
  5455. {
  5456. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5457. {
  5458. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5459. goto end;
  5460. }
  5461. }// END FOR GB_QUANTITY
  5462. for (int index = 0; index < AC_QUANTITY; index++)
  5463. {
  5464. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5465. {
  5466. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5467. goto end;
  5468. }
  5469. }//END FOR AC_QUANTITY
  5470. }//END FOR AvailabilityTypeStr[Operative]
  5471. end:
  5472. if(gunIndex != 0)
  5473. {
  5474. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5475. }
  5476. else
  5477. {
  5478. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5479. }
  5480. if(gunIndex != 0)
  5481. {
  5482. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5483. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5484. }
  5485. else
  5486. {
  5487. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5488. {
  5489. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5490. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5491. }
  5492. }
  5493. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5494. return result;
  5495. }
  5496. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5497. {
  5498. mtrace();
  5499. int result = FAIL;
  5500. char keystr[40]={0};
  5501. char valuestr[100]={0};
  5502. char comfirmstr[20]={0};
  5503. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5504. json_object *ChangeConfiguration;
  5505. ChangeConfiguration = json_tokener_parse(payload);
  5506. if(!is_error(ChangeConfiguration))
  5507. {
  5508. // Required data
  5509. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5510. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5511. }
  5512. json_object_put(ChangeConfiguration);
  5513. if((uuid==NULL) || (payload ==NULL) )
  5514. {
  5515. DEBUG_ERROR("Payload is null\n");
  5516. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5517. }
  5518. else
  5519. {
  5520. int status = setKeyValue(keystr, valuestr);
  5521. switch(status)
  5522. {
  5523. case ConfigurationStatus_Accepted:
  5524. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5525. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5526. StoreConfigurationTable();
  5527. break;
  5528. case ConfigurationStatus_Rejected:
  5529. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5530. break;
  5531. case RebootRequired:
  5532. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5533. StoreConfigurationTable();
  5534. break;
  5535. case NotSupported:
  5536. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5537. break;
  5538. default:
  5539. break;
  5540. }
  5541. }
  5542. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5543. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5544. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5545. {
  5546. ChageWebSocketPingInterval(atoi(valuestr));
  5547. }
  5548. return result;
  5549. }
  5550. int handleClearCacheRequest(char *uuid, char *payload)
  5551. {
  5552. mtrace();
  5553. int result = FAIL;
  5554. char comfirmstr[20];
  5555. int fd;
  5556. char rmFileCmd[100]={0};
  5557. struct stat stats;
  5558. DEBUG_INFO("handleClearCacheRequest...\n");
  5559. stat("/Storage/OCPP", &stats);
  5560. // Check for directory existence
  5561. if (S_ISDIR(stats.st_mode) == 1)
  5562. {}
  5563. else
  5564. {
  5565. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5566. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5567. system(rmFileCmd);
  5568. }
  5569. memset(rmFileCmd, 0, sizeof rmFileCmd);
  5570. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5571. {
  5572. DEBUG_INFO("AuthorizationCache file exist.\n");
  5573. }
  5574. else
  5575. {
  5576. DEBUG_INFO("AuthorizationCache file not exist\n");
  5577. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5578. if(log == NULL)
  5579. {
  5580. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5581. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5582. goto end;
  5583. }
  5584. else
  5585. {
  5586. fclose(log);
  5587. }
  5588. }
  5589. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5590. {
  5591. DEBUG_INFO("open AuthorizationCache file failed\n");
  5592. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5593. }
  5594. else
  5595. {
  5596. DEBUG_INFO("open AuthorizationCache file successful\n");
  5597. ftruncate(fd,0);
  5598. lseek(fd,0,SEEK_SET);
  5599. close(fd);
  5600. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5601. }
  5602. end:
  5603. sendClearCacheConfirmation(uuid, comfirmstr);
  5604. return result;
  5605. }
  5606. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5607. {
  5608. mtrace();
  5609. int result = FAIL;
  5610. int resultRename;
  5611. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5612. char chargingProfilePurposeStr[26]={0};
  5613. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5614. char tempchargingProfilePurposeStr[26]={0};
  5615. char sstr[160]={0};
  5616. char str[100]={0};
  5617. int c = 0;
  5618. char *loc;
  5619. char fname[200]={0};
  5620. char comfirmstr[20]={0};
  5621. char word[1600]={0};
  5622. int clearflag = FALSE;
  5623. int chargingProfileIdIsNULL = FALSE;
  5624. int connectorIsNULL = FALSE;
  5625. int chargingProfilePurposeIsNULL = FALSE;
  5626. int stackLevelIsNULL = FALSE;
  5627. //int GotoEnd = FALSE;
  5628. FILE *fptr1, *fptr2;
  5629. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5630. int n_chargingProfile=0;
  5631. int isEmptyFile = FALSE;
  5632. char sLineWord[1600]={0};
  5633. char chargingProfiles[10][100]={0};
  5634. int ChargeProfileCount = 0;
  5635. char ch;
  5636. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5637. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5638. json_object *ClearChargingProfile;
  5639. ClearChargingProfile = json_tokener_parse(payload);
  5640. if(!is_error(ClearChargingProfile))
  5641. {
  5642. // Optional data
  5643. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5644. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5645. else
  5646. chargingProfileIdIsNULL = TRUE;
  5647. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5648. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5649. else
  5650. connectorIsNULL = TRUE;
  5651. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5652. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5653. else
  5654. chargingProfilePurposeIsNULL = TRUE;
  5655. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5656. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5657. else
  5658. stackLevelIsNULL = TRUE;
  5659. }
  5660. json_object_put(ClearChargingProfile);
  5661. if(connectorIsNULL == FALSE)
  5662. {
  5663. switch(connectorIdInt)
  5664. {
  5665. case 0:
  5666. if(chargingProfilePurposeIsNULL == TRUE)
  5667. {
  5668. int l = 0;
  5669. strcpy(fname, ChargePointMaxProfile_JSON);
  5670. if((access(fname,F_OK))!=-1)
  5671. {
  5672. strcpy(chargingProfiles[l], fname);
  5673. l = l + 1;
  5674. }
  5675. strcpy(fname, TxDefaultProfile_0_JSON);
  5676. if((access(fname,F_OK))!=-1)
  5677. {
  5678. strcpy(chargingProfiles[l], fname);
  5679. l = l + 1;
  5680. }
  5681. ChargeProfileCount = l;
  5682. }
  5683. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5684. {
  5685. strcpy(fname, ChargePointMaxProfile_JSON);
  5686. if((access(fname,F_OK))!=-1)
  5687. {
  5688. strcpy(chargingProfiles[0], fname);
  5689. ChargeProfileCount = 1;
  5690. }
  5691. }
  5692. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5693. {
  5694. strcpy(fname, TxDefaultProfile_0_JSON);
  5695. if((access(fname,F_OK))!=-1)
  5696. {
  5697. strcpy(chargingProfiles[0], fname);
  5698. ChargeProfileCount = 1;
  5699. }
  5700. }
  5701. break;
  5702. default:
  5703. if(chargingProfilePurposeIsNULL == TRUE)
  5704. {
  5705. int m = 0;
  5706. memset(fname, 0, sizeof fname);
  5707. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5708. if((access(fname,F_OK))!=-1)
  5709. {
  5710. strcpy(chargingProfiles[m], fname);
  5711. m = m + 1;
  5712. }
  5713. memset(fname, 0, sizeof fname);
  5714. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5715. if((access(fname,F_OK))!=-1)
  5716. {
  5717. strcpy(chargingProfiles[m], fname);
  5718. m = m + 1;
  5719. }
  5720. ChargeProfileCount = m;
  5721. }
  5722. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5723. {
  5724. //strcpy(fname, TxDefaultProfile_1_JSON);
  5725. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5726. if((access(fname,F_OK))!=-1)
  5727. {
  5728. strcpy(chargingProfiles[0], fname);
  5729. ChargeProfileCount = 1;
  5730. }
  5731. }
  5732. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5733. {
  5734. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5735. if((access(fname,F_OK))!=-1)
  5736. {
  5737. strcpy(chargingProfiles[0], fname);
  5738. ChargeProfileCount = 1;
  5739. }
  5740. //strcpy(fname, TxProfile_1_JSON);
  5741. }
  5742. //strcpy(fname, ChargePointMaxProfile_JSON );
  5743. break;
  5744. }
  5745. }
  5746. else // Check all Charging Profiles
  5747. {
  5748. int i = 0;
  5749. char fnametemp[200]={0};
  5750. ChargeProfileCount = 0;
  5751. //Check ChargePointMaxProfile.json exit
  5752. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5753. {
  5754. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5755. i = i + 1;
  5756. }
  5757. //Check TxDefaultProfile_0.json exit
  5758. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5759. {
  5760. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5761. i = i + 1;
  5762. }
  5763. //Check TxDefaultProfile_%d.json
  5764. for(int j=1; j <= gunTotalNumber; j++)
  5765. {
  5766. memset(fnametemp, 0, sizeof fnametemp);
  5767. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5768. if((access(fnametemp,F_OK))!=-1)
  5769. {
  5770. strcpy(chargingProfiles[i], fnametemp);
  5771. i = i + 1;
  5772. }
  5773. }
  5774. //Check TxProfile_%d.json
  5775. for(int j=1; j <= gunTotalNumber; j++)
  5776. {
  5777. memset(fnametemp, 0, sizeof fnametemp);
  5778. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  5779. if((access(fnametemp,F_OK))!=-1)
  5780. {
  5781. strcpy(chargingProfiles[i], fnametemp);
  5782. i = i + 1;
  5783. }
  5784. }
  5785. ChargeProfileCount = i;
  5786. }// End connectorIsNULL is TRUE
  5787. if(ChargeProfileCount == 0)
  5788. {
  5789. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5790. goto end;
  5791. }
  5792. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  5793. {
  5794. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5795. goto end;
  5796. }
  5797. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  5798. {
  5799. memset(str, 0, sizeof str);
  5800. // clear temp file
  5801. sprintf(str,"rm -f %s",temp);
  5802. system(str);
  5803. for(int k=0; k < ChargeProfileCount; k++)
  5804. {
  5805. memset(str, 0, sizeof str);
  5806. //clear file in C
  5807. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5808. system(str);
  5809. }
  5810. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5811. goto end;
  5812. }
  5813. else if(connectorIsNULL == TRUE)
  5814. {
  5815. for(int k=0; k < ChargeProfileCount; k++)
  5816. {
  5817. fptr1 = fopen(chargingProfiles[k], "r");
  5818. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  5819. //Check Charging Profile Count
  5820. while(fscanf(fptr1, "%s", word) != EOF)
  5821. {
  5822. //DEBUG_INFO("word=%s\n",word);
  5823. if(strstr(word, "chargingProfileId")!= NULL)
  5824. {
  5825. //DEBUG_INFO("test chargingProfileId \n");
  5826. n_chargingProfile = n_chargingProfile + 1;
  5827. //DEBUG_INFO("chargingProfileId Found\n");
  5828. }
  5829. }
  5830. rewind(fptr1);
  5831. //search Charging Profile Element
  5832. //int i= 0;
  5833. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5834. {
  5835. //------------------------tempconnectorIdInt------------------------//
  5836. loc = strstr(sLineWord, "connectorId");
  5837. c = 0;
  5838. memset(sstr ,0, sizeof(sstr) );
  5839. while (loc[strlen("connectorId")+2+c] != ',')
  5840. {
  5841. sstr[c] = loc[strlen("connectorId")+2+c];
  5842. c++;
  5843. }
  5844. sstr[c] = '\0';
  5845. tempconnectorIdInt = atoi(sstr);
  5846. printf("file's gun number is %d\n", tempconnectorIdInt);
  5847. //--------------------------chargingProfileId--------------------//
  5848. c = 0;
  5849. loc = strstr(sLineWord, "chargingProfileId");
  5850. memset(sstr ,0, sizeof(sstr) );
  5851. while (loc[strlen("chargingProfileId")+2+c] != ',')
  5852. {
  5853. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  5854. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5855. c++;
  5856. }
  5857. sstr[c] = '\0';
  5858. tempchargingProfileIdInt = atoi(sstr);
  5859. //stackLevel
  5860. c = 0;
  5861. loc = strstr(sLineWord, "stackLevel");
  5862. memset(sstr ,0, sizeof(sstr) );
  5863. while (loc[strlen("stackLevel")+2+c] != ',')
  5864. {
  5865. sstr[c] = loc[strlen("stackLevel")+2+c];
  5866. //printf("i=%d sstr=%c\n",c, sstr[c]);
  5867. c++;
  5868. }
  5869. sstr[c] = '\0';
  5870. tempstackLevelInt = atoi(sstr);
  5871. c = 0;
  5872. loc = strstr(sLineWord, "chargingProfilePurpose");
  5873. memset(sstr ,0, sizeof(sstr) );
  5874. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  5875. {
  5876. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  5877. c++;
  5878. }
  5879. sstr[c] = '\0';
  5880. strcpy(tempchargingProfilePurposeStr, sstr);
  5881. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  5882. {
  5883. //------- not write to fptr2-------//
  5884. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5885. //clearflag = TRUE;
  5886. }
  5887. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  5888. {
  5889. //------- not write to fptr2-------//
  5890. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5891. }
  5892. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  5893. {
  5894. //------- not write to fptr2-------//
  5895. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  5896. }
  5897. else
  5898. {
  5899. fprintf(fptr2, sLineWord);//writing data into file
  5900. }
  5901. memset(sLineWord, 0, sizeof sLineWord);
  5902. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5903. if(clearflag == TRUE)
  5904. {
  5905. fclose(fptr1);
  5906. fclose(fptr2);
  5907. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5908. system(str);
  5909. // clear temp file
  5910. sprintf(str,"rm -f %s",temp);
  5911. system(str);
  5912. }
  5913. else
  5914. {
  5915. fclose(fptr1);
  5916. fclose(fptr2);
  5917. memset(str, 0, sizeof str);
  5918. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5919. system(str);
  5920. resultRename = rename(temp, chargingProfiles[k]);
  5921. if(resultRename == 0)
  5922. {
  5923. DEBUG_INFO("File ChargingProfile renamed successfully");
  5924. }
  5925. else
  5926. {
  5927. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  5928. }
  5929. if(comfirmstr[0]== 0)
  5930. {
  5931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  5932. }
  5933. //Check chargingProfile is empty file
  5934. /*------ Read the file ----------------*/
  5935. fptr1=fopen(chargingProfiles[k],"r");
  5936. ch=fgetc(fptr1);
  5937. rewind(fptr1);
  5938. memset(sLineWord, 0, sizeof sLineWord);
  5939. if(ch!=EOF)
  5940. {
  5941. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  5942. {
  5943. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  5944. if(sLineWord[0]=='\0')
  5945. {
  5946. isEmptyFile = TRUE;
  5947. break;
  5948. }
  5949. else
  5950. {
  5951. isEmptyFile = FALSE;
  5952. break;
  5953. }
  5954. }
  5955. }
  5956. fclose(fptr1);
  5957. if(isEmptyFile == TRUE)
  5958. {
  5959. memset(str, 0, sizeof str);
  5960. sprintf(str,"rm -f %s",chargingProfiles[k]);
  5961. system(str);
  5962. }
  5963. }
  5964. }// End of while(int k=0; k < ChargePointCount; k++)
  5965. }
  5966. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  5967. {
  5968. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  5969. for(int k=0; k < ChargeProfileCount; k++)
  5970. {
  5971. fptr1 = fopen(chargingProfiles[k], "r");
  5972. fptr2 = fopen(temp, "w+");
  5973. //Check Charging Profile Count
  5974. while(fscanf(fptr1, "%s", word) != EOF)
  5975. {
  5976. //DEBUG_INFO("word=%s\n",word);
  5977. if(strstr(word, "chargingProfileId")!= NULL)
  5978. {
  5979. n_chargingProfile = n_chargingProfile + 1;
  5980. }
  5981. }
  5982. rewind(fptr1);
  5983. //search Charging Profile Element
  5984. //int i= 0;
  5985. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  5986. {
  5987. //*************************tempconnectorIdInt*********************************/
  5988. loc = strstr(sLineWord, "connectorId");
  5989. c = 0;
  5990. memset(sstr ,0, sizeof(sstr) );
  5991. while (loc[strlen("connectorId")+2+c] != ',')
  5992. {
  5993. sstr[c] = loc[strlen("connectorId")+2+c];
  5994. c++;
  5995. }
  5996. sstr[c] = '\0';
  5997. tempconnectorIdInt = atoi(sstr);
  5998. //chargingProfileId
  5999. c = 0;
  6000. loc = strstr(sLineWord, "chargingProfileId");
  6001. memset(sstr ,0, sizeof(sstr) );
  6002. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6003. {
  6004. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6005. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6006. c++;
  6007. }
  6008. sstr[c] = '\0';
  6009. tempchargingProfileIdInt = atoi(sstr);
  6010. //stackLevel
  6011. c = 0;
  6012. loc = strstr(sLineWord, "stackLevel");
  6013. memset(sstr ,0, sizeof(sstr) );
  6014. while (loc[strlen("stackLevel")+2+c] != ',')
  6015. {
  6016. sstr[c] = loc[strlen("stackLevel")+2+c];
  6017. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6018. c++;
  6019. }
  6020. sstr[c] = '\0';
  6021. tempstackLevelInt = atoi(sstr);
  6022. c = 0;
  6023. loc = strstr(sLineWord, "chargingProfilePurpose");
  6024. memset(sstr ,0, sizeof(sstr) );
  6025. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6026. {
  6027. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6028. c++;
  6029. }
  6030. sstr[c] = '\0';
  6031. strcpy(tempchargingProfilePurposeStr, sstr);
  6032. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6033. {
  6034. //------- not write to fptr2-------//
  6035. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6036. //clearflag = TRUE;
  6037. }
  6038. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6039. {
  6040. //------- not write to fptr2-------//
  6041. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6042. }
  6043. else if(stackLevelIsNULL == TRUE)
  6044. {
  6045. //Clear Whole File
  6046. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6047. clearflag = TRUE;
  6048. break;
  6049. }
  6050. else
  6051. {
  6052. fprintf(fptr2, sLineWord);//writing data into file
  6053. }
  6054. memset(sLineWord, 0, sizeof sLineWord);
  6055. }
  6056. if(clearflag == TRUE)
  6057. {
  6058. fclose(fptr1);
  6059. fclose(fptr2);
  6060. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6061. system(str);
  6062. // clear temp file
  6063. sprintf(str,"rm -f %s",temp);
  6064. system(str);
  6065. }
  6066. else
  6067. {
  6068. fclose(fptr1);
  6069. fclose(fptr2);
  6070. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6071. system(str);
  6072. resultRename = rename(temp, chargingProfiles[k]);
  6073. if(resultRename == 0)
  6074. {
  6075. DEBUG_INFO("File ChargingProfile renamed successfully");
  6076. }
  6077. else
  6078. {
  6079. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6080. }
  6081. if(comfirmstr[0]== 0)
  6082. {
  6083. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6084. }
  6085. //Check chargingProfile is empty file
  6086. /*------ Read the file ----------------*/
  6087. fptr1=fopen(chargingProfiles[k],"r");
  6088. ch=fgetc(fptr1);
  6089. rewind(fptr1);
  6090. memset(sLineWord, 0, sizeof sLineWord);
  6091. if(ch!=EOF)
  6092. {
  6093. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6094. {
  6095. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6096. if(sLineWord[0]=='\0')
  6097. {
  6098. isEmptyFile = TRUE;
  6099. break;
  6100. }
  6101. else
  6102. {
  6103. isEmptyFile = FALSE;
  6104. break;
  6105. }
  6106. }
  6107. }
  6108. fclose(fptr1);
  6109. if(isEmptyFile == TRUE)
  6110. {
  6111. memset(str, 0, sizeof str);
  6112. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6113. system(str);
  6114. }
  6115. /*------- End of reading ---------------*/
  6116. }
  6117. } // while(int k=0; k < ChargeProfileCount; k++)
  6118. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6119. end:
  6120. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6121. return result;
  6122. }
  6123. int handleDataTransferRequest(char *uuid, char *payload)
  6124. {
  6125. mtrace();
  6126. int result = FAIL;
  6127. //Payload={"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}
  6128. char tempvendorId[255]={0};
  6129. char tempmessageId[50]={0};
  6130. char tempdata[50]={0};
  6131. char message[80]={0};
  6132. DEBUG_INFO("handleDataTransferRequest...\n");
  6133. if((uuid != NULL) && (payload != NULL))
  6134. {
  6135. json_object *DataTransfer;
  6136. DataTransfer = json_tokener_parse(payload);
  6137. if(!is_error(DataTransfer))
  6138. {
  6139. // Required data
  6140. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6141. // Optional data
  6142. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6143. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6144. if(json_object_object_get(DataTransfer, "data") != NULL)
  6145. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6146. result = PASS;
  6147. }
  6148. json_object_put(DataTransfer);
  6149. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "Rejected", tempvendorId, tempmessageId, tempdata );
  6150. }
  6151. else
  6152. {
  6153. char guid[37]={0};
  6154. random_uuid(guid);
  6155. //[2,"1577349264923","DataTransfer",{"vendorId":"Phihong","messageId":"MSGID","data":"Data1"}]
  6156. sprintf(message,"[%d,\"%s\",\"%s\",{\"vendorId\":\"Phihong\",\"messageId\":\"MSGID\",\"data\":\"Data1\"}]",MESSAGE_TYPE_CALL, guid, "DataTransfer");
  6157. }
  6158. LWS_Send(message);
  6159. return result;
  6160. }
  6161. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6162. {
  6163. mtrace();
  6164. int result = FAIL;
  6165. int connectorIdInt, durationInt;
  6166. char chargingRateUnitStr[4]={0};
  6167. char comfirmstr[20];
  6168. int confirmPeriods = 0;
  6169. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6170. json_object *GetCompositeSchedule;
  6171. GetCompositeSchedule = json_tokener_parse(payload);
  6172. if(!is_error(GetCompositeSchedule))
  6173. {
  6174. // Required data
  6175. connectorIdInt= json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6176. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6177. // Optional data
  6178. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6179. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6180. }
  6181. json_object_put(GetCompositeSchedule);
  6182. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6183. if((connectorIdInt == 0) ||
  6184. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6185. {
  6186. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6187. struct StructChargingProfile tmpProfile[1];
  6188. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6189. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6190. {
  6191. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6192. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6193. }
  6194. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6195. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6196. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6197. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6198. {
  6199. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6200. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6201. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6202. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6203. {
  6204. confirmPeriods = idx;
  6205. break;
  6206. }
  6207. }
  6208. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6209. }
  6210. else
  6211. {
  6212. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6213. }
  6214. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6215. return result;
  6216. }
  6217. int handleGetConfigurationRequest(char *uuid, char *payload)
  6218. {
  6219. mtrace();
  6220. int result = FAIL;
  6221. int MaxKeySupported = 0;
  6222. int n_keys = 0;
  6223. char requestKey[43][50]={0};
  6224. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6225. json_object *GetConfiguration;
  6226. GetConfiguration = json_tokener_parse(payload);
  6227. if(!is_error(GetConfiguration))
  6228. {
  6229. // Optional data
  6230. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6231. {
  6232. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6233. {
  6234. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6235. n_keys = idx + 1;
  6236. }
  6237. }
  6238. }
  6239. json_object_put(GetConfiguration);
  6240. UnknownKeynum = 0;
  6241. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6242. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6243. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6244. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6245. if(n_keys != 0)
  6246. {
  6247. for(int i=0;i<n_keys;i++)
  6248. {
  6249. getKeyValue(requestKey[i]);
  6250. }
  6251. }
  6252. else
  6253. {
  6254. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6255. getKeyValue("");
  6256. }
  6257. processUnkownKey();
  6258. sendGetConfigurationConfirmation(uuid);
  6259. return result;
  6260. }
  6261. static char fnamePlusPath[100]={0};
  6262. static char fnamePWithNoPath[60]={0};
  6263. void checkUploadLog(void)
  6264. {
  6265. FILE *fp;
  6266. /* Open the command for reading. */
  6267. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6268. if (fp == NULL) {
  6269. printf("Failed to run command\n" );
  6270. exit(1);
  6271. }
  6272. int ftppathlen = 0;
  6273. memset(fnamePlusPath, 0, sizeof(fnamePlusPath));
  6274. int i = 0;
  6275. /* Read the output a line at a time - output it. */
  6276. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6277. if(i==0)
  6278. {
  6279. ftppathlen = strlen(fnamePlusPath);
  6280. printf("%s\n", fnamePlusPath);
  6281. fnamePlusPath[ftppathlen]='\0';
  6282. break;
  6283. }
  6284. i= i+1;
  6285. }
  6286. /* close */
  6287. pclose(fp);
  6288. for(int k=0; k< sizeof(fnamePlusPath); k++)
  6289. {
  6290. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6291. {
  6292. fnamePlusPath[k]='\0';
  6293. }
  6294. }
  6295. i=1;
  6296. //char fname[60]={0};
  6297. while(i < ftppathlen)
  6298. {
  6299. int len=ftppathlen-i;
  6300. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6301. {
  6302. printf("compare '/' all right\n");
  6303. break;
  6304. }
  6305. i=i+1;
  6306. }
  6307. memset(fnamePWithNoPath, 0, sizeof(fnamePWithNoPath));
  6308. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6309. fnamePWithNoPath[i+1] = '\0';
  6310. for(int j=0; j< sizeof(fnamePWithNoPath); j++)
  6311. {
  6312. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6313. {
  6314. fnamePWithNoPath[j]='\0';
  6315. }
  6316. }
  6317. FILE* fp1 = fopen(fnamePlusPath, "r");
  6318. if (fp1)
  6319. {
  6320. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6321. // file exists
  6322. fclose(fp1);
  6323. }
  6324. else
  6325. {
  6326. // file doesn't exist
  6327. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6328. }
  6329. }
  6330. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6331. {
  6332. mtrace();
  6333. int result = FAIL;
  6334. char cmdBuf[512];
  6335. char fName[258];
  6336. time_t CurrentTime;
  6337. struct tm *tm;
  6338. pthread_t th_Status;
  6339. CurrentTime = time(NULL);
  6340. tm = localtime(&CurrentTime);
  6341. 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);
  6342. sendGetDiagnosticsConfirmation(uuid, fName);
  6343. system("exec /root/logPackTools 'log' 6");
  6344. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6345. system(cmdBuf);
  6346. checkUploadLog();
  6347. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6348. return result;
  6349. }
  6350. void* GetDiagnosticsProcess(void* data)
  6351. {
  6352. pthread_detach(pthread_self());
  6353. mtrace();
  6354. int retriesInt=0, retryIntervalInt=0;
  6355. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6356. int retriesIsNULL,retryIntervalIsNULL, startTimeIsNULL, stopTimeIsNULL;
  6357. 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};
  6358. int port=0;
  6359. char sstr[260]={ 0 };
  6360. int c = 0;
  6361. char *loc;
  6362. int isSuccess = FALSE;
  6363. char ftpbuf[200]={0};
  6364. char * pch;
  6365. char str[300]={ 0 };
  6366. strcpy(str,(const char*)data);
  6367. retriesIsNULL = retryIntervalIsNULL = startTimeIsNULL = stopTimeIsNULL = FALSE;
  6368. DEBUG_INFO("GetDiagnosticsProcess...%s\n", str);
  6369. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6370. //****************location*******************/
  6371. c = 0;
  6372. memset(sstr ,0, sizeof(sstr) );
  6373. loc = strstr(str, "location");
  6374. while (loc[3+strlen("location")+c] != '\"')
  6375. {
  6376. sstr[c] = loc[3+strlen("location")+c];
  6377. c++;
  6378. }
  6379. sstr[c] = '\0';
  6380. strcpy(locationstr,sstr);
  6381. //strcpy(locationstr,"http://test.evsocket.phihong.com.cn:9001/UploadFiles/Diagnostics/");
  6382. if(strcmp(locationstr,"")==0)
  6383. {
  6384. DEBUG_INFO("location is <Empty>!\n");
  6385. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6386. goto end;
  6387. }
  6388. //****************retries*******************/
  6389. c = 0;
  6390. loc = strstr(str, "retries");
  6391. if(loc == NULL)
  6392. {
  6393. retriesIsNULL = TRUE;
  6394. }
  6395. else
  6396. {
  6397. while ((loc[strlen("retries")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6398. {
  6399. sstr[c] = loc[strlen("retries")+2+c];
  6400. c++;
  6401. }
  6402. sstr[c] = '\0';
  6403. retriesInt = atoi(sstr);
  6404. }
  6405. if(retriesIsNULL == TRUE)
  6406. {
  6407. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6408. }
  6409. //****************retryInterval*******************/
  6410. c = 0;
  6411. loc = strstr(str, "retryInterval");
  6412. if(loc == NULL)
  6413. {
  6414. retryIntervalIsNULL = TRUE;
  6415. retryIntervalInt = 30; // if this field is not present, it is left to Charge Point to decide how long to wait between attempts.
  6416. }
  6417. else
  6418. {
  6419. while ((loc[strlen("retryInterval")+2+c] != ',')&&(loc[strlen("retries")+2+c] != '}'))
  6420. {
  6421. sstr[c] = loc[strlen("retryInterval")+2+c];
  6422. c++;
  6423. }
  6424. sstr[c] = '\0';
  6425. retryIntervalInt = atoi(sstr);
  6426. }
  6427. //****************startTime*******************/
  6428. c = 0;
  6429. memset(sstr ,0, sizeof(sstr) );
  6430. loc = strstr(str, "startTime");
  6431. if(loc == NULL)
  6432. {
  6433. startTimeIsNULL = TRUE;
  6434. }
  6435. else
  6436. {
  6437. while (loc[3+strlen("startTime")+c] != '\"')
  6438. {
  6439. sstr[c] = loc[3+strlen("startTime")+c];
  6440. c++;
  6441. }
  6442. sstr[c] = '\0';
  6443. strcpy(startTimestr,sstr);
  6444. }
  6445. //****************stopTime*******************/
  6446. c = 0;
  6447. memset(sstr ,0, sizeof(sstr) );
  6448. loc = strstr(str, "stopTime");
  6449. if(loc == NULL)
  6450. {
  6451. stopTimeIsNULL = TRUE;
  6452. }
  6453. else
  6454. {
  6455. while (loc[3+strlen("stopTime")+c] != '\"')
  6456. {
  6457. sstr[c] = loc[3+strlen("stopTime")+c];
  6458. c++;
  6459. }
  6460. sstr[c] = '\0';
  6461. strcpy(stopTimestr,sstr);
  6462. }
  6463. memset(protocol, 0, sizeof(protocol));
  6464. memset(user, 0, sizeof(user) );
  6465. memset(password, 0, sizeof(password));
  6466. memset(host, 0, sizeof(host));
  6467. memset(path, 0, sizeof(path));
  6468. memset(ftppath, 0, sizeof(ftppath));
  6469. memset(host1, 0, sizeof(host1));
  6470. memset(path1, 0, sizeof(path1));
  6471. /*location: ftp://user:password@host:port/path*/
  6472. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6473. if((access(fnamePlusPath,F_OK))!=-1)
  6474. {
  6475. DEBUG_INFO("fnamePlusPath exist.\n");
  6476. }
  6477. else
  6478. {
  6479. DEBUG_INFO("fnamePlusPath not exist!\n");
  6480. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6481. goto end;
  6482. }
  6483. pch=strchr(locationstr,'@');
  6484. if(pch==NULL)
  6485. {
  6486. sscanf(locationstr,
  6487. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6488. protocol, host, &port, path);
  6489. strcpy(user,"anonymous");
  6490. strcpy(password,"");
  6491. }
  6492. else
  6493. {
  6494. //DEBUG_INFO("pch=%s\n", pch);
  6495. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6496. protocol, user, password, host, &port, path);
  6497. }
  6498. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6499. {
  6500. DEBUG_INFO("protocol is not ftp/http ! \n");
  6501. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6502. goto end;
  6503. }
  6504. if(strncmp(locationstr,"http", 4) == 0)
  6505. {
  6506. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6507. sprintf(ftppath,"/%s", path);
  6508. do{
  6509. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6510. sleep(retryIntervalInt);
  6511. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6512. if(!isSuccess)
  6513. {
  6514. DEBUG_INFO("Diagnostics fail.\n");
  6515. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6516. }
  6517. else
  6518. {
  6519. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6520. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6521. }
  6522. }
  6523. else
  6524. {
  6525. sscanf(host,"%[^/]%s",host1, path1);
  6526. sprintf(ftppath,"%s", path1);
  6527. int ftppathlen=strlen(ftppath);
  6528. int i=1;
  6529. char filenametemp[50];
  6530. while(i < ftppathlen)
  6531. {
  6532. int len=ftppathlen-i;
  6533. if(ftppath[len]== 47) // '/' ascll code: 47
  6534. {
  6535. DEBUG_INFO("find '/' all right\n");
  6536. break;
  6537. }
  6538. i=i+1;
  6539. }
  6540. memset(filenametemp, 0, sizeof(filenametemp));
  6541. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6542. filenametemp[i+1] = 0;
  6543. memset(ftpbuf, 0, sizeof(ftpbuf));
  6544. if(port == 0)
  6545. port = 21;
  6546. do{
  6547. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6548. sleep(retryIntervalInt);
  6549. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6550. if(!isSuccess)
  6551. {
  6552. DEBUG_INFO("Diagnostics fail.\n");
  6553. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6554. }
  6555. else
  6556. {
  6557. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6558. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6559. }
  6560. }
  6561. end:
  6562. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6563. pthread_exit(NULL);
  6564. }
  6565. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6566. {
  6567. mtrace();
  6568. int result = FAIL;
  6569. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6570. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6571. {
  6572. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6573. localversion = -1;
  6574. }
  6575. else
  6576. {
  6577. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6578. OCPP_getListVerion();
  6579. }
  6580. //from db.OCPP_getListVerion
  6581. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6582. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6583. sendGetLocalListVersionConfirmation(uuid,"");
  6584. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6585. return result;
  6586. }
  6587. int handleRemoteStartRequest(char *uuid, char *payload)
  6588. {
  6589. mtrace();
  6590. int result = FAIL;
  6591. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0, stackLevelInt=0,
  6592. durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  6593. int tempIndex = 0;
  6594. char idTagstr[20]={0}, chargingProfilePurposestr[30]={0}, chargingProfileKindstr[14]={0}, recurrencyKindstr[10]={0},
  6595. validFromstr[30]={0}, validTostr[30]={0}, startSchedulestr[30]={0}, chargingRateUnitstr[4]={0};
  6596. int connectorIdIsNULL,chargingProfileIsNULL,transactionIdIsNULL,recurrencyKindIsNULL,validFromIsNULL,validToIsNULL,durationIsNULL,startScheduleIsNULL,minChargingRateIsNULL,numberPhasesIsNULL;
  6597. float minChargingRateflaot=0.0, limitflaot[10]={0.0};
  6598. int chargingSchedulePeriodCount = 0;
  6599. char sstr[30]={ 0 },sstrtemp[1600]={ 0 };//sstr[200]={ 0 };
  6600. int c = 0;
  6601. char *loc;
  6602. char comfirmstr[20]={0};
  6603. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6604. if(server_pending == TRUE)
  6605. {
  6606. return 0;
  6607. }
  6608. connectorIdIsNULL = chargingProfileIsNULL = transactionIdIsNULL = recurrencyKindIsNULL = validFromIsNULL = validToIsNULL = durationIsNULL = startScheduleIsNULL = minChargingRateIsNULL = numberPhasesIsNULL= FALSE;
  6609. strcpy(sstrtemp, stringtrimspace(payload));
  6610. //**********connectorId****************/
  6611. c = 0;
  6612. memset(sstr ,0, sizeof(sstr) );
  6613. loc = strstr(sstrtemp, "connectorId");
  6614. if(loc == NULL)
  6615. {
  6616. connectorIdIsNULL = TRUE;
  6617. }
  6618. else
  6619. {
  6620. while ((loc[strlen("connectorId")+2+c] != '}') && (loc[strlen("connectorId")+2+c] != ','))
  6621. {
  6622. sstr[c] = loc[strlen("connectorId")+2+c];
  6623. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6624. c++;
  6625. }
  6626. sstr[c] = '\0';
  6627. connectorIdInt = atoi(sstr);
  6628. }
  6629. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6630. {
  6631. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6632. goto end;
  6633. }
  6634. //****************idTag*******************/
  6635. c = 0;
  6636. memset(sstr ,0, sizeof(sstr) );
  6637. loc = strstr(sstrtemp, "idTag");
  6638. while (loc[3+strlen("idTag")+c] != '\"')
  6639. {
  6640. sstr[c] = loc[3+strlen("idTag")+c];
  6641. c++;
  6642. }
  6643. sstr[c] = '\0';
  6644. strcpy(idTagstr,sstr);
  6645. //****************chargingProfile*******************/
  6646. c = 0;
  6647. memset(sstr ,0, sizeof(sstr) );
  6648. loc = strstr(sstrtemp, "chargingProfile");
  6649. if(loc == NULL)
  6650. {
  6651. chargingProfileIsNULL = TRUE;
  6652. }
  6653. else
  6654. {
  6655. //****************chargingProfileId*******************/
  6656. c=0;
  6657. loc = strstr(sstrtemp, "chargingProfileId");
  6658. memset(sstr ,0, sizeof(sstr) );
  6659. while ((loc[strlen("chargingProfileId")+2+c] != '}') && (loc[strlen("chargingProfileId")+2+c] != ','))
  6660. {
  6661. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6662. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6663. c++;
  6664. }
  6665. sstr[c] = '\0';
  6666. chargingProfileIdInt = atoi(sstr);
  6667. //****************transactionId*******************/
  6668. loc = strstr(sstrtemp, "transactionId");
  6669. if(loc == NULL)
  6670. {
  6671. transactionIdIsNULL = TRUE;
  6672. }
  6673. else
  6674. {
  6675. c=0;
  6676. memset(sstr ,0, sizeof(sstr) );
  6677. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  6678. {
  6679. sstr[c] = loc[strlen("transactionId")+2+c];
  6680. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6681. c++;
  6682. }
  6683. sstr[c] = '\0';
  6684. transactionIdInt = atoi(sstr);
  6685. }
  6686. //****************stackLevel*******************/
  6687. c=0;
  6688. loc = strstr(sstrtemp, "stackLevel");
  6689. memset(sstr ,0, sizeof(sstr) );
  6690. while ((loc[strlen("stackLevel")+2+c] != '}') && (loc[strlen("stackLevel")+2+c] != ','))
  6691. {
  6692. sstr[c] = loc[strlen("stackLevel")+2+c];
  6693. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6694. c++;
  6695. }
  6696. sstr[c] = '\0';
  6697. stackLevelInt = atoi(sstr);
  6698. //****************chargingProfilePurpose*******************/
  6699. c = 0;
  6700. memset(sstr ,0, sizeof(sstr) );
  6701. loc = strstr(sstrtemp, "chargingProfilePurpose");
  6702. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6703. {
  6704. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6705. c++;
  6706. }
  6707. sstr[c] = '\0';
  6708. strcpy(chargingProfilePurposestr,sstr);
  6709. //****************chargingProfileKind*******************/
  6710. c = 0;
  6711. memset(sstr ,0, sizeof(sstr) );
  6712. loc = strstr(sstrtemp, "chargingProfileKind");
  6713. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  6714. {
  6715. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  6716. c++;
  6717. }
  6718. sstr[c] = '\0';
  6719. strcpy(chargingProfileKindstr,sstr);
  6720. //****************recurrencyKind*******************/
  6721. loc = strstr(sstrtemp, "recurrencyKind");
  6722. if(loc == NULL)
  6723. {
  6724. recurrencyKindIsNULL = TRUE;
  6725. }
  6726. else
  6727. {
  6728. c = 0;
  6729. memset(sstr ,0, sizeof(sstr) );
  6730. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  6731. {
  6732. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  6733. c++;
  6734. }
  6735. sstr[c] = '\0';
  6736. strcpy(recurrencyKindstr,sstr);
  6737. }
  6738. //****************validFrom*******************/
  6739. loc = strstr(sstrtemp, "validFrom");
  6740. if(loc == NULL)
  6741. {
  6742. validFromIsNULL = TRUE;
  6743. }
  6744. else
  6745. {
  6746. c = 0;
  6747. memset(sstr ,0, sizeof(sstr) );
  6748. while (loc[3+strlen("validFrom")+c] != '\"')
  6749. {
  6750. sstr[c] = loc[3+strlen("validFrom")+c];
  6751. c++;
  6752. }
  6753. sstr[c] = '\0';
  6754. strcpy(validFromstr,sstr);
  6755. }
  6756. //****************validTo*******************/
  6757. loc = strstr(sstrtemp, "validTo");
  6758. if(loc == NULL)
  6759. {
  6760. validToIsNULL = TRUE;
  6761. }
  6762. else
  6763. {
  6764. c = 0;
  6765. memset(sstr ,0, sizeof(sstr) );
  6766. while (loc[3+strlen("validTo")+c] != '\"')
  6767. {
  6768. sstr[c] = loc[3+strlen("validTo")+c];
  6769. c++;
  6770. }
  6771. sstr[c] = '\0';
  6772. strcpy(validTostr,sstr);
  6773. }
  6774. //****************chargingSchedule*******************/
  6775. loc = strstr(sstrtemp, "chargingSchedule");
  6776. if(loc != NULL)
  6777. {
  6778. //****************duration*******************/
  6779. loc = strstr(sstrtemp, "duration");
  6780. if(loc == NULL)
  6781. {
  6782. durationIsNULL = TRUE;
  6783. }
  6784. else
  6785. {
  6786. c=0;
  6787. memset(sstr ,0, sizeof(sstr) );
  6788. while ((loc[strlen("duration")+2+c] != '}') && (loc[strlen("duration")+2+c] != ','))
  6789. {
  6790. sstr[c] = loc[strlen("duration")+2+c];
  6791. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6792. c++;
  6793. }
  6794. sstr[c] = '\0';
  6795. durationInt = atoi(sstr);
  6796. }
  6797. //****************startSchedule******************/
  6798. loc = strstr(sstrtemp, "startSchedule");
  6799. if(loc == NULL)
  6800. {
  6801. startScheduleIsNULL = TRUE;
  6802. }
  6803. else
  6804. {
  6805. c = 0;
  6806. memset(sstr ,0, sizeof(sstr) );
  6807. while (loc[3+strlen("startSchedule")+c] != '\"')
  6808. {
  6809. sstr[c] = loc[3+strlen("startSchedule")+c];
  6810. c++;
  6811. }
  6812. sstr[c] = '\0';
  6813. strcpy(startSchedulestr,sstr);
  6814. }
  6815. //****************chargingRateUnit*******************/
  6816. c = 0;
  6817. memset(sstr ,0, sizeof(sstr) );
  6818. loc = strstr(sstrtemp, "chargingRateUnit");
  6819. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  6820. {
  6821. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  6822. c++;
  6823. }
  6824. sstr[c] = '\0';
  6825. strcpy(chargingRateUnitstr,sstr);
  6826. //****************minChargingRate*******************/
  6827. loc = strstr(sstrtemp, "minChargingRate");
  6828. if(loc == NULL)
  6829. {
  6830. minChargingRateIsNULL = TRUE;
  6831. }
  6832. else
  6833. {
  6834. c=0;
  6835. memset(sstr ,0, sizeof(sstr) );
  6836. while ((loc[strlen("minChargingRate")+2+c] != '}') && (loc[strlen("minChargingRate")+2+c] != ','))
  6837. {
  6838. sstr[c] = loc[strlen("minChargingRate")+2+c];
  6839. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6840. c++;
  6841. }
  6842. sstr[c] = '\0';
  6843. minChargingRateflaot = atof(sstr);
  6844. }
  6845. //****************chargingSchedulePeriod count*******************/
  6846. int what_len = strlen("startPeriod");
  6847. char *where = sstrtemp;
  6848. while ((where = strstr(where, "startPeriod"))) {
  6849. where += what_len;
  6850. chargingSchedulePeriodCount++;
  6851. }
  6852. where = sstrtemp;
  6853. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  6854. {
  6855. //****************startPeriod*******************/
  6856. c=0;
  6857. loc = strstr(where, "startPeriod");
  6858. memset(sstr ,0, sizeof(sstr) );
  6859. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  6860. {
  6861. sstr[c] = loc[strlen("startPeriod")+2+c];
  6862. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6863. c++;
  6864. }
  6865. sstr[c] = '\0';
  6866. startPeriodInt[periodNums] = atoi(sstr);
  6867. //****************limit*******************/
  6868. c=0;
  6869. loc = strstr(where, "limit");
  6870. memset(sstr ,0, sizeof(sstr) );
  6871. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  6872. {
  6873. sstr[c] = loc[strlen("limit")+2+c];
  6874. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6875. c++;
  6876. }
  6877. sstr[c] = '\0';
  6878. limitflaot[periodNums] = atof(sstr);
  6879. //****************numberPhases*******************/
  6880. loc = strstr(where, "numberPhases");
  6881. if(loc == NULL)
  6882. {
  6883. numberPhasesIsNULL = TRUE;
  6884. }
  6885. else
  6886. {
  6887. c=0;
  6888. memset(sstr ,0, sizeof(sstr) );
  6889. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  6890. {
  6891. sstr[c] = loc[strlen("numberPhases")+2+c];
  6892. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6893. c++;
  6894. }
  6895. sstr[c] = '\0';
  6896. numberPhasesInt[periodNums] = atoi(sstr);
  6897. }
  6898. where = loc;
  6899. } // END FOR chargingSchedulePeriodCount
  6900. }// END IF chargingSchedule
  6901. } // END chargingProfile
  6902. /*
  6903. enum _SYSTEM_STATUS
  6904. {
  6905. S_BOOTING = 0,
  6906. S_IDLE, = 1
  6907. S_AUTHORIZING, =2
  6908. S_REASSIGN_CHECK, =3
  6909. S_REASSIGN, =4
  6910. S_PRECHARGE, =5
  6911. S_PREPARING_FOR_EV, =6
  6912. S_PREPARING_FOR_EVSE, =7
  6913. S_CHARGING, =8
  6914. S_TERMINATING, =9
  6915. S_COMPLETE, =10
  6916. S_ALARM, =11
  6917. S_FAULT =12
  6918. }
  6919. */
  6920. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber/*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  6921. {
  6922. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s" , idTagstr);
  6923. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  6924. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault 8: Reserved
  6925. //check Transaction active
  6926. if(gunType[connectorIdInt -1] == 'J')
  6927. {
  6928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6929. {
  6930. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6931. }
  6932. else
  6933. {
  6934. tempIndex = connectorIdInt -1;
  6935. }
  6936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6937. {
  6938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6939. {
  6940. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6941. {
  6942. //Reserved
  6943. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6944. }
  6945. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6946. {
  6947. //Reserved
  6948. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6949. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6950. goto end;
  6951. }
  6952. else
  6953. {
  6954. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6955. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6956. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6957. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6958. {
  6959. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6960. goto end;
  6961. }
  6962. }//END FOR ELSE
  6963. }
  6964. }// END FOR CHAdeMO_QUANTITY
  6965. }
  6966. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6967. {
  6968. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6969. {
  6970. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6971. }
  6972. else
  6973. {
  6974. tempIndex = connectorIdInt -1;
  6975. }
  6976. for (int index = 0; index < CCS_QUANTITY; index++)
  6977. {
  6978. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6979. {
  6980. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  6981. {
  6982. //Reserved
  6983. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6984. }
  6985. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  6986. {
  6987. //Reserved
  6988. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6989. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6990. goto end;
  6991. }
  6992. else
  6993. {
  6994. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6995. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6996. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6997. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6998. {
  6999. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7000. goto end;
  7001. }
  7002. }// END FOR ELSE
  7003. }
  7004. }// END FOR CCS_QUANTITY
  7005. }
  7006. else if(gunType[connectorIdInt -1] == 'G')
  7007. {
  7008. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7009. {
  7010. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7011. }
  7012. else
  7013. {
  7014. tempIndex = connectorIdInt -1;
  7015. }
  7016. for (int index = 0; index < GB_QUANTITY; index++)
  7017. {
  7018. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7019. {
  7020. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7021. {
  7022. //Reserved
  7023. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7024. }
  7025. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7026. {
  7027. //Reserved
  7028. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7029. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7030. goto end;
  7031. }
  7032. else
  7033. {
  7034. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7035. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7036. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7037. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7038. {
  7039. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7040. goto end;
  7041. }
  7042. }// END FOR ELSE
  7043. }
  7044. } // END FOR GB_QUANTITY
  7045. }
  7046. else
  7047. {
  7048. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7049. {
  7050. tempIndex = 2;
  7051. }
  7052. else
  7053. {
  7054. tempIndex = connectorIdInt -1;
  7055. }
  7056. for (int index = 0; index < AC_QUANTITY; index++)
  7057. {
  7058. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7059. {
  7060. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) == 0))
  7061. {
  7062. //Reserved
  7063. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7064. }
  7065. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, idTagstr) != 0))
  7066. {
  7067. //Reserved
  7068. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7069. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7070. goto end;
  7071. }
  7072. else
  7073. {
  7074. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7075. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7076. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7077. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7078. {
  7079. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7080. goto end;
  7081. }
  7082. }//END FOR ELSE
  7083. }
  7084. }// END FOR AC_QUANTITY
  7085. }
  7086. if(chargingProfileIsNULL == FALSE)
  7087. {
  7088. //ChargingProfile
  7089. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  7090. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s" ,chargingProfileKindstr);
  7091. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s" ,chargingProfilePurposestr);
  7092. if(recurrencyKindIsNULL == FALSE) //OPTION
  7093. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind, "%s" ,recurrencyKindstr);
  7094. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  7095. if(transactionIdIsNULL == FALSE) // OPTION
  7096. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  7097. if(validFromIsNULL == FALSE) // OPTION
  7098. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom, "%s" ,validFromstr);
  7099. if(validToIsNULL == FALSE) //OPTION
  7100. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo, "%s" ,validTostr);
  7101. //ChargingSchedule
  7102. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit, "%s" ,chargingRateUnitstr);
  7103. if(durationIsNULL == FALSE) //OPTION
  7104. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  7105. if(minChargingRateIsNULL == FALSE) //OPTION
  7106. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateflaot;
  7107. if(startScheduleIsNULL == FALSE) //OPTION
  7108. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s" ,startSchedulestr);
  7109. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  7110. {
  7111. //ChargingSchedulePeriod
  7112. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums] ;
  7113. if(numberPhasesIsNULL == FALSE)
  7114. {
  7115. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  7116. }
  7117. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  7118. }
  7119. if(strcmp(chargingProfilePurposestr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7120. {
  7121. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7122. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7123. //memset idTag
  7124. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7125. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7126. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7127. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7128. }
  7129. else
  7130. {
  7131. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7132. }
  7133. }
  7134. else
  7135. {
  7136. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7137. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7138. //memset idTag
  7139. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7140. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7141. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7142. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, idTagstr);
  7143. }
  7144. }
  7145. else
  7146. {
  7147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7148. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7149. }
  7150. end:
  7151. if(connectorIdIsNULL == FALSE)
  7152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7153. strcpy((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, idTagstr);
  7154. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7155. //OCPP send RemoteStartConfirmation by first.
  7156. sendRemoteStartConfirmation(uuid, comfirmstr);
  7157. return result;
  7158. }
  7159. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7160. {
  7161. mtrace();
  7162. int result = FAIL;
  7163. int match = FALSE;
  7164. int GunNO = 0;
  7165. int tempIndex = 0;
  7166. int transactionIdInt=0;
  7167. int transactionIdIsNULL= FALSE;
  7168. char sstr[16]={ 0 },sstrtemp[50]={ 0 };//sstr[200]={ 0 };
  7169. int c = 0;
  7170. char *loc;
  7171. char comfirmstr[20];
  7172. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7173. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7174. if(server_pending == TRUE)
  7175. {
  7176. return 0;
  7177. }
  7178. strcpy(sstrtemp, stringtrimspace(payload));
  7179. c=0;
  7180. loc = strstr(sstrtemp, "transactionId");
  7181. if(loc == NULL)
  7182. {
  7183. transactionIdIsNULL= TRUE;
  7184. }
  7185. else
  7186. {
  7187. memset(sstr ,0, sizeof(sstr) );
  7188. while ((loc[strlen("transactionId")+2+c] != '}') && (loc[strlen("transactionId")+2+c] != ','))
  7189. {
  7190. sstr[c] = loc[strlen("transactionId")+2+c];
  7191. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7192. c++;
  7193. }
  7194. sstr[c] = '\0';
  7195. transactionIdInt = atoi(sstr);
  7196. }
  7197. if(transactionIdIsNULL == FALSE)
  7198. {
  7199. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7200. {
  7201. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7202. {
  7203. //check Transaction active
  7204. if(gunType[gun_index] == 'J')
  7205. {
  7206. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7207. {
  7208. tempIndex = ((gun_index==2) ? 1: 0);
  7209. }
  7210. else
  7211. {
  7212. tempIndex = gun_index;
  7213. }
  7214. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7215. {
  7216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7217. {
  7218. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7219. {
  7220. match = TRUE;
  7221. GunNO = gun_index;
  7222. }
  7223. }
  7224. }// END FOR CHAdeMO_QUANTITY
  7225. }
  7226. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7227. {
  7228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7229. {
  7230. tempIndex = ((gun_index==2) ? 1: 0);
  7231. }
  7232. else
  7233. {
  7234. tempIndex = gun_index;
  7235. }
  7236. for (int index = 0; index < CCS_QUANTITY; index++)
  7237. {
  7238. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7239. {
  7240. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7241. {
  7242. match = TRUE;
  7243. GunNO = gun_index;
  7244. }
  7245. }
  7246. }// END FOR CCS_QUANTITY
  7247. }
  7248. else if(gunType[gun_index] == 'G')
  7249. {
  7250. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7251. {
  7252. tempIndex = ((gun_index==2) ? 1: 0);
  7253. }
  7254. else
  7255. {
  7256. tempIndex = gun_index;
  7257. }
  7258. for (int index = 0; index < GB_QUANTITY; index++)
  7259. {
  7260. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7261. {
  7262. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7263. {
  7264. match = TRUE;
  7265. GunNO = gun_index;
  7266. }
  7267. }
  7268. }// END FOR GB_QUANTITY
  7269. }
  7270. else
  7271. {
  7272. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7273. {
  7274. tempIndex = 2;
  7275. }
  7276. else
  7277. {
  7278. tempIndex = gun_index;
  7279. }
  7280. for (int index = 0; index < AC_QUANTITY; index++)
  7281. {
  7282. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7283. {
  7284. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7285. {
  7286. match = TRUE;
  7287. GunNO = gun_index;
  7288. }
  7289. }
  7290. }// END FOR CHAdeMO_QUANTITY
  7291. } // END FOR AC ELSE
  7292. }// CHECK IF ResponseTransactionId == transactionIdInt
  7293. }//END FOR
  7294. if( match == TRUE)
  7295. {
  7296. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7297. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7298. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7299. }
  7300. else
  7301. {
  7302. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7303. }
  7304. }
  7305. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7306. return result;
  7307. }
  7308. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7309. {
  7310. mtrace();
  7311. int result = FAIL;
  7312. int connectorIdInt=0, reservationIdInt=0;
  7313. int tempIndex = 0;
  7314. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7315. char comfirmstr[20]={0};
  7316. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7317. int c = 0;
  7318. char *loc;
  7319. //char *ptr;
  7320. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7321. strcpy(sstrtemp, stringtrimspace(payload));
  7322. //***(1)connectorId ****/
  7323. c=0;
  7324. loc = strstr(sstrtemp, "connectorId");
  7325. memset(sstr ,0, sizeof(sstr) );
  7326. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7327. {
  7328. sstr[c] = loc[strlen("connectorId")+2+c];
  7329. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7330. c++;
  7331. }
  7332. sstr[c] = '\0';
  7333. connectorIdInt = atoi(sstr);
  7334. //***(2)expiryDate ****/
  7335. loc = strstr(sstrtemp, "expiryDate");
  7336. memset(sstr ,0, sizeof(sstr) );
  7337. c = 0;
  7338. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7339. {
  7340. sstr[c] = loc[3+strlen("expiryDate")+c];
  7341. c++;
  7342. }
  7343. sstr[c] = '\0';
  7344. strcpy(expiryDatestr, sstr);
  7345. //***(3)idTag ****/
  7346. loc = strstr(sstrtemp, "idTag");
  7347. memset(sstr ,0, sizeof(sstr) );
  7348. c = 0;
  7349. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7350. {
  7351. sstr[c] = loc[3+strlen("idTag")+c];
  7352. c++;
  7353. }
  7354. sstr[c] = '\0';
  7355. strcpy(idTagstr, sstr);
  7356. //***(4)parentIdTag ****/
  7357. loc = strstr(sstrtemp, "parentIdTag");
  7358. memset(sstr ,0, sizeof(sstr) );
  7359. c = 0;
  7360. if(loc == NULL)
  7361. {
  7362. strcpy(parentIdTagstr, "");
  7363. }
  7364. else
  7365. {
  7366. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7367. {
  7368. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7369. c++;
  7370. }
  7371. sstr[c] = '\0';
  7372. strcpy(parentIdTagstr, sstr);
  7373. }
  7374. //***(5)reservationId ****/
  7375. c=0;
  7376. loc = strstr(sstrtemp, "reservationId");
  7377. memset(sstr ,0, sizeof(sstr) );
  7378. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7379. {
  7380. sstr[c] = loc[strlen("reservationId")+2+c];
  7381. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7382. c++;
  7383. }
  7384. sstr[c] = '\0';
  7385. reservationIdInt = atoi(sstr);
  7386. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7387. /*
  7388. enum SYSTEM_STATUS
  7389. {
  7390. SYS_MODE_BOOTING = 0,
  7391. SYS_MODE_IDLE = 1,
  7392. SYS_MODE_AUTHORIZING = 2,
  7393. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7394. SYS_MODE_REASSIGN = 4,
  7395. SYS_MODE_PREPARING = 5,
  7396. SYS_MODE_PREPARE_FOR_EV = 6,
  7397. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7398. SYS_MODE_CHARGING = 8,
  7399. SYS_MODE_TERMINATING = 9,
  7400. SYS_MODE_COMPLETE = 10,
  7401. SYS_MODE_ALARM = 11,
  7402. SYS_MODE_FAULT = 12,
  7403. SYS_MODE_RESERVATION = 13,
  7404. SYS_MODE_BOOKING = 14,
  7405. SYS_MODE_MAINTAIN = 15,
  7406. SYS_MODE_DEBUG = 16,
  7407. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7408. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7409. SYS_MODE_UPDATE = 19
  7410. };
  7411. */
  7412. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7413. {
  7414. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7415. goto end;
  7416. }
  7417. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7418. {
  7419. //check Transaction active
  7420. if(gunType[connectorIdInt -1] == 'J')
  7421. {
  7422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7423. {
  7424. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7425. }
  7426. else
  7427. {
  7428. tempIndex = connectorIdInt -1;
  7429. }
  7430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7431. {
  7432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7433. {
  7434. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7435. {
  7436. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7437. {
  7438. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7439. {
  7440. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7441. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7442. }
  7443. 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'))
  7444. {
  7445. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7446. }
  7447. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7448. {
  7449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7450. }
  7451. else
  7452. {
  7453. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7454. }
  7455. }
  7456. 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
  7457. {
  7458. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7459. }
  7460. }
  7461. else
  7462. {
  7463. //replace reservation
  7464. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7465. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7466. }
  7467. }
  7468. } // END FOR CHAdeMO_QUANTITY
  7469. }
  7470. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7471. {
  7472. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7473. {
  7474. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7475. }
  7476. else
  7477. {
  7478. tempIndex = connectorIdInt -1;
  7479. }
  7480. for (int index = 0; index < CCS_QUANTITY; index++)
  7481. {
  7482. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7483. {
  7484. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7485. {
  7486. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7487. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7488. {
  7489. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7490. {
  7491. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7492. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7493. }
  7494. 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'))
  7495. {
  7496. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7497. }
  7498. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7499. {
  7500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7501. }
  7502. else
  7503. {
  7504. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7505. }
  7506. }
  7507. 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
  7508. {
  7509. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7510. }
  7511. }
  7512. else
  7513. {
  7514. //replace reservation
  7515. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7516. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7517. }
  7518. }
  7519. } // END FOR CCS_QUANTITY
  7520. }
  7521. else if(gunType[connectorIdInt -1] == 'G')
  7522. {
  7523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7524. {
  7525. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7526. }
  7527. else
  7528. {
  7529. tempIndex = connectorIdInt -1;
  7530. }
  7531. for (int index = 0; index < GB_QUANTITY; index++)
  7532. {
  7533. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7534. {
  7535. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7536. {
  7537. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7538. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7539. {
  7540. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7541. {
  7542. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7543. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7544. }
  7545. 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'))
  7546. {
  7547. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7548. }
  7549. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7550. {
  7551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7552. }
  7553. else
  7554. {
  7555. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7556. }
  7557. }
  7558. 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
  7559. {
  7560. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7561. }
  7562. }
  7563. else
  7564. {
  7565. //replace reservation
  7566. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7567. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7568. }
  7569. }
  7570. }// END FOR GB_QUANTITY
  7571. }
  7572. else
  7573. {
  7574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7575. {
  7576. tempIndex = 2;
  7577. }
  7578. else
  7579. {
  7580. tempIndex = (connectorIdInt -1);
  7581. }
  7582. for (int index = 0; index < AC_QUANTITY; index++)
  7583. {
  7584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7585. {
  7586. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7587. {
  7588. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7589. {
  7590. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7591. {
  7592. 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))
  7593. {
  7594. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7595. }
  7596. else
  7597. {
  7598. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7600. }
  7601. }
  7602. 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'))
  7603. {
  7604. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7605. }
  7606. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7607. {
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7609. }
  7610. else
  7611. {
  7612. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7613. }
  7614. }
  7615. 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
  7616. {
  7617. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7618. }
  7619. }
  7620. else
  7621. {
  7622. //replace reservation
  7623. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7624. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7625. }
  7626. }
  7627. } // END FOR AC_QUANTITY
  7628. }
  7629. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7630. }
  7631. else if(connectorIdInt == 0)
  7632. {
  7633. //check Transaction active
  7634. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7635. {
  7636. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7637. {
  7638. 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'))
  7639. {
  7640. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7641. goto end;
  7642. }
  7643. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7644. {
  7645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7646. goto end;
  7647. }
  7648. 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
  7649. {
  7650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7651. goto end;
  7652. }
  7653. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7654. {
  7655. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7656. goto end;
  7657. }
  7658. }
  7659. }// END FOR CHAdeMO_QUANTITY
  7660. for (int index = 0; index < CCS_QUANTITY; index++)
  7661. {
  7662. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7663. {
  7664. 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'))
  7665. {
  7666. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7667. goto end;
  7668. }
  7669. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7670. {
  7671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7672. goto end;
  7673. }
  7674. 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
  7675. {
  7676. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7677. goto end;
  7678. }
  7679. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7680. {
  7681. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7682. goto end;
  7683. }
  7684. }
  7685. } // END FOR CCS_QUANTITY
  7686. for (int index = 0; index < GB_QUANTITY; index++)
  7687. {
  7688. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7689. {
  7690. 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'))
  7691. {
  7692. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7693. goto end;
  7694. }
  7695. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7696. {
  7697. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7698. goto end;
  7699. }
  7700. 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
  7701. {
  7702. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7703. goto end;
  7704. }
  7705. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7706. {
  7707. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7708. goto end;
  7709. }
  7710. }
  7711. } // END FOR GB_QUANTITY
  7712. for (int index = 0; index < AC_QUANTITY; index++)
  7713. {
  7714. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7715. {
  7716. 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'))
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7719. goto end;
  7720. }
  7721. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7722. {
  7723. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7724. goto end;
  7725. }
  7726. 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
  7727. {
  7728. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7729. goto end;
  7730. }
  7731. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7732. {
  7733. 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))
  7734. {
  7735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7736. goto end;
  7737. }
  7738. }
  7739. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7740. {
  7741. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7742. goto end;
  7743. }
  7744. }
  7745. }// END FOR AC_QUANTITY
  7746. //The connectorId is 0
  7747. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7748. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7749. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7750. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7751. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7752. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7753. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7754. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7755. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7756. result = TRUE;
  7757. return result;
  7758. }
  7759. else
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7762. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7763. }
  7764. if(strcmp(comfirmstr,"Accepted") == 0)
  7765. {
  7766. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7767. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7768. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7769. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7770. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7771. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7772. result = TRUE;
  7773. return result;
  7774. }
  7775. end:
  7776. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7777. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7778. return result;
  7779. }
  7780. int handleResetRequest(char *uuid, char *payload)
  7781. {
  7782. mtrace();
  7783. int result = FAIL;
  7784. char sstr[10]={0},sstrtemp[30]={ 0 };
  7785. char typestr[10]={0};
  7786. char comfirmstr[20]={0};
  7787. int c = 0;
  7788. char *loc;
  7789. DEBUG_INFO("handleResetRequest...\n");
  7790. strcpy(sstrtemp, stringtrimspace(payload));
  7791. loc = strstr(sstrtemp, "type");
  7792. memset(sstr ,0, sizeof(sstr) );
  7793. c = 0;
  7794. while (loc[3+strlen("type")+c] != '\"')
  7795. {
  7796. sstr[c] = loc[3+strlen("type")+c];
  7797. c++;
  7798. }
  7799. sstr[c] = '\0';
  7800. strcpy(typestr,sstr);
  7801. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7802. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7803. {
  7804. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7805. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7806. result = TRUE;
  7807. return result;
  7808. }
  7809. else
  7810. {
  7811. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7812. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7813. goto errorend;
  7814. }
  7815. errorend:
  7816. sendResetConfirmation(uuid, comfirmstr);
  7817. return result;
  7818. }
  7819. int handleSendLocalListRequest(char *uuid, char *payload)
  7820. {
  7821. mtrace();
  7822. int result = FAIL;
  7823. int listVersionInt;
  7824. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7825. char listsearch[]="listVersion";
  7826. char updateTypesearch[]="updateType";
  7827. char localAuthorizationListsearch[]="localAuthorizationList";
  7828. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7829. char CardList[500][160]={0};
  7830. char updateTypestr[15]={0};
  7831. char idTagstr[20]={0};
  7832. char parentIdTag[20]={0};
  7833. char expiryDate[30]={0};
  7834. char idTagstatus[16]={0};
  7835. int c = 0;
  7836. int i = 0;
  7837. char *delim1 = "}";
  7838. char * pch;
  7839. char *loc;
  7840. //char *ptr;
  7841. char comfirmstr[20];
  7842. //int n_localAuthorizations = 0;
  7843. int checkState_Faulted = FALSE;
  7844. DEBUG_INFO("handleSendLocalListRequest...\n");
  7845. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7846. {
  7847. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7848. goto end;
  7849. }
  7850. //check Charge Point state
  7851. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7852. {
  7853. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7854. {
  7855. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7856. }
  7857. }
  7858. for (int index = 0; index < CCS_QUANTITY; index++)
  7859. {
  7860. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7861. {
  7862. checkState_Faulted = TRUE; //OCPP Status
  7863. }
  7864. }
  7865. for (int index = 0; index < GB_QUANTITY; index++)
  7866. {
  7867. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7868. {
  7869. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7870. }
  7871. }
  7872. //check Charge Point state
  7873. for (int index = 0; index < AC_QUANTITY; index++)
  7874. {
  7875. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7876. {
  7877. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7878. }
  7879. }
  7880. if(checkState_Faulted == TRUE)
  7881. {
  7882. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7883. goto end;
  7884. }
  7885. //Filter payload space
  7886. strcpy(sstrtemp, stringtrimspace(payload));
  7887. //listVersion
  7888. c = 0;
  7889. loc = strstr(sstrtemp, listsearch);
  7890. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7891. {
  7892. sstr[c] = loc[strlen("listVersion")+2+c];
  7893. c++;
  7894. }
  7895. sstr[c] = '\0';
  7896. listVersionInt = atoi(sstr);
  7897. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7898. //updateType
  7899. loc = strstr(sstrtemp, updateTypesearch);
  7900. c = 0;
  7901. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7902. {
  7903. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7904. c++;
  7905. }
  7906. sstr[c] = '\0';
  7907. strcpy(updateTypestr, sstr);
  7908. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7909. //localAuthorizationList
  7910. memset(sstr ,0, sizeof(sstr) );
  7911. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7912. if(loc != NULL) // localAuthorizationList is not NULL
  7913. {
  7914. //Check UpdateType
  7915. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7916. {
  7917. //Local list full update
  7918. printf("Local list full update.\n");
  7919. OCPP_getListVerion();
  7920. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7921. {
  7922. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7923. goto end;
  7924. }
  7925. OCPP_cleanLocalList();
  7926. }
  7927. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7928. {
  7929. //Local list different update
  7930. printf("Local list different update.\n");
  7931. OCPP_getListVerion();
  7932. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7933. {
  7934. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7935. goto end;
  7936. }
  7937. }
  7938. else
  7939. {
  7940. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7941. goto end;
  7942. }
  7943. c = 0;
  7944. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7945. {
  7946. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7947. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7948. c++;
  7949. }
  7950. sstr[c] = '\0';
  7951. //DEBUG_INFO("sstr=%s\n", sstr);
  7952. //parsing strings to words
  7953. i = 0;
  7954. pch = strtok(sstr,delim1);
  7955. while (pch != NULL)
  7956. {
  7957. strcpy(CardList[i], pch);
  7958. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7959. pch = strtok (NULL, delim1);
  7960. i = i + 1;
  7961. }
  7962. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7963. //local Authorizations List Numbers
  7964. //n_localAuthorizations = i;
  7965. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7966. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7967. c= 0;
  7968. while(c < i) // i is CardList Number
  7969. {
  7970. //Search "IdToken"
  7971. memset(sstr ,0, sizeof(sstr) );
  7972. loc = strstr(CardList[c], "idTag");
  7973. int j = 0;
  7974. while (loc[3+strlen("idTag")+j] != '\"')
  7975. {
  7976. sstr[j] = loc[3+strlen("idTag")+j];
  7977. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7978. j++;
  7979. }
  7980. sstr[j] = '\0';
  7981. strcpy(idTagstr, sstr);
  7982. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7983. //Search "expiryDate"
  7984. memset(sstr ,0, sizeof(sstr) );
  7985. loc = strstr(CardList[c], "expiryDate");
  7986. j = 0;
  7987. if(loc != NULL)
  7988. {
  7989. while (loc[3+strlen("expiryDate")+j] != '\"')
  7990. {
  7991. sstr[j] = loc[3+strlen("expiryDate")+j];
  7992. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7993. j++;
  7994. }
  7995. sstr[j] = '\0';
  7996. strcpy(expiryDate, sstr);
  7997. }
  7998. else
  7999. {
  8000. strcpy(expiryDate, "");
  8001. }
  8002. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8003. //Search "parentIdTag"
  8004. memset(sstr ,0, sizeof(sstr) );
  8005. loc = strstr(CardList[c], "parentIdTag");
  8006. j = 0;
  8007. if(loc != NULL)
  8008. {
  8009. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8010. {
  8011. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8012. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8013. j++;
  8014. }
  8015. sstr[j] = '\0';
  8016. strcpy(parentIdTag, sstr);
  8017. }
  8018. else
  8019. {
  8020. strcpy(parentIdTag, "");
  8021. }
  8022. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8023. //Search "status"
  8024. memset(sstr ,0, sizeof(sstr) );
  8025. loc = strstr(CardList[c], "status");
  8026. j = 0;
  8027. while (loc[3+strlen("status")+j] != '\"')
  8028. {
  8029. sstr[j] = loc[3+strlen("status")+j];
  8030. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8031. j++;
  8032. }
  8033. sstr[j] = '\0';
  8034. strcpy(idTagstatus, sstr);
  8035. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8036. OCPP_getIdTag(idTagstr);
  8037. //OCPP_getIdTag("test"); For Test
  8038. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8039. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8040. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8041. {
  8042. //Local list full update
  8043. DEBUG_INFO("Local list full update.\n");
  8044. // update list
  8045. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8046. //DEBUG_INFO("Local list full update. 1\n");
  8047. //OCPP_get_TableAuthlocalAllData();
  8048. //DEBUG_INFO("Local list full update. 2\n");
  8049. }
  8050. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8051. {
  8052. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8053. }
  8054. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8055. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8056. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8057. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8058. c++;
  8059. }
  8060. }
  8061. else
  8062. {
  8063. //Check UpdateType
  8064. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8065. {
  8066. //Local list full update
  8067. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8068. OCPP_cleanLocalList();
  8069. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8070. goto end;
  8071. }
  8072. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8073. {
  8074. //Local list different update
  8075. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8076. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8077. goto end;
  8078. }
  8079. }
  8080. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8081. end:
  8082. sendSendLocalListConfirmation(uuid, comfirmstr);
  8083. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8084. return result;
  8085. }
  8086. #define MAX 200
  8087. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8088. {
  8089. mtrace();
  8090. int result = FAIL;
  8091. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8092. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8093. char chargingProfilePurposeStr[30]={0};
  8094. char chargingProfileKindStr[16]={0};
  8095. char recurrencyKindStr[10]={0};
  8096. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8097. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8098. int chargingSchedulePeriodCount = 0;
  8099. //int updateflag = FALSE;
  8100. char comfirmstr[20]={0};
  8101. int meet= FALSE;
  8102. char sstr[10]={0},sstrtemp[1600]={ 0 };
  8103. int c = 0;
  8104. char *loc;
  8105. FILE *fptr1;//, *fptr2;
  8106. //int lno=0;//, linectr = 0;
  8107. //int modifyflag = FALSE;
  8108. char filename[MAX]={0};
  8109. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8110. //int resultRename=0;
  8111. char rmFileCmd[50]={0};
  8112. char tempchargingProfilePurposeStr[30]={0};
  8113. char word[1600]={0};
  8114. int n_chargingProfile = 0;
  8115. //[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}}}]
  8116. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8117. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8118. //Filter string space
  8119. strcpy(sstrtemp, stringtrimspace(payload));
  8120. //*********************connectorId***************************/
  8121. loc = strstr(sstrtemp, "connectorId");
  8122. c = 0;
  8123. memset(sstr ,0, sizeof(sstr) );
  8124. while (loc[strlen("connectorId")+2+c] != ',')
  8125. {
  8126. sstr[c] = loc[strlen("connectorId")+2+c];
  8127. c++;
  8128. }
  8129. sstr[c] = '\0';
  8130. connectorIdInt = atoi(sstr);
  8131. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8132. {
  8133. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8134. }
  8135. else
  8136. {
  8137. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ConnectorId = connectorIdInt;
  8138. }
  8139. //DEBUG_INFO("handleSetChargingProfileRequest -1\n");
  8140. //*********************chargingProfileId***************************/
  8141. loc = strstr(sstrtemp, "chargingProfileId");
  8142. c = 0;
  8143. memset(sstr ,0, sizeof(sstr) );
  8144. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8145. {
  8146. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8147. c++;
  8148. }
  8149. sstr[c] = '\0';
  8150. chargingProfileIdInt = atoi(sstr);
  8151. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8152. {
  8153. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8154. }
  8155. else
  8156. {
  8157. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8158. }
  8159. //DEBUG_INFO("handleSetChargingProfileRequest -2\n");
  8160. //*********************transactionId***************************/
  8161. loc = strstr(sstrtemp, "transactionId");
  8162. if(loc != NULL)
  8163. {
  8164. c = 0;
  8165. memset(sstr ,0, sizeof(sstr) );
  8166. while (loc[strlen("transactionId")+2+c] != ',')
  8167. {
  8168. sstr[c] = loc[strlen("transactionId")+2+c];
  8169. c++;
  8170. }
  8171. sstr[c] = '\0';
  8172. transactionIdInt = atoi(sstr);
  8173. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8174. {
  8175. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8176. }
  8177. else
  8178. {
  8179. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8180. }
  8181. }
  8182. //DEBUG_INFO("handleSetChargingProfileRequest -3\n");
  8183. //*********************stackLevel***************************/
  8184. loc = strstr(sstrtemp, "stackLevel");
  8185. c = 0;
  8186. memset(sstr ,0, sizeof(sstr) );
  8187. while (loc[strlen("stackLevel")+2+c] != ',')
  8188. {
  8189. sstr[c] = loc[strlen("stackLevel")+2+c];
  8190. c++;
  8191. }
  8192. sstr[c] = '\0';
  8193. stackLevelInt = atoi(sstr);
  8194. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8195. {
  8196. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8197. }
  8198. else
  8199. {
  8200. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8201. }
  8202. //DEBUG_INFO("handleSetChargingProfileRequest -4\n");
  8203. //*********************chargingProfilePurpose***************************/
  8204. loc = strstr(sstrtemp, "chargingProfilePurpose");
  8205. c = 0;
  8206. memset(sstr ,0, sizeof(sstr) );
  8207. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8208. {
  8209. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8210. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8211. c++;
  8212. }
  8213. sstr[c] = '\0';
  8214. strcpy(chargingProfilePurposeStr,sstr);
  8215. //DEBUG_INFO("chargingProfilePurposeStr=%s\n",chargingProfilePurposeStr);
  8216. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8217. {
  8218. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8219. }
  8220. else
  8221. {
  8222. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8223. }
  8224. //DEBUG_INFO("handleSetChargingProfileRequest -6\n");
  8225. //*********************chargingProfileKind***************************/
  8226. loc = strstr(sstrtemp, "chargingProfileKind");
  8227. c = 0;
  8228. memset(sstr ,0, sizeof(sstr) );
  8229. while (loc[3+strlen("chargingProfileKind")+c] != '\"')
  8230. {
  8231. sstr[c] = loc[3+strlen("chargingProfileKind")+c];
  8232. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8233. c++;
  8234. }
  8235. sstr[c] = '\0';
  8236. strcpy(chargingProfileKindStr,sstr);
  8237. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8238. {
  8239. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8240. }
  8241. else
  8242. {
  8243. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8244. }
  8245. //DEBUG_INFO("handleSetChargingProfileRequest -7\n");
  8246. //*********************recurrencyKind***************************/
  8247. loc = strstr(sstrtemp, "recurrencyKind");
  8248. if(loc != NULL)
  8249. {
  8250. c = 0;
  8251. memset(sstr ,0, sizeof(sstr) );
  8252. while (loc[3+strlen("recurrencyKind")+c] != '\"')
  8253. {
  8254. sstr[c] = loc[3+strlen("recurrencyKind")+c];
  8255. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8256. c++;
  8257. }
  8258. sstr[c] = '\0';
  8259. strcpy(recurrencyKindStr,sstr);
  8260. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8261. {
  8262. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8263. }
  8264. else
  8265. {
  8266. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8267. }
  8268. }
  8269. else
  8270. {
  8271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8272. {
  8273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, "");
  8274. }
  8275. else
  8276. {
  8277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, "");
  8278. }
  8279. }
  8280. //DEBUG_INFO("handleSetChargingProfileRequest -8\n");
  8281. //*********************validFrom***************************/
  8282. loc = strstr(sstrtemp, "validFrom");
  8283. if(loc != NULL)
  8284. {
  8285. c = 0;
  8286. memset(sstr ,0, sizeof(sstr) );
  8287. while (loc[3+strlen("validFrom")+c] != '\"')
  8288. {
  8289. sstr[c] = loc[3+strlen("validFrom")+c];
  8290. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8291. c++;
  8292. }
  8293. sstr[c] = '\0';
  8294. strcpy(validFromStr,sstr);
  8295. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8296. {
  8297. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8298. }
  8299. else
  8300. {
  8301. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8302. }
  8303. }
  8304. else
  8305. {
  8306. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8307. {
  8308. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, "");
  8309. }
  8310. else
  8311. {
  8312. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, "");
  8313. }
  8314. }
  8315. //DEBUG_INFO("handleSetChargingProfileRequest -9\n");
  8316. //*********************validTo***************************/
  8317. loc = strstr(sstrtemp, "validTo");
  8318. if(loc != NULL)
  8319. {
  8320. c = 0;
  8321. memset(sstr ,0, sizeof(sstr) );
  8322. while (loc[3+strlen("validTo")+c] != '\"')
  8323. {
  8324. sstr[c] = loc[3+strlen("validTo")+c];
  8325. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8326. c++;
  8327. }
  8328. sstr[c] = '\0';
  8329. strcpy(validToStr,sstr);
  8330. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8331. {
  8332. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8333. }
  8334. else
  8335. {
  8336. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8337. }
  8338. }
  8339. else
  8340. {
  8341. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8342. {
  8343. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, "");
  8344. }
  8345. else
  8346. {
  8347. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, "");
  8348. }
  8349. }
  8350. //DEBUG_INFO("handleSetChargingProfileRequest -10\n");
  8351. //*********************duration***************************/
  8352. loc = strstr(sstrtemp, "duration");
  8353. if(loc != NULL)
  8354. {
  8355. c = 0;
  8356. memset(sstr ,0, sizeof(sstr) );
  8357. while (loc[strlen("duration")+2+c] != ',')
  8358. {
  8359. sstr[c] = loc[strlen("duration")+2+c];
  8360. c++;
  8361. }
  8362. sstr[c] = '\0';
  8363. durationInt = atoi(sstr);
  8364. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8365. {
  8366. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8367. }
  8368. else
  8369. {
  8370. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8371. }
  8372. }
  8373. else
  8374. {
  8375. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8376. {
  8377. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = 0;
  8378. }
  8379. else
  8380. {
  8381. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = 0;
  8382. }
  8383. }
  8384. //DEBUG_INFO("handleSetChargingProfileRequest -11\n");
  8385. //*********************startSchedule***************************/
  8386. loc = strstr(sstrtemp, "startSchedule");
  8387. if(loc != NULL)
  8388. {
  8389. c = 0;
  8390. memset(sstr ,0, sizeof(sstr) );
  8391. while (loc[3+strlen("startSchedule")+c] != '\"')
  8392. {
  8393. sstr[c] = loc[3+strlen("startSchedule")+c];
  8394. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8395. c++;
  8396. }
  8397. sstr[c] = '\0';
  8398. strcpy(startScheduleStr,sstr);
  8399. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8400. {
  8401. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8402. }
  8403. else
  8404. {
  8405. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8406. }
  8407. }
  8408. else
  8409. {
  8410. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8411. {
  8412. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8413. }
  8414. else
  8415. {
  8416. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,"");
  8417. }
  8418. }
  8419. //DEBUG_INFO("handleSetChargingProfileRequest -12\n");
  8420. //*********************chargingRateUnit***************************/
  8421. loc = strstr(sstrtemp, "chargingRateUnit");
  8422. if(loc != NULL)
  8423. {
  8424. c = 0;
  8425. memset(sstr ,0, sizeof(sstr) );
  8426. while (loc[3+strlen("chargingRateUnit")+c] != '\"')
  8427. {
  8428. sstr[c] = loc[3+strlen("chargingRateUnit")+c];
  8429. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8430. c++;
  8431. }
  8432. sstr[c] = '\0';
  8433. strcpy(chargingRateUnitStr,sstr);
  8434. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8435. {
  8436. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8437. }
  8438. else
  8439. {
  8440. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8441. }
  8442. }
  8443. //DEBUG_INFO("handleSetChargingProfileRequest -13\n");
  8444. //****************chargingSchedulePeriod count start*******************/
  8445. int what_len = strlen("startPeriod");
  8446. char tempChargingProfile[1600]={0};
  8447. strcpy(tempChargingProfile,(const char*)sstrtemp);
  8448. char *where = tempChargingProfile;
  8449. if (what_len)
  8450. {
  8451. while ((where = strstr(where, "startPeriod"))) {
  8452. where += what_len;
  8453. chargingSchedulePeriodCount++;
  8454. }
  8455. }
  8456. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8457. {
  8458. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8459. goto end;
  8460. }
  8461. //DEBUG_INFO("chargingSchedulePeriodCount=%d\n",chargingSchedulePeriodCount);
  8462. //where = payload;
  8463. int templength = 0;
  8464. //int searchstart = 0;
  8465. for(int periodNums=0; periodNums < chargingSchedulePeriodCount; periodNums++)
  8466. {
  8467. //****************startPeriod*******************/
  8468. c=0;
  8469. loc = strstr(tempChargingProfile + templength, "startPeriod");
  8470. memset(sstr ,0, sizeof(sstr) );
  8471. while ((loc[strlen("startPeriod")+2+c] != '}') && (loc[strlen("startPeriod")+2+c] != ','))
  8472. {
  8473. sstr[c] = loc[strlen("startPeriod")+2+c];
  8474. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8475. c++;
  8476. }
  8477. sstr[c] = '\0';
  8478. startPeriodInt[periodNums] = atoi(sstr);
  8479. //DEBUG_INFO("sstr=%d\n",atoi(sstr));
  8480. //DEBUG_INFO("handleSetChargingProfileRequest -13 -1 -1\n");
  8481. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8482. {
  8483. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8484. }
  8485. else
  8486. {
  8487. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].StartPeriod = startPeriodInt[periodNums];
  8488. }
  8489. templength = strlen("startPeriod")+2+c;
  8490. //DEBUG_INFO("handleSetChargingProfileRequest -13 -2\n");
  8491. //****************limit*******************/
  8492. c=0;
  8493. loc = strstr(tempChargingProfile + templength, "limit");
  8494. memset(sstr ,0, sizeof(sstr) );
  8495. while ((loc[strlen("limit")+2+c] != '}') && (loc[strlen("limit")+2+c] != ','))
  8496. {
  8497. sstr[c] = loc[strlen("limit")+2+c];
  8498. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8499. c++;
  8500. }
  8501. sstr[c] = '\0';
  8502. limitflaot[periodNums] = atof(sstr);
  8503. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8504. {
  8505. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8506. }
  8507. else
  8508. {
  8509. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].Limit = limitflaot[periodNums];
  8510. }
  8511. templength = templength + strlen("limit")+2+c;
  8512. //****************numberPhases*******************/
  8513. loc = strstr(tempChargingProfile + templength, "numberPhases");
  8514. if(loc != NULL)
  8515. {
  8516. c=0;
  8517. memset(sstr ,0, sizeof(sstr) );
  8518. while ((loc[strlen("numberPhases")+2+c] != '}') && (loc[strlen("numberPhases")+2+c] != ','))
  8519. {
  8520. sstr[c] = loc[strlen("numberPhases")+2+c];
  8521. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8522. c++;
  8523. }
  8524. sstr[c] = '\0';
  8525. numberPhasesInt[periodNums] = atoi(sstr);
  8526. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8527. {
  8528. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8529. }
  8530. else
  8531. {
  8532. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[periodNums].NumberPhases = numberPhasesInt[periodNums];
  8533. }
  8534. templength = templength + strlen("numberPhases")+2+c;
  8535. }
  8536. //where = loc;
  8537. }
  8538. //****************chargingSchedulePeriod count end*******************/
  8539. //*********************minChargingRate***************************/
  8540. loc = strstr(sstrtemp, "minChargingRate");
  8541. if(loc != NULL)
  8542. {
  8543. c = 0;
  8544. memset(sstr ,0, sizeof(sstr) );
  8545. while ((loc[strlen("minChargingRate")+2+c] != ',')&&(loc[strlen("minChargingRate")+2+c] != '}'))
  8546. {
  8547. sstr[c] = loc[strlen("minChargingRate")+2+c];
  8548. c++;
  8549. }
  8550. sstr[c] = '\0';
  8551. minChargingRateFloat = atof(sstr);
  8552. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8553. {
  8554. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8555. }
  8556. else
  8557. {
  8558. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8559. }
  8560. }
  8561. else
  8562. {
  8563. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8564. {
  8565. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8566. }
  8567. else
  8568. {
  8569. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = 0.0;
  8570. }
  8571. }
  8572. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8573. {
  8574. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8575. if(connectorIdInt != 0)
  8576. {
  8577. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8578. goto end;
  8579. }
  8580. strcpy(filename, ChargePointMaxProfile_JSON );
  8581. fptr1 = fopen(filename, "r");
  8582. if (!fptr1)
  8583. {
  8584. //file not exist
  8585. DEBUG_INFO("Unable to open the input file!!\n");
  8586. fptr1 = fopen(filename, "w+");
  8587. }
  8588. else
  8589. {
  8590. //Check Charging Profile Count
  8591. while(fscanf(fptr1, "%s", word) != EOF)
  8592. {
  8593. //DEBUG_INFO("word=%s\n",word);
  8594. if(strstr(word, "chargingProfileId")!= NULL)
  8595. {
  8596. //DEBUG_INFO("test chargingProfileId \n");
  8597. n_chargingProfile = n_chargingProfile + 1;
  8598. //DEBUG_INFO("chargingProfileId Found\n");
  8599. }
  8600. }
  8601. }
  8602. fclose(fptr1);
  8603. }
  8604. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8605. {
  8606. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8607. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8608. {
  8609. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8610. goto end;
  8611. }
  8612. memset(filename, 0, sizeof filename);
  8613. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8614. fptr1 = fopen(filename, "r");
  8615. if (!fptr1)
  8616. {
  8617. //file not exist
  8618. //DEBUG_INFO("Unable to open the input file!!\n");
  8619. fptr1 = fopen(filename, "w+");
  8620. }
  8621. else
  8622. {
  8623. //Check Charging Profile Count
  8624. while(fscanf(fptr1, "%s", word) != EOF)
  8625. {
  8626. //DEBUG_INFO("word=%s\n",word);
  8627. if(strstr(word, "chargingProfileId")!= NULL)
  8628. {
  8629. //DEBUG_INFO("test chargingProfileId \n");
  8630. n_chargingProfile = n_chargingProfile + 1;
  8631. //DEBUG_INFO("chargingProfileId Found\n");
  8632. }
  8633. }
  8634. }
  8635. fclose(fptr1);
  8636. }
  8637. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8638. {
  8639. //printf("set chargingProfile 1-4\n");
  8640. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8641. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8642. if(connectorIdInt == 0)
  8643. {
  8644. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8645. goto end;
  8646. }
  8647. int tempIndex = 0;
  8648. //check Transaction active
  8649. if(gunType[connectorIdInt -1] == 'J')
  8650. {
  8651. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8652. {
  8653. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8654. }
  8655. else
  8656. {
  8657. tempIndex = connectorIdInt -1;
  8658. }
  8659. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8660. {
  8661. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8662. {
  8663. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8664. {
  8665. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8666. {
  8667. meet = TRUE;
  8668. break;
  8669. }
  8670. }
  8671. }
  8672. }
  8673. }
  8674. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8675. {
  8676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8677. {
  8678. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8679. }
  8680. else
  8681. {
  8682. tempIndex = connectorIdInt -1;
  8683. }
  8684. for (int index = 0; index < CCS_QUANTITY; index++)
  8685. {
  8686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8687. {
  8688. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8689. {
  8690. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8691. {
  8692. meet = TRUE;
  8693. break;
  8694. }
  8695. }
  8696. }
  8697. }
  8698. }
  8699. else if(gunType[connectorIdInt -1] == 'G')
  8700. {
  8701. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8702. {
  8703. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8704. }
  8705. else
  8706. {
  8707. tempIndex = connectorIdInt -1;
  8708. }
  8709. for (int index = 0; index < GB_QUANTITY; index++)
  8710. {
  8711. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8712. {
  8713. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8714. {
  8715. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8716. {
  8717. meet = TRUE;
  8718. break;
  8719. }
  8720. }
  8721. }
  8722. }
  8723. }
  8724. else
  8725. {
  8726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8727. {
  8728. tempIndex = 2;
  8729. }
  8730. else
  8731. {
  8732. tempIndex = (connectorIdInt -1);
  8733. }
  8734. for (int index = 0; index < AC_QUANTITY; index++)
  8735. {
  8736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8737. {
  8738. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8739. {
  8740. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8741. {
  8742. meet = TRUE;
  8743. break;
  8744. }
  8745. }
  8746. }
  8747. }
  8748. }
  8749. //check Transaction active
  8750. if(meet == FALSE)
  8751. {
  8752. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8753. goto end;
  8754. }
  8755. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8756. {
  8757. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8758. goto end;
  8759. }
  8760. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8761. fptr1 = fopen(filename, "r");
  8762. if (!fptr1)
  8763. {
  8764. //file not exist
  8765. DEBUG_INFO("Unable to open the input file!!\n");
  8766. fptr1 = fopen(filename, "w+");
  8767. }
  8768. else
  8769. {
  8770. //Check Charging Profile Count
  8771. while(fscanf(fptr1, "%s", word) != EOF)
  8772. {
  8773. //DEBUG_INFO("word=%s\n",word);
  8774. if(strstr(word, "chargingProfileId")!= NULL)
  8775. {
  8776. //DEBUG_INFO("test chargingProfileId \n");
  8777. n_chargingProfile = n_chargingProfile + 1;
  8778. //DEBUG_INFO("chargingProfileId Found\n");
  8779. }
  8780. }
  8781. }
  8782. fclose(fptr1);
  8783. }
  8784. // Check ChargeProfileMaxStackLevel
  8785. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8786. {
  8787. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8788. goto end;
  8789. }
  8790. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8791. {
  8792. int i = 0;
  8793. char fnametemp[200]={0};
  8794. n_chargingProfile = 0;
  8795. //Check ChargePointMaxProfile.json exit
  8796. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8797. {
  8798. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8799. //Check Charging Profile Count
  8800. while(fscanf(fptr1, "%s", word) != EOF)
  8801. {
  8802. //DEBUG_INFO("word=%s\n",word);
  8803. if(strstr(word, "chargingProfileId")!= NULL)
  8804. {
  8805. //DEBUG_INFO("test chargingProfileId \n");
  8806. n_chargingProfile = n_chargingProfile + 1;
  8807. i = i + 1;
  8808. //DEBUG_INFO("chargingProfileId Found\n");
  8809. }
  8810. memset(word, 0, sizeof word);
  8811. }
  8812. fclose(fptr1);
  8813. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8814. }
  8815. //Check TxDefaultProfile_0.json exit
  8816. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8817. {
  8818. i = 0;
  8819. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8820. //Check Charging Profile Count
  8821. while(fscanf(fptr1, "%s", word) != EOF)
  8822. {
  8823. //DEBUG_INFO("word=%s\n",word);
  8824. if(strstr(word, "chargingProfileId")!= NULL)
  8825. {
  8826. //DEBUG_INFO("test chargingProfileId \n");
  8827. n_chargingProfile = n_chargingProfile + 1;
  8828. i = i + 1;
  8829. //DEBUG_INFO("chargingProfileId Found\n");
  8830. }
  8831. memset(word, 0, sizeof word);
  8832. }
  8833. fclose(fptr1);
  8834. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8835. }
  8836. //Check TxDefaultProfile_%d.json
  8837. for(int j=1; j <= gunTotalNumber; j++)
  8838. {
  8839. memset(fnametemp, 0, sizeof fnametemp);
  8840. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8841. if((access(fnametemp,F_OK))!=-1)
  8842. {
  8843. i = 0;
  8844. fptr1 = fopen(fnametemp, "r");
  8845. //Check Charging Profile Count
  8846. while(fscanf(fptr1, "%s", word) != EOF)
  8847. {
  8848. //DEBUG_INFO("word=%s\n",word);
  8849. if(strstr(word, "chargingProfileId")!= NULL)
  8850. {
  8851. //DEBUG_INFO("test chargingProfileId \n");
  8852. n_chargingProfile = n_chargingProfile + 1;
  8853. i = i + 1;
  8854. //DEBUG_INFO("chargingProfileId Found\n");
  8855. }
  8856. memset(word, 0, sizeof word);
  8857. }
  8858. fclose(fptr1);
  8859. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8860. }
  8861. }
  8862. //Check TxProfile_%d.json
  8863. for(int j=1; j <= gunTotalNumber; j++)
  8864. {
  8865. memset(fnametemp, 0, sizeof fnametemp);
  8866. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8867. if((access(fnametemp,F_OK))!=-1)
  8868. {
  8869. i = 0;
  8870. fptr1 = fopen(fnametemp, "r");
  8871. //Check Charging Profile Count
  8872. while(fscanf(fptr1, "%s", word) != EOF)
  8873. {
  8874. //DEBUG_INFO("word=%s\n",word);
  8875. if(strstr(word, "chargingProfileId")!= NULL)
  8876. {
  8877. //DEBUG_INFO("test chargingProfileId \n");
  8878. n_chargingProfile = n_chargingProfile + 1;
  8879. i = i + 1;
  8880. //DEBUG_INFO("chargingProfileId Found\n");
  8881. }
  8882. memset(word, 0, sizeof word);
  8883. }
  8884. fclose(fptr1);
  8885. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8886. }
  8887. }
  8888. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8889. {
  8890. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8891. goto end;
  8892. }
  8893. }
  8894. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8895. //**********************************Write to File********************************************************/
  8896. FILE *infile;
  8897. FILE *outfile;
  8898. // open file for writing
  8899. infile = fopen (filename, "r");
  8900. outfile = fopen (tempfile, "w");
  8901. int d =0;
  8902. d = fgetc(infile);
  8903. //DEBUG_INFO("d:%d\n",d);
  8904. rewind(infile);
  8905. //*璉 瘚 辣蝏     1嚗   0 */
  8906. if(d == EOF)
  8907. {
  8908. //DEBUG_INFO("ChargingProfile content is NULL\n");
  8909. fprintf(outfile,"%s\n",payload);
  8910. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8911. fclose(infile);
  8912. fclose(outfile);
  8913. sprintf(rmFileCmd,"rm -f %s",filename);
  8914. system(rmFileCmd);
  8915. rename(tempfile, filename);
  8916. sleep(1);
  8917. //sprintf(rmFileCmd,"rm -f %s",tempfile);
  8918. //system(rmFileCmd);
  8919. }
  8920. else
  8921. {
  8922. char buf[1000]={0};
  8923. int ChargingProfileAdded = FALSE;
  8924. while (fgets(buf, sizeof(buf), infile) != NULL)
  8925. {
  8926. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8927. //*************************tempconnectorIdInt*********************************/
  8928. loc = strstr(buf, "connectorId");
  8929. c = 0;
  8930. memset(sstr ,0, sizeof(sstr) );
  8931. while (loc[strlen("connectorId")+2+c] != ',')
  8932. {
  8933. sstr[c] = loc[strlen("connectorId")+2+c];
  8934. c++;
  8935. }
  8936. sstr[c] = '\0';
  8937. tempconnectorIdInt = atoi(sstr);
  8938. //*************************tempchargingProfileIdInt*********************************/
  8939. loc = strstr(buf, "chargingProfileId");
  8940. c = 0;
  8941. memset(sstr ,0, sizeof(sstr) );
  8942. while (loc[strlen("chargingProfileId")+2+c] != ',')
  8943. {
  8944. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  8945. c++;
  8946. }
  8947. sstr[c] = '\0';
  8948. tempchargingProfileIdInt = atoi(sstr);
  8949. //*************************tempstackLevelInt*********************************/
  8950. loc = strstr(buf, "stackLevel");
  8951. c = 0;
  8952. memset(sstr ,0, sizeof(sstr) );
  8953. while (loc[strlen("stackLevel")+2+c] != ',')
  8954. {
  8955. sstr[c] = loc[strlen("stackLevel")+2+c];
  8956. c++;
  8957. }
  8958. sstr[c] = '\0';
  8959. tempstackLevelInt = atoi(sstr);
  8960. //*************************tempchargingProfilePurposeStr*********************************/
  8961. loc = strstr(payload, "chargingProfilePurpose");
  8962. c = 0;
  8963. memset(sstr ,0, sizeof(sstr) );
  8964. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  8965. {
  8966. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  8967. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8968. c++;
  8969. }
  8970. sstr[c] = '\0';
  8971. strcpy(tempchargingProfilePurposeStr,sstr);
  8972. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8973. {
  8974. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8975. {
  8976. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8977. if(ChargingProfileAdded == FALSE)
  8978. {
  8979. fprintf(outfile,"%s\n",payload);
  8980. ChargingProfileAdded = TRUE;
  8981. }
  8982. }
  8983. else
  8984. {
  8985. if(tempstackLevelInt < stackLevelInt)
  8986. {
  8987. if(ChargingProfileAdded == FALSE)
  8988. {
  8989. fprintf(outfile,"%s\n",payload);
  8990. ChargingProfileAdded = TRUE;
  8991. fprintf(outfile,"%s\n",buf);
  8992. }
  8993. else
  8994. {
  8995. fprintf(outfile,"%s\n",buf);
  8996. }
  8997. }
  8998. else
  8999. {
  9000. if(ChargingProfileAdded == FALSE)
  9001. {
  9002. fprintf(outfile,"%s\n",buf);
  9003. fprintf(outfile,"%s\n",payload);
  9004. ChargingProfileAdded = TRUE;
  9005. }
  9006. else
  9007. {
  9008. fprintf(outfile,"%s\n",buf);
  9009. }
  9010. }
  9011. }
  9012. }
  9013. else
  9014. {
  9015. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9016. {
  9017. if(ChargingProfileAdded == FALSE)
  9018. {
  9019. fprintf(outfile,"%s\n",payload);
  9020. ChargingProfileAdded = TRUE;
  9021. fprintf(outfile,"%s\n",buf);
  9022. }
  9023. else
  9024. {
  9025. fprintf(outfile,"%s\n",buf);
  9026. }
  9027. }
  9028. else if(tempstackLevelInt < stackLevelInt)
  9029. {
  9030. if(ChargingProfileAdded == FALSE)
  9031. {
  9032. fprintf(outfile,"%s\n",payload);
  9033. ChargingProfileAdded = TRUE;
  9034. fprintf(outfile,"%s\n",buf);
  9035. }
  9036. else
  9037. {
  9038. fprintf(outfile,"%s\n",buf);
  9039. }
  9040. }
  9041. else
  9042. {
  9043. if(ChargingProfileAdded == FALSE)
  9044. {
  9045. fprintf(outfile,"%s\n",buf);
  9046. fprintf(outfile,"%s\n",payload);
  9047. ChargingProfileAdded = TRUE;
  9048. }
  9049. else
  9050. {
  9051. fprintf(outfile,"%s\n",buf);
  9052. }
  9053. }
  9054. }
  9055. } // end of while loop
  9056. fclose(infile);
  9057. fclose(outfile);
  9058. sprintf(rmFileCmd,"rm -f %s",filename);
  9059. system(rmFileCmd);
  9060. rename(tempfile, filename);
  9061. sleep(1);
  9062. result = TRUE;
  9063. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9064. }
  9065. end:
  9066. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9067. return result;
  9068. return result;
  9069. }
  9070. int handleTriggerMessageRequest(char *uuid, char *payload)
  9071. {
  9072. mtrace();
  9073. int result = FAIL;
  9074. int connectorIdIsNULL = FALSE;
  9075. int connectorIdInt =0;
  9076. char sstr[40]={0},sstrtemp[100]={ 0 };
  9077. char requestedMessagestr[40]={0};
  9078. char comfirmstr[20]={0};
  9079. int c = 0;
  9080. char *loc;
  9081. DEBUG_INFO("handleTriggerMessageRequest\n");
  9082. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9083. strcpy(sstrtemp, stringtrimspace(payload));
  9084. c = 0;
  9085. loc = strstr(sstrtemp, "requestedMessage");
  9086. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9087. {
  9088. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9089. c++;
  9090. }
  9091. sstr[c] = '\0';
  9092. strcpy(requestedMessagestr, sstr);
  9093. c = 0;
  9094. loc = strstr(sstrtemp, "connectorId");
  9095. if(loc == NULL)
  9096. {
  9097. connectorIdIsNULL = TRUE;
  9098. }
  9099. else
  9100. {
  9101. memset(sstr ,0, sizeof(sstr) );
  9102. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9103. {
  9104. sstr[c] = loc[strlen("connectorId")+2+c];
  9105. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9106. c++;
  9107. }
  9108. sstr[c] = '\0';
  9109. connectorIdInt = atoi(sstr);
  9110. }
  9111. if(connectorIdIsNULL == FALSE && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ )))
  9112. {
  9113. //connectorIdInt = json_object_get_int(connectorId);
  9114. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9115. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9116. //ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9117. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9118. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9119. }
  9120. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9121. {
  9122. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9123. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9124. return TRUE;
  9125. }
  9126. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9127. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9128. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9129. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9130. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9131. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9132. {
  9133. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9134. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9135. return TRUE;
  9136. }
  9137. else
  9138. {
  9139. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9140. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9141. }
  9142. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9143. {
  9144. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9145. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9146. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9147. {
  9148. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9149. }
  9150. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9151. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9152. }
  9153. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9154. {
  9155. //printf("DiagnosticsStatusStr[DiagnosticsStatus_Idle] =%s\n",DiagnosticsStatusStr[DiagnosticsStatus_Idle]);
  9156. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9157. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9158. }
  9159. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9160. {
  9161. sendBootNotificationRequest();
  9162. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9163. }
  9164. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9165. {
  9166. sendHeartbeatRequest(connectorIdInt);
  9167. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9168. }
  9169. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9170. {
  9171. if(connectorIdIsNULL == FALSE)
  9172. {
  9173. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9174. {
  9175. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].TriggerMessageReq = 1;
  9176. sendMeterValuesRequest(connectorIdInt -1);
  9177. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9178. }
  9179. }
  9180. else
  9181. {
  9182. for(int idx=0;idx< gunTotalNumber;idx++)
  9183. {
  9184. ShmOCPP16Data->CsMsg.bits[idx].TriggerMessageReq = 1;
  9185. sendMeterValuesRequest(idx);
  9186. }
  9187. }
  9188. }
  9189. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9190. {
  9191. if(connectorIdIsNULL == FALSE)
  9192. {
  9193. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9194. {
  9195. sendStatusNotificationRequest(connectorIdInt -1);
  9196. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9197. }
  9198. }
  9199. else
  9200. {
  9201. for(int idx=0;idx< gunTotalNumber;idx++)
  9202. sendStatusNotificationRequest(idx);
  9203. //sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9204. }
  9205. }
  9206. return result;
  9207. }
  9208. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9209. {
  9210. mtrace();
  9211. int result = FAIL;
  9212. char sstr[6]={0},sstrtemp[50]={ 0 };
  9213. int connectorIdInt =0;
  9214. char comfirmstr[20]={0};
  9215. int c = 0;
  9216. int tempIndex = 0;
  9217. char *loc;
  9218. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9219. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9220. strcpy(sstrtemp, stringtrimspace(payload));
  9221. c = 0;
  9222. loc = strstr(sstrtemp, "connectorId");
  9223. memset(sstr ,0, sizeof(sstr) );
  9224. while (loc[strlen("connectorId")+2+c] != '}')
  9225. {
  9226. sstr[c] = loc[strlen("connectorId")+2+c];
  9227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9228. c++;
  9229. }
  9230. sstr[c] = '\0';
  9231. connectorIdInt = atoi(sstr);
  9232. DEBUG_INFO("\n unlock connectorIdInt=%d\n",connectorIdInt);
  9233. if(gunTotalNumber == 0)
  9234. {
  9235. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9236. goto end;
  9237. }
  9238. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9239. {
  9240. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9241. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9242. goto end;
  9243. }
  9244. else
  9245. {
  9246. //check Transaction active
  9247. if(gunType[connectorIdInt-1] == 'J')
  9248. {
  9249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9250. {
  9251. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9252. }
  9253. else
  9254. {
  9255. tempIndex = connectorIdInt -1;
  9256. }
  9257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9258. {
  9259. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9260. {
  9261. //stop Transaction
  9262. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9263. }
  9264. }
  9265. }
  9266. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9267. {
  9268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9269. {
  9270. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9271. }
  9272. else
  9273. {
  9274. tempIndex = connectorIdInt -1;
  9275. }
  9276. for (int index = 0; index < CCS_QUANTITY; index++)
  9277. {
  9278. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9279. {
  9280. //stop Transaction
  9281. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9282. }
  9283. }
  9284. }
  9285. else if(gunType[connectorIdInt-1] == 'G')
  9286. {
  9287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9288. {
  9289. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9290. }
  9291. else
  9292. {
  9293. tempIndex = connectorIdInt -1;
  9294. }
  9295. for (int index = 0; index < GB_QUANTITY; index++)
  9296. {
  9297. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9298. {
  9299. //stop Transaction
  9300. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9301. }
  9302. }
  9303. }
  9304. else
  9305. {
  9306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9307. {
  9308. tempIndex = 2;
  9309. }
  9310. else
  9311. {
  9312. tempIndex = connectorIdInt-1;
  9313. }
  9314. for (int index = 0; index < AC_QUANTITY; index++)
  9315. {
  9316. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9317. {
  9318. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9319. }
  9320. }
  9321. }
  9322. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9323. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9324. result = TRUE;
  9325. return result;
  9326. }
  9327. end:
  9328. //json_object_put(obj); --- remove temporally
  9329. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9330. return result;
  9331. }
  9332. static char UpdateFirmwarepayloadData[300]={0};
  9333. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9334. {
  9335. mtrace();
  9336. int result = FAIL;
  9337. pthread_t t;
  9338. sendUpdateFirmwareConfirmation(uuid);
  9339. memset(UpdateFirmwarepayloadData, 0, 300);
  9340. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9341. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9342. ////pthread_join(t, NULL); //
  9343. //pthread_detach(t);
  9344. //sendUpdateFirmwareConfirmation(uuid);
  9345. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9346. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9347. return result;
  9348. }
  9349. void *UpdateFirmwareProcess(void *data)
  9350. {
  9351. pthread_detach(pthread_self());
  9352. mtrace();
  9353. int retriesInt =0, retryIntervalInt=0;
  9354. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9355. int port=0;
  9356. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9357. //char fname[50]="00000_2018-09-07 160902_CSULog.zip";
  9358. //char comfirmstr[20];
  9359. int isSuccess = 0;
  9360. char ftpbuf[200];
  9361. char temp[100];
  9362. char * pch;
  9363. int retriesISNULL=FALSE;
  9364. int retryInterval=FALSE;
  9365. int c = 0;
  9366. //int i = 0;
  9367. char *loc;
  9368. char sstr[300]={ 0 };
  9369. char str[300]={ 0 };
  9370. //char *str = (char*) data; // ? ?頛詨鞈 ?
  9371. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9372. //DEBUG_INFO("packet=%s\n", (const char*)payloadData);
  9373. strcpy(str,(const char*)UpdateFirmwarepayloadData);
  9374. //***************location **************/
  9375. loc = strstr(str, "location");
  9376. memset(sstr ,0, sizeof(sstr) );
  9377. c = 0;
  9378. while (loc[3+strlen("location")+c] != '\"')
  9379. {
  9380. sstr[c] = loc[3+strlen("location")+c];
  9381. c++;
  9382. }
  9383. sstr[c] = '\0';
  9384. strcpy(locationstr, sstr);
  9385. //***************retries**************/
  9386. c = 0;
  9387. loc = strstr(str, "retries");
  9388. if(loc == NULL)
  9389. {
  9390. retriesISNULL=TRUE;
  9391. }
  9392. else
  9393. {
  9394. memset(sstr ,0, sizeof(sstr) );
  9395. while (loc[strlen("retries")+2+c] != ',')
  9396. {
  9397. sstr[c] = loc[strlen("retries")+2+c];
  9398. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9399. c++;
  9400. }
  9401. sstr[c] = '\0';
  9402. }
  9403. if(retriesISNULL == FALSE)
  9404. {
  9405. retriesInt = atoi(sstr);
  9406. }
  9407. //***************retrieveDate **************/
  9408. loc = strstr(str, "retrieveDate");
  9409. memset(sstr ,0, sizeof(sstr) );
  9410. c = 0;
  9411. while (loc[3+strlen("retrieveDate")+c] != '\"')
  9412. {
  9413. sstr[c] = loc[3+strlen("retrieveDate")+c];
  9414. c++;
  9415. }
  9416. sstr[c] = '\0';
  9417. strcpy(retrieveDatestr, sstr);
  9418. //***************retryInterval **************/
  9419. c = 0;
  9420. loc = strstr(str, "retryInterval");
  9421. memset(sstr ,0, sizeof(sstr) );
  9422. if(loc == NULL)
  9423. {
  9424. retryInterval=TRUE;
  9425. }
  9426. else
  9427. {
  9428. while ((loc[strlen("retryInterval")+2+c] != ',') && (loc[strlen("retryInterval")+2+c] != '}'))
  9429. {
  9430. sstr[c] = loc[strlen("retryInterval")+2+c];
  9431. //DEBUG_INFO("i=%d sstr=%c\n",c, sstr[c]);
  9432. c++;
  9433. }
  9434. sstr[c] = '\0';
  9435. }
  9436. if(retryInterval==FALSE)
  9437. {
  9438. retryIntervalInt = atoi(sstr);
  9439. }
  9440. memset(ftppath, 0, sizeof(ftppath));
  9441. memset(path, 0, sizeof(path));
  9442. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9443. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9444. if(strncmp(locationstr,"http", 4) == 0)
  9445. {
  9446. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]",
  9447. protocol, host, path);
  9448. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9449. // protocol, user, password, host, path);
  9450. sprintf(ftppath,"/%s", path);
  9451. //DEBUG_INFO("protocol =%s\n",protocol);
  9452. //DEBUG_INFO("host =%s\n",host);
  9453. //DEBUG_INFO("path =%s\n",path);
  9454. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9455. int ftppathlen=strlen(ftppath);
  9456. int i=1;
  9457. char filenametemp[50];
  9458. while(i < ftppathlen)
  9459. {
  9460. int len=ftppathlen-i;
  9461. if(ftppath[len]== 47) // '/' ascll code: 47
  9462. {
  9463. DEBUG_INFO("compare '/' all right\n");
  9464. break;
  9465. }
  9466. i=i+1;
  9467. }
  9468. memset(filenametemp, 0, sizeof(filenametemp));
  9469. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9470. filenametemp[i+1] = 0;
  9471. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9472. do{
  9473. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9474. sleep(retryIntervalInt);
  9475. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9476. // isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9477. if(!isSuccess)
  9478. {
  9479. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9480. }
  9481. else
  9482. {
  9483. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9484. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9485. //isUpdateRequest = TRUE;
  9486. }
  9487. }
  9488. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9489. {
  9490. memset(ftpbuf, 0, sizeof(ftpbuf));
  9491. memset(temp, 0, sizeof(temp));
  9492. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9493. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9494. int ftppathlen=strlen(ftpbuf);
  9495. int i=1;
  9496. char filenametemp[50];
  9497. while(i < ftppathlen)
  9498. {
  9499. int len=ftppathlen-i;
  9500. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9501. {
  9502. DEBUG_INFO(" compare '/' all right\n");
  9503. break;
  9504. }
  9505. i=i+1;
  9506. }
  9507. memset(filenametemp, 0, sizeof(filenametemp));
  9508. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9509. filenametemp[i+1] = 0;
  9510. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9511. pch=strchr(temp,'@');
  9512. if(pch==NULL)
  9513. {
  9514. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9515. protocol, host, &port, path);
  9516. strcpy(user,"anonymous");
  9517. strcpy(password,"");
  9518. }
  9519. else
  9520. {
  9521. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9522. protocol, user, password, host, &port, path);
  9523. }
  9524. sscanf(host,"%[^/]%s",host1, path1);
  9525. sprintf(ftppath,"%s", path1);
  9526. //DEBUG_INFO("protocol =%s\n",protocol);
  9527. //DEBUG_INFO("user =%s\n",user);
  9528. //DEBUG_INFO("password =%s\n",password);
  9529. //DEBUG_INFO("host1 =%s\n",host1);
  9530. //DEBUG_INFO("port =%d\n",port);
  9531. //DEBUG_INFO("path1 =%s\n",path1);
  9532. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9533. //ftpFile(host, user, password, port, ftppath, fname);
  9534. //download firmware pthred
  9535. if(port == 0)
  9536. {
  9537. port = 21;
  9538. }
  9539. //sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9540. do{
  9541. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9542. sleep(retryIntervalInt);
  9543. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9544. if(!isSuccess)
  9545. {
  9546. //BulldogUtil.sleepMs(interval*1000);
  9547. DEBUG_INFO("Update firmware request and download file fail.\n");
  9548. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9549. }
  9550. else
  9551. {
  9552. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9553. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9554. //isUpdateRequest = TRUE;
  9555. }
  9556. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9557. }
  9558. else
  9559. {
  9560. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9561. //ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9562. }
  9563. pthread_exit(NULL);
  9564. }
  9565. //==========================================
  9566. // Handle server response routine
  9567. //==========================================
  9568. void handleAuthorizeResponse(char *payload, int gun_index)
  9569. {
  9570. mtrace();
  9571. char expiryDatestr[30]={0};
  9572. char parentIdTagstr[20]={0};
  9573. char statusstr[20]={0};
  9574. char expiryDatestrtemp[30]={0};
  9575. char parentIdTagstrtemp[20]={0};
  9576. char IdTagstrtemp[20]={0};
  9577. char statusstrtemp[20]={0};
  9578. int expiryDateISNULL=FALSE;
  9579. int parentIdTagISNULL=FALSE;
  9580. char sstr[160]={0};
  9581. char* filename = AuthorizationCache_JSON;
  9582. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9583. char *loc;
  9584. int resultRename=0;
  9585. int responseIdTagInfoAsZero= 0;
  9586. char rmFileCmd[50]={0};
  9587. DEBUG_INFO("handleAuthorizeResponse...\n");
  9588. json_object *Authorize;
  9589. Authorize = json_tokener_parse(payload);
  9590. if(!is_error(Authorize))
  9591. {
  9592. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9593. {
  9594. // Required data
  9595. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9596. // Optional data
  9597. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9598. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9599. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9600. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9601. }
  9602. }
  9603. json_object_put(Authorize);
  9604. if(expiryDateISNULL == FALSE)
  9605. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9606. if(parentIdTagISNULL == FALSE)
  9607. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9608. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9609. //Update idTag information to authorization cache if supproted
  9610. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9611. {
  9612. if((access(filename,F_OK))!=-1)
  9613. {
  9614. printf("AuthorizationCache exist.\n");
  9615. }
  9616. else
  9617. {
  9618. printf("AuthorizationCache not exist\n");
  9619. FILE *log = fopen(filename, "w+");
  9620. if(log == NULL)
  9621. {
  9622. printf("log is NULL\n");
  9623. goto out;
  9624. }
  9625. else
  9626. {
  9627. fclose(log);
  9628. }
  9629. }
  9630. FILE *infile;
  9631. FILE *outfile;
  9632. // open file for writing
  9633. infile = fopen (filename, "r");
  9634. outfile = fopen (tempfile, "w");
  9635. int c;
  9636. c = fgetc(infile);
  9637. //DEBUG_INFO("c:%d\n",c);
  9638. rewind(infile);
  9639. if(c == EOF)
  9640. {
  9641. DEBUG_INFO("Orignal File is NULL\n");
  9642. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9643. {
  9644. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9645. }
  9646. else
  9647. {
  9648. strcpy(expiryDatestrtemp, "");
  9649. }
  9650. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9651. {
  9652. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9653. }
  9654. else
  9655. {
  9656. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9657. }
  9658. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9659. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9660. fclose(infile);
  9661. fclose(outfile);
  9662. sprintf(rmFileCmd,"rm -f %s",filename);
  9663. system(rmFileCmd);
  9664. resultRename = rename(tempfile, filename);
  9665. if(resultRename == 0)
  9666. {
  9667. printf("File renamed successfully");
  9668. }
  9669. else
  9670. {
  9671. printf("Error: unable to rename the file");
  9672. }
  9673. }
  9674. else
  9675. {
  9676. char buf[160]={0};
  9677. while (fgets(buf, sizeof(buf), infile) != NULL)
  9678. {
  9679. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9680. memset(expiryDatestr, 0, sizeof(expiryDatestrtemp));
  9681. memset(parentIdTagstr,0, sizeof(parentIdTagstrtemp));
  9682. memset(statusstr, 0, sizeof(statusstrtemp));
  9683. memset(IdTagstrtemp, 0, sizeof(IdTagstrtemp));
  9684. memset(expiryDatestrtemp, 0, sizeof(expiryDatestrtemp));
  9685. memset(parentIdTagstrtemp, 0, sizeof(parentIdTagstrtemp));
  9686. memset(statusstrtemp, 0, sizeof(statusstrtemp));
  9687. //------------------IdTag-----------------------
  9688. loc = strstr(buf, "idTag");
  9689. memset(sstr ,0, sizeof(sstr) );
  9690. c = 0;
  9691. while (loc[3+strlen("idTag")+c] != '\"')
  9692. {
  9693. sstr[c] = loc[3+strlen("idTag")+c];
  9694. c++;
  9695. }
  9696. sstr[c] = '\0';
  9697. strcpy(IdTagstrtemp,sstr);
  9698. //*********************expiryDate***************/
  9699. loc = strstr(buf, "expiryDate");
  9700. memset(sstr ,0, sizeof(sstr) );
  9701. c = 0;
  9702. while (loc[3+strlen("expiryDate")+c] != '\"')
  9703. {
  9704. sstr[c] = loc[3+strlen("expiryDate")+c];
  9705. c++;
  9706. }
  9707. sstr[c] = '\0';
  9708. strcpy(expiryDatestr,sstr);
  9709. //*********************parentIdTag***************/
  9710. loc = strstr(buf, "parentIdTag");
  9711. memset(sstr ,0, sizeof(sstr) );
  9712. c = 0;
  9713. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9714. {
  9715. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9716. c++;
  9717. }
  9718. sstr[c] = '\0';
  9719. strcpy(parentIdTagstr,sstr);
  9720. //*********************status***************/
  9721. loc = strstr(buf, "status");
  9722. memset(sstr ,0, sizeof(sstr) );
  9723. c = 0;
  9724. while (loc[3+strlen("status")+c] != '\"')
  9725. {
  9726. sstr[c] = loc[3+strlen("status")+c];
  9727. c++;
  9728. }
  9729. sstr[c] = '\0';
  9730. strcpy(statusstr,sstr);
  9731. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9732. {
  9733. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9734. responseIdTagInfoAsZero = 1;
  9735. }
  9736. else
  9737. {
  9738. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9739. }
  9740. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9741. {
  9742. //modify item
  9743. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9744. {
  9745. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9746. }
  9747. else
  9748. {
  9749. strcpy(expiryDatestrtemp, "");
  9750. }
  9751. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9752. {
  9753. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9754. }
  9755. else
  9756. {
  9757. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9758. }
  9759. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9760. }
  9761. else
  9762. {
  9763. //wrie original item
  9764. strcpy(expiryDatestrtemp, expiryDatestr);
  9765. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9766. strcpy(statusstrtemp, statusstr);
  9767. }
  9768. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9769. }
  9770. fclose(infile);
  9771. fclose(outfile);
  9772. sprintf(rmFileCmd,"rm -f %s",filename);
  9773. system(rmFileCmd);
  9774. resultRename = rename(tempfile, filename);
  9775. if(resultRename == 0)
  9776. {
  9777. DEBUG_INFO("File renamed successfully");
  9778. }
  9779. else
  9780. {
  9781. DEBUG_INFO("Error: unable to rename the file");
  9782. }
  9783. }
  9784. }
  9785. out:
  9786. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9787. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9788. authorizeRetryTimes = 0;
  9789. }
  9790. char * strtrimc( char * s )
  9791. {
  9792. char * p1 = s;
  9793. char * p2 = s;
  9794. while(*p1 != '\0')
  9795. {
  9796. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9797. {
  9798. if(*p1 != ',')
  9799. {
  9800. p1 ++;
  9801. }
  9802. else
  9803. {
  9804. break;
  9805. }
  9806. }
  9807. if(*p1 != ',')
  9808. {
  9809. * p2 ++ = *p1 ++;
  9810. //printf("p2=%s\n",p2);
  9811. }
  9812. else
  9813. {
  9814. break;
  9815. }
  9816. }
  9817. *p2 = '\0';
  9818. return (s);
  9819. }
  9820. void handleBootNotificationResponse(char *payload, int gun_index)
  9821. {
  9822. mtrace();
  9823. char statusStr[12]={0};
  9824. char currentTimeStr[30]={0};
  9825. int intervalInt = 0;
  9826. struct tm tp;
  9827. char buf[28]={0};
  9828. char timebuf[50]={0};
  9829. DEBUG_INFO("handleBootNotificationResponse...\n");
  9830. json_object *BootNotification;
  9831. BootNotification = json_tokener_parse(payload);
  9832. if(!is_error(BootNotification))
  9833. {
  9834. // Required data
  9835. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9836. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9837. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9838. }
  9839. json_object_put(BootNotification);
  9840. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9841. BootNotificationInterval = intervalInt;
  9842. HeartBeatWaitTime = intervalInt;
  9843. //write back to ShmOCPP16Data->BootNotification
  9844. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9845. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9846. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9847. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9848. {
  9849. server_sign = TRUE;
  9850. server_pending =FALSE;
  9851. }
  9852. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9853. {
  9854. server_pending = TRUE;
  9855. }
  9856. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9857. tp.tm_isdst = -1;
  9858. //time_t utc = mktime(&tp);
  9859. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9860. memset(timebuf, 0, sizeof timebuf);
  9861. sprintf(timebuf,"date -s '%s'",buf);
  9862. system(timebuf);
  9863. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-5);
  9864. //==============================================
  9865. // RTC sync
  9866. //==============================================
  9867. system("/sbin/hwclock -w --systohc");
  9868. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9869. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9870. sendFirmwareVersionByDataTransfer();
  9871. }
  9872. void handleDataTransferResponse(char *payload, int gun_index)
  9873. {
  9874. char sstr[160]={0};//sstr[200]={ 0 };
  9875. int c = 0;
  9876. char *loc;
  9877. DEBUG_INFO("handleDataTransferResponse ...\n");
  9878. loc = strstr(payload, "status");
  9879. printf("loc=%s\n",loc);
  9880. c = 0;
  9881. while (loc[3+strlen("status")+c] != '\"')
  9882. {
  9883. sstr[c] = loc[3+strlen("status")+c];
  9884. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9885. c++;
  9886. }
  9887. sstr[c] = '\0';
  9888. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9889. }
  9890. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9891. {
  9892. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9893. //struct json_object *obj;
  9894. // obj = json_tokener_parse(payload);
  9895. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9896. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9897. //No fields are defined.
  9898. }
  9899. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9900. {
  9901. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9902. //struct json_object *obj;
  9903. // obj = json_tokener_parse(payload);
  9904. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9905. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9906. //No fields are defined.
  9907. }
  9908. void handleHeartbeatResponse(char *payload, int gun_index)
  9909. {
  9910. mtrace();
  9911. struct tm tp;
  9912. char buf[28]={0};
  9913. char timebuf[50]={0};
  9914. DEBUG_INFO("handleHeartbeatResponse...\n");
  9915. json_object *Heartbeat;
  9916. Heartbeat = json_tokener_parse(payload);
  9917. if(!is_error(Heartbeat))
  9918. {
  9919. // Required data
  9920. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9921. }
  9922. json_object_put(BootNotification);
  9923. if(FirstHeartBeat == 0)
  9924. {
  9925. FirstHeartBeat = 1;
  9926. DEBUG_INFO("FirstHeartBeat \n");
  9927. }
  9928. HeartBeatWithNOResponse = 0;
  9929. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9930. tp.tm_isdst = -1;
  9931. //time_t utc = mktime(&tp);
  9932. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9933. memset(timebuf, 0, sizeof timebuf);
  9934. sprintf(timebuf,"date -s '%s'",buf);
  9935. system(timebuf);
  9936. //==============================================
  9937. // RTC sync
  9938. //==============================================
  9939. system("/sbin/hwclock -w --systohc");
  9940. //===============================================
  9941. //Print Out HeartBeat log
  9942. //===============================================
  9943. {
  9944. double diff_t;
  9945. struct tm tp,tp1;
  9946. // BootNotification Receive Time
  9947. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9948. tp.tm_isdst = -1;
  9949. time_t BootNotificationReceiveTime = mktime(&tp);
  9950. //HeartBeat Receive Time
  9951. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp1);
  9952. tp1.tm_isdst = -1;
  9953. time_t HeartBeatReceiveTime = mktime(&tp1);
  9954. diff_t = difftime(HeartBeatReceiveTime, BootNotificationReceiveTime);
  9955. printf("handleHeartbeatResponse differnt time=%f..\n",diff_t);
  9956. if(((int)diff_t / 3600) > HeartBeatCountPerHour)
  9957. {
  9958. HeartBeatCountPerHour = (int)diff_t / 3600;
  9959. DEBUG_INFO("handleHeartbeatResponse ...\n");
  9960. DEBUG_INFO("After 1 hour, It will print out Heartbeat.\n");
  9961. }
  9962. }
  9963. }
  9964. void handleMeterValuesResponse(char *payload, int gun_index)
  9965. {
  9966. mtrace();
  9967. DEBUG_INFO("handleMeterValuesResponse...\n");
  9968. }
  9969. void handleStartTransactionResponse(char *payload, int gun_index)
  9970. {
  9971. mtrace();
  9972. //int transactionIdInt = 0;
  9973. FILE *outfile;
  9974. char data[100]={0};
  9975. DEBUG_INFO("handleStartTransactionResponse...\n");
  9976. json_object *StartTransaction;
  9977. StartTransaction = json_tokener_parse(payload);
  9978. if(!is_error(StartTransaction))
  9979. {
  9980. // Required data
  9981. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9982. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9983. // Optional data
  9984. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9985. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9986. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9987. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9988. }
  9989. json_object_put(StartTransaction);
  9990. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9991. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9992. //-----------Start : write to the Queue TransactionId file -----------------//
  9993. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9994. {}
  9995. else
  9996. {
  9997. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9998. if(log == NULL)
  9999. {
  10000. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  10001. return ;
  10002. }
  10003. else
  10004. {
  10005. fclose(log);
  10006. }
  10007. }
  10008. // open file for writing
  10009. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  10010. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  10011. {
  10012. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  10013. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  10014. fputs(data, outfile);
  10015. fclose (outfile);
  10016. }
  10017. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10018. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10019. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10020. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10021. }
  10022. void handleStatusNotificationResponse(char *payload, int gun_index)
  10023. {
  10024. mtrace();
  10025. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10026. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10027. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10028. }
  10029. void handleStopTransactionnResponse(char *payload, int gun_index)
  10030. {
  10031. mtrace();
  10032. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10033. json_object *StopTransaction;
  10034. StopTransaction = json_tokener_parse(payload);
  10035. if(!is_error(StopTransaction))
  10036. {
  10037. // Optional data
  10038. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10039. {
  10040. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10041. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10042. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10043. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10044. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10045. }
  10046. }
  10047. json_object_put(StopTransaction);
  10048. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10049. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10050. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10051. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10052. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10053. }
  10054. //==========================================
  10055. // Handle Error routine
  10056. //==========================================
  10057. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10058. {
  10059. mtrace();
  10060. #ifdef SystemLogMessage
  10061. DEBUG_INFO("errorCode: %s\n", errorCode);
  10062. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10063. DEBUG_INFO("errorDetails: %s\n", payload);
  10064. #endif
  10065. }
  10066. //===============================================
  10067. // Common routine
  10068. //===============================================
  10069. int initialConfigurationTable(void)
  10070. {
  10071. //clock_t start_t, end_t, total_t;
  10072. FILE *fp;
  10073. FILE *outfile;
  10074. char str[200]={0};
  10075. char sstr[100]={0};
  10076. int c = 0;
  10077. char *loc;
  10078. DEBUG_INFO("initialConfigurationTable...\n");
  10079. //start_t = clock();
  10080. //printf("Starting of the program, start_t = %ld\n", start_t);
  10081. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10082. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10083. {
  10084. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10085. if(outfile == NULL)
  10086. {
  10087. DEBUG_INFO("Error opening file\n");
  10088. return FALSE;
  10089. }
  10090. /*Core Profile*/
  10091. //AllowOfflineTxForUnknownId
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10093. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", "FALSE");
  10097. //AuthorizationCacheEnabled
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", "FALSE");
  10102. //AuthorizeRemoteTxRequests
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", "FALSE");
  10107. //BlinkRepeat
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", "0");
  10112. //ClockAlignedDataInterval
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", "0");
  10117. //ConnectionTimeOut
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", "180");
  10122. //GetConfigurationMaxKeys
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", "43");
  10127. // HeartbeatInterval
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10131. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", "10");
  10132. // LightIntensity
  10133. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10134. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10136. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", "0");
  10137. // LocalAuthorizeOffline
  10138. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10140. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10141. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", "TRUE");
  10142. // LocalPreAuthorize
  10143. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10144. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10146. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", "FALSE");
  10147. // MaxEnergyOnInvalidId
  10148. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10149. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10150. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10151. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10152. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", "0");
  10153. // MeterValuesAlignedData
  10154. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10156. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "" );
  10157. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", "");
  10158. // MeterValuesAlignedDataMaxLength
  10159. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10160. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10162. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", "5");
  10163. // MeterValuesSampledData
  10164. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10165. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10166. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10167. 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");
  10168. // MeterValuesSampledDataMaxLength
  10169. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10170. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10171. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10172. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", "6");
  10173. // MeterValueSampleInterval
  10174. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10175. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10176. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10177. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", "10");
  10178. // MinimumStatusDuration
  10179. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10180. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10181. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10182. server_cycle_Status = 120; //StatusNotification cycle
  10183. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", "120");
  10184. // NumberOfConnectors
  10185. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10186. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10188. {
  10189. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10190. }
  10191. else
  10192. {
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10194. }
  10195. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10196. // ResetRetries
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10198. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10199. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10200. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", "3");
  10201. // ConnectorPhaseRotation
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10203. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10204. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10205. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", "NotApplicable");
  10206. // ConnectorPhaseRotationMaxLength
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10208. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10209. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10210. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", "1");
  10211. // StopTransactionOnEVSideDisconnect
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10213. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10214. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10215. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", "TRUE");
  10216. // StopTransactionOnInvalidId
  10217. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10218. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10219. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10220. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", "FALSE");
  10221. // StopTxnAlignedData
  10222. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10223. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10224. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10225. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", "Energy.Active.Import.Register");
  10226. // StopTxnAlignedDataMaxLength
  10227. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10228. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", "0");
  10231. // StopTxnSampledData
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10234. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10235. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  10236. // StopTxnSampledDataMaxLength
  10237. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10238. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10239. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10240. {
  10241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10242. }
  10243. else
  10244. {
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10246. }
  10247. //strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10248. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10249. // SupportedFeatureProfiles
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10252. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10253. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger");
  10254. // SupportedFeatureProfilesMaxLength
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10257. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", "6");
  10259. // TransactionMessageAttempts
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10263. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", "3");
  10265. // TransactionMessageRetryInterval
  10266. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10269. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10270. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", "60");
  10271. // UnlockConnectorOnEVSideDisconnect
  10272. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10274. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10275. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", "TRUE");
  10276. // WebSocketPingInterval
  10277. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10279. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10280. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", "30");
  10281. //* Local Auth List Management Profile*/
  10282. #if 0
  10283. //For OCTT Test Case
  10284. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10285. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10286. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10287. #endif
  10288. #if 1
  10289. //LocalAuthListEnabled
  10290. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10291. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10293. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", "TRUE");
  10294. #endif
  10295. //LocalAuthListMaxLength
  10296. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", "500");
  10300. //SendLocalListMaxLength
  10301. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", "500");
  10305. //ReserveConnectorZeroSupported
  10306. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10307. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10308. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10309. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", "FALSE");
  10310. //* Smart Charging Profile */
  10311. //ChargeProfileMaxStackLevel
  10312. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10313. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10314. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10315. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", "3");
  10316. // ChargingScheduleAllowedChargingRateUnit
  10317. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10318. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10319. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10320. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", "Current");
  10321. // ChargingScheduleMaxPeriods
  10322. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10323. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10324. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10325. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", "10");
  10326. // ConnectorSwitch3to1PhaseSupported
  10327. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10328. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10329. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10330. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", "TRUE");
  10331. // MaxChargingProfilesInstalled
  10332. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10333. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10334. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10335. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", "3");
  10336. fclose(outfile);
  10337. }
  10338. else
  10339. {
  10340. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10341. char keystr[60]={0};
  10342. char readonlystr[10]={0};
  10343. char valuestr[100]={0};
  10344. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10345. if(fp == NULL) {
  10346. DEBUG_INFO("Error opening file");
  10347. return FALSE;
  10348. }
  10349. while( fgets (str, sizeof(str), fp)!=NULL )
  10350. {
  10351. //DEBUG_INFO("Get Configuration \n");
  10352. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10353. //*************************key*********************************/
  10354. loc = strstr(str, "key");
  10355. c = 0;
  10356. memset(sstr ,0, sizeof(sstr) );
  10357. while (loc[strlen("key")+3+c] != '\"')
  10358. {
  10359. sstr[c] = loc[strlen("key")+3+c];
  10360. c++;
  10361. }
  10362. sstr[c] = '\0';
  10363. strcpy(keystr,sstr);
  10364. //*************************readonly*********************************/
  10365. loc = strstr(str, "readonly");
  10366. c = 0;
  10367. memset(sstr ,0, sizeof(sstr) );
  10368. while (loc[strlen("readonly")+2+c] != ',')
  10369. {
  10370. sstr[c] = loc[strlen("readonly")+2+c];
  10371. c++;
  10372. }
  10373. sstr[c] = '\0';
  10374. strcpy(readonlystr,sstr);
  10375. //*************************value*********************************/
  10376. loc = strstr(str, "value");
  10377. c = 0;
  10378. memset(sstr ,0, sizeof(sstr) );
  10379. while (loc[strlen("value")+3+c] != '\"')
  10380. {
  10381. sstr[c] = loc[strlen("value")+3+c];
  10382. c++;
  10383. }
  10384. sstr[c] = '\0';
  10385. strcpy(valuestr,sstr);
  10386. // DEBUG_INFO("keystr=%s\n",keystr);
  10387. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10388. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10389. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10390. {
  10391. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10392. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10394. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10395. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10396. }
  10397. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10398. {
  10399. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10400. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10401. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10402. }
  10403. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10404. {
  10405. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10407. }
  10408. if(strcmp(keystr, "BlinkRepeat") == 0)
  10409. {
  10410. //Charger.BlinkRepeat = Integer.parseInt(value);
  10411. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10412. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10413. }
  10414. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10415. {
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10418. }
  10419. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10420. {
  10421. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10422. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10423. }
  10424. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10425. {
  10426. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10427. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(valuestr));
  10428. }
  10429. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10430. {
  10431. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10432. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10433. HeartBeatWaitTime = atoi(valuestr);
  10434. }
  10435. if(strcmp(keystr, "LightIntensity") == 0)
  10436. {
  10437. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10438. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10439. }
  10440. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10441. {
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10444. }
  10445. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10446. {
  10447. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10449. }
  10450. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10451. {
  10452. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10453. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10454. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10455. }
  10456. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10457. {
  10458. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10459. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10460. }
  10461. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10462. {
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10464. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10465. }
  10466. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10467. {
  10468. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10470. }
  10471. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10472. {
  10473. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10474. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10475. }
  10476. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10477. {
  10478. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10480. }
  10481. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10482. {
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10485. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10486. }
  10487. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10488. {
  10489. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10490. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10491. }
  10492. if(strcmp(keystr, "ResetRetries") == 0)
  10493. {
  10494. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10495. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10496. }
  10497. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10498. {
  10499. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10500. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10501. }
  10502. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10503. {
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10505. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10506. }
  10507. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10508. {
  10509. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10510. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10511. }
  10512. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10513. {
  10514. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10515. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10516. }
  10517. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10518. {
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10521. }
  10522. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10523. {
  10524. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10525. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10526. }
  10527. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10528. {
  10529. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10531. }
  10532. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10533. {
  10534. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10535. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10536. }
  10537. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10538. {
  10539. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10541. }
  10542. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10543. {
  10544. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10545. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10546. }
  10547. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10548. {
  10549. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10550. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10551. TransactionMessageAttemptsValue = atoi(valuestr);
  10552. }
  10553. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10554. {
  10555. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10556. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10557. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10558. }
  10559. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10560. {
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10563. }
  10564. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10565. {
  10566. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10568. }
  10569. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10570. {
  10571. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10572. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10573. }
  10574. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10575. {
  10576. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10577. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10578. }
  10579. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10580. {
  10581. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10583. }
  10584. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10585. {
  10586. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10588. }
  10589. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10590. {
  10591. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10592. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10593. }
  10594. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10595. {
  10596. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10597. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10598. }
  10599. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10600. {
  10601. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10602. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10603. }
  10604. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10605. {
  10606. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10607. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10608. }
  10609. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10610. {
  10611. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10612. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10613. }
  10614. }
  10615. fclose(fp);
  10616. }
  10617. return 0;
  10618. }
  10619. void StoreConfigurationTable(void)
  10620. {
  10621. FILE *outfile;
  10622. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10623. if(outfile == NULL)
  10624. {
  10625. DEBUG_INFO("Error opening file");
  10626. return ;
  10627. }
  10628. /*Core Profile*/
  10629. //AllowOfflineTxForUnknownId
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10632. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10634. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10635. */
  10636. //DEBUG_INFO("data=%s\n",data);
  10637. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10638. //AuthorizationCacheEnabled
  10639. /*
  10640. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10642. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10643. */
  10644. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10645. //AuthorizeRemoteTxRequests
  10646. /*
  10647. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10649. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10650. */
  10651. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10652. //BlinkRepeat
  10653. /*
  10654. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10656. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10657. */
  10658. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10659. //ClockAlignedDataInterval
  10660. /*
  10661. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10663. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10664. */
  10665. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10666. //ConnectionTimeOut
  10667. /*
  10668. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10671. */
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10673. //GetConfigurationMaxKeys
  10674. /*
  10675. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10678. */
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10680. // HeartbeatInterval
  10681. /*
  10682. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10685. */
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10687. // LightIntensity
  10688. /*
  10689. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10692. */
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10694. // LocalAuthorizeOffline
  10695. /*
  10696. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10699. */
  10700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10701. // LocalPreAuthorize
  10702. /*
  10703. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10705. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10706. */
  10707. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10708. // MaxEnergyOnInvalidId
  10709. /*
  10710. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10713. */
  10714. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10715. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10716. // MeterValuesAlignedData
  10717. /*
  10718. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10720. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10721. */
  10722. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10723. // MeterValuesAlignedDataMaxLength
  10724. /*
  10725. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10727. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10728. */
  10729. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10730. // MeterValuesSampledData
  10731. /*
  10732. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10734. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10735. */
  10736. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10737. // MeterValuesSampledDataMaxLength
  10738. /*
  10739. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10741. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10742. */
  10743. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10744. // MeterValueSampleInterval
  10745. /*
  10746. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10749. */
  10750. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10751. // MinimumStatusDuration
  10752. /*
  10753. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10754. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10755. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10756. */
  10757. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10758. // NumberOfConnectors
  10759. /*
  10760. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10761. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10762. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10763. {
  10764. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10765. }
  10766. else
  10767. {
  10768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10769. }
  10770. */
  10771. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10772. // ResetRetries
  10773. /*
  10774. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10776. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10777. */
  10778. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10779. // ConnectorPhaseRotation
  10780. /*
  10781. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10784. */
  10785. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10786. // ConnectorPhaseRotationMaxLength
  10787. /*
  10788. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10791. */
  10792. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10793. // StopTransactionOnEVSideDisconnect
  10794. /*
  10795. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10797. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10798. */
  10799. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10800. // StopTransactionOnInvalidId
  10801. /*
  10802. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10805. */
  10806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10807. // StopTxnAlignedData
  10808. /*
  10809. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10811. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10812. */
  10813. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10814. // StopTxnAlignedDataMaxLength
  10815. /*
  10816. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10817. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10819. */
  10820. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10821. // StopTxnSampledData
  10822. /*
  10823. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10826. */
  10827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10828. // StopTxnSampledDataMaxLength
  10829. /*
  10830. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10832. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10833. */
  10834. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10835. // SupportedFeatureProfiles
  10836. /*
  10837. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10838. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10839. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10840. */
  10841. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10842. // SupportedFeatureProfilesMaxLength
  10843. /*
  10844. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10845. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10846. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10847. */
  10848. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10849. // TransactionMessageAttempts
  10850. /*
  10851. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10854. */
  10855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10856. // TransactionMessageRetryInterval
  10857. /*
  10858. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10861. */
  10862. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10863. // UnlockConnectorOnEVSideDisconnect
  10864. /*
  10865. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10868. */
  10869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10870. // WebSocketPingInterval
  10871. /*
  10872. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10875. */
  10876. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10877. //* Local Auth List Management Profile*/
  10878. //LocalAuthListEnabled
  10879. /*
  10880. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10881. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10883. */
  10884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10885. //LocalAuthListMaxLength
  10886. /*
  10887. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10889. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10890. */
  10891. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10892. //SendLocalListMaxLength
  10893. /*
  10894. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10897. */
  10898. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10899. //ReserveConnectorZeroSupported
  10900. /*
  10901. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10902. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10904. */
  10905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10906. //* Smart Charging Profile */
  10907. //ChargeProfileMaxStackLevel
  10908. /*
  10909. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10912. */
  10913. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10914. // ChargingScheduleAllowedChargingRateUnit
  10915. /*
  10916. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10917. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10919. */
  10920. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10921. // ChargingScheduleMaxPeriods
  10922. /*
  10923. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10926. */
  10927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10928. // ConnectorSwitch3to1PhaseSupported
  10929. /*
  10930. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10933. */
  10934. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10935. // MaxChargingProfilesInstalled
  10936. /*
  10937. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10939. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10940. */
  10941. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10942. fclose(outfile);
  10943. }
  10944. void getKeyValue(char *keyReq)
  10945. {
  10946. int isEmpty = FALSE;
  10947. int isKnowKey = FALSE;
  10948. DEBUG_INFO("keyReq = %s\n", keyReq);
  10949. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10950. isEmpty = TRUE;
  10951. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10958. }
  10959. else
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10962. }
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10964. isKnowKey = TRUE;
  10965. }
  10966. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10973. }
  10974. else
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10977. }
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10979. isKnowKey = TRUE;
  10980. }
  10981. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10988. }
  10989. else
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10992. }
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10994. isKnowKey = TRUE;
  10995. }
  10996. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11003. }
  11004. else
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11007. }
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11009. isKnowKey = TRUE;
  11010. }
  11011. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11018. }
  11019. else
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11022. }
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11024. isKnowKey = TRUE;
  11025. }
  11026. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11033. }
  11034. else
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11037. }
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11039. isKnowKey = TRUE;
  11040. }
  11041. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11048. }
  11049. else
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11052. }
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11054. isKnowKey = TRUE;
  11055. }
  11056. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11063. }
  11064. else
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11067. }
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11069. isKnowKey = TRUE;
  11070. }
  11071. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11078. }
  11079. else
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11082. }
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11084. isKnowKey = TRUE;
  11085. }
  11086. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11093. }
  11094. else
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11097. }
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11129. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11130. isKnowKey = TRUE;
  11131. }
  11132. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11135. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11136. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11139. }
  11140. else
  11141. {
  11142. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11143. }
  11144. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11145. isKnowKey = TRUE;
  11146. }
  11147. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11150. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11151. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11154. }
  11155. else
  11156. {
  11157. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11158. }
  11159. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11160. isKnowKey = TRUE;
  11161. }
  11162. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11165. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11166. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11169. }
  11170. else
  11171. {
  11172. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11173. }
  11174. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11175. isKnowKey = TRUE;
  11176. }
  11177. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11180. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11181. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11184. }
  11185. else
  11186. {
  11187. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11188. }
  11189. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11190. isKnowKey = TRUE;
  11191. }
  11192. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11195. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11196. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11199. }
  11200. else
  11201. {
  11202. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11203. }
  11204. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11205. isKnowKey = TRUE;
  11206. }
  11207. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11210. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11214. }
  11215. else
  11216. {
  11217. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11218. }
  11219. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11220. isKnowKey = TRUE;
  11221. }
  11222. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11225. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11229. }
  11230. else
  11231. {
  11232. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11233. }
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11235. isKnowKey = TRUE;
  11236. }
  11237. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11250. isKnowKey = TRUE;
  11251. }
  11252. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11259. }
  11260. else
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11263. }
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11265. isKnowKey = TRUE;
  11266. }
  11267. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11274. }
  11275. else
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11278. }
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11280. isKnowKey = TRUE;
  11281. }
  11282. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11289. }
  11290. else
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11293. }
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11295. isKnowKey = TRUE;
  11296. }
  11297. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11304. }
  11305. else
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11308. }
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11310. isKnowKey = TRUE;
  11311. }
  11312. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11313. {
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11316. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11317. {
  11318. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11319. }
  11320. else
  11321. {
  11322. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11323. }
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11325. isKnowKey = TRUE;
  11326. }
  11327. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11328. {
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11331. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11332. {
  11333. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11334. }
  11335. else
  11336. {
  11337. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11338. }
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11340. isKnowKey = TRUE;
  11341. }
  11342. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11355. isKnowKey = TRUE;
  11356. }
  11357. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11364. }
  11365. else
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11368. }
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11370. isKnowKey = TRUE;
  11371. }
  11372. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11379. }
  11380. else
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11383. }
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11385. isKnowKey = TRUE;
  11386. }
  11387. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11394. }
  11395. else
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11398. }
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11400. isKnowKey = TRUE;
  11401. }
  11402. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11409. }
  11410. else
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11413. }
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11415. isKnowKey = TRUE;
  11416. }
  11417. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11418. {
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11421. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11422. {
  11423. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11424. }
  11425. else
  11426. {
  11427. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11428. }
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11430. isKnowKey = TRUE;
  11431. }
  11432. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11433. {
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11436. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11437. {
  11438. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11439. }
  11440. else
  11441. {
  11442. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11443. }
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11445. isKnowKey = TRUE;
  11446. }
  11447. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11448. {
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11451. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11452. {
  11453. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11454. }
  11455. else
  11456. {
  11457. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11458. }
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11460. isKnowKey = TRUE;
  11461. }
  11462. #if 1
  11463. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11464. {
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11467. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11468. {
  11469. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11470. }
  11471. else
  11472. {
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11474. }
  11475. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11476. isKnowKey = TRUE;
  11477. }
  11478. #endif
  11479. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11483. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11486. }
  11487. else
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11490. }
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11492. isKnowKey = TRUE;
  11493. }
  11494. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11498. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11501. }
  11502. else
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11505. }
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11507. isKnowKey = TRUE;
  11508. }
  11509. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11513. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11516. }
  11517. else
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11520. }
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11522. isKnowKey = TRUE;
  11523. }
  11524. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11528. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11531. }
  11532. else
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11535. }
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11537. isKnowKey = TRUE;
  11538. }
  11539. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11543. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11546. }
  11547. else
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11550. }
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11552. isKnowKey = TRUE;
  11553. }
  11554. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11555. {
  11556. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11557. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11558. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11561. }
  11562. else
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11565. }
  11566. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11567. isKnowKey = TRUE;
  11568. }
  11569. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11570. {
  11571. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11572. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11573. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11574. {
  11575. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11576. }
  11577. else
  11578. {
  11579. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11580. }
  11581. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11582. isKnowKey = TRUE;
  11583. }
  11584. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11585. {
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11587. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11588. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11589. {
  11590. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11591. }
  11592. else
  11593. {
  11594. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11595. }
  11596. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11597. isKnowKey = TRUE;
  11598. }
  11599. //=========================================================
  11600. if(!isEmpty && !isKnowKey)
  11601. {
  11602. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11603. strcpy(unknownkey[UnknownKeynum], keyReq);
  11604. UnknownKeynum = UnknownKeynum + 1;
  11605. }
  11606. }
  11607. void processUnkownKey(void)
  11608. {
  11609. DEBUG_INFO("processUnkownKey...\n");
  11610. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11611. for(int index=0; index < UnknownKeynum; index++)
  11612. {
  11613. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11614. {
  11615. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11616. }
  11617. }
  11618. }
  11619. int setKeyValue(char *key, char *value)
  11620. {
  11621. int isSuccess = NotSupported;
  11622. int check_ascii=0;
  11623. char str[10]={0};
  11624. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11625. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11626. {
  11627. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11628. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11629. {
  11630. strcpy(str, (const char*)value);
  11631. for(int i = 0; str[i]; i++){
  11632. str[i] = tolower(str[i]);
  11633. }
  11634. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11635. isSuccess = ConfigurationStatus_Accepted;
  11636. }
  11637. else
  11638. {
  11639. isSuccess = ConfigurationStatus_Rejected;
  11640. }
  11641. }
  11642. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11643. {
  11644. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11645. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11646. {
  11647. strcpy(str, (const char*)value);
  11648. for(int i = 0; str[i]; i++){
  11649. str[i] = tolower(str[i]);
  11650. }
  11651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11652. isSuccess = ConfigurationStatus_Accepted;
  11653. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11654. }
  11655. else
  11656. {
  11657. isSuccess = ConfigurationStatus_Rejected;
  11658. }
  11659. }
  11660. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11661. {
  11662. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11663. {
  11664. strcpy(str, (const char*)value);
  11665. for(int i = 0; str[i]; i++)
  11666. {
  11667. str[i] = tolower(str[i]);
  11668. }
  11669. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11670. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11671. isSuccess = ConfigurationStatus_Accepted;
  11672. }
  11673. else
  11674. {
  11675. isSuccess = ConfigurationStatus_Rejected;
  11676. }
  11677. }
  11678. if(strcmp(key, "BlinkRepeat") == 0)
  11679. {
  11680. //Charger.BlinkRepeat = Integer.parseInt(value);
  11681. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11682. {
  11683. check_ascii = value[0];
  11684. if( (check_ascii < 48) || (check_ascii > 57) )
  11685. {
  11686. isSuccess = ConfigurationStatus_Rejected;
  11687. }
  11688. else
  11689. {
  11690. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11691. isSuccess = ConfigurationStatus_Accepted;
  11692. }
  11693. }
  11694. else
  11695. {
  11696. isSuccess = ConfigurationStatus_Rejected;
  11697. }
  11698. }
  11699. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11700. {
  11701. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11702. {
  11703. check_ascii = value[0];
  11704. if( (check_ascii < 48) || (check_ascii > 57) )
  11705. {
  11706. isSuccess = ConfigurationStatus_Rejected;
  11707. }
  11708. else
  11709. {
  11710. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11712. isSuccess = ConfigurationStatus_Accepted;
  11713. }
  11714. }
  11715. else
  11716. {
  11717. isSuccess = ConfigurationStatus_Rejected;
  11718. }
  11719. }
  11720. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11721. {
  11722. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11723. {
  11724. check_ascii = value[0];
  11725. if( (check_ascii < 48) || (check_ascii > 57) )
  11726. {
  11727. isSuccess = ConfigurationStatus_Rejected;
  11728. }
  11729. else
  11730. {
  11731. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11732. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11733. isSuccess = ConfigurationStatus_Accepted;
  11734. }
  11735. }
  11736. else
  11737. {
  11738. isSuccess = ConfigurationStatus_Rejected;
  11739. }
  11740. }
  11741. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11742. {
  11743. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11744. {
  11745. check_ascii = value[0];
  11746. if( (check_ascii < 48) || (check_ascii > 57) )
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. else
  11751. {
  11752. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11753. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11754. isSuccess = ConfigurationStatus_Accepted;
  11755. }
  11756. }
  11757. else
  11758. {
  11759. isSuccess = ConfigurationStatus_Rejected;
  11760. }
  11761. }
  11762. if(strcmp(key, "HeartbeatInterval") == 0)
  11763. {
  11764. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11765. {
  11766. check_ascii = value[0];
  11767. if( (check_ascii < 48) || (check_ascii > 57) )
  11768. {
  11769. isSuccess = ConfigurationStatus_Rejected;
  11770. }
  11771. else
  11772. {
  11773. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11774. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11775. HeartBeatWaitTime = atoi(value);
  11776. isSuccess = ConfigurationStatus_Accepted;
  11777. }
  11778. }
  11779. else
  11780. {
  11781. isSuccess = ConfigurationStatus_Rejected;
  11782. }
  11783. }
  11784. if(strcmp(key, "LightIntensity") == 0)
  11785. {
  11786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11787. {
  11788. check_ascii = value[0];
  11789. if( (check_ascii < 48) || (check_ascii > 57) )
  11790. {
  11791. isSuccess = ConfigurationStatus_Rejected;
  11792. }
  11793. else
  11794. {
  11795. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11796. isSuccess = ConfigurationStatus_Accepted;
  11797. }
  11798. }
  11799. else
  11800. {
  11801. isSuccess = ConfigurationStatus_Rejected;
  11802. }
  11803. }
  11804. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11805. {
  11806. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11807. {
  11808. strcpy(str, (const char*)value);
  11809. for(int i = 0; str[i]; i++)
  11810. {
  11811. str[i] = tolower(str[i]);
  11812. }
  11813. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11814. isSuccess = ConfigurationStatus_Accepted;
  11815. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11816. }
  11817. else
  11818. {
  11819. isSuccess = ConfigurationStatus_Rejected;
  11820. }
  11821. }
  11822. if(strcmp(key, "LocalPreAuthorize") == 0)
  11823. {
  11824. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11825. {
  11826. strcpy(str, (const char*)value);
  11827. for(int i = 0; str[i]; i++)
  11828. {
  11829. str[i] = tolower(str[i]);
  11830. }
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. else
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. }
  11839. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11840. {
  11841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11842. {
  11843. check_ascii = value[0];
  11844. if( (check_ascii < 48) || (check_ascii > 57) )
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. else
  11849. {
  11850. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11851. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11863. {
  11864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11865. isSuccess = ConfigurationStatus_Accepted;
  11866. }
  11867. else
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. }
  11872. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11873. {
  11874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11875. {
  11876. check_ascii = value[0];
  11877. if( (check_ascii < 48) || (check_ascii > 57) )
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. else
  11882. {
  11883. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11885. isSuccess = ConfigurationStatus_Accepted;
  11886. }
  11887. }
  11888. else
  11889. {
  11890. isSuccess = ConfigurationStatus_Rejected;
  11891. }
  11892. }
  11893. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11894. {
  11895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11896. {
  11897. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11898. isSuccess = ConfigurationStatus_Accepted;
  11899. }
  11900. else
  11901. {
  11902. isSuccess = ConfigurationStatus_Rejected;
  11903. }
  11904. }
  11905. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11906. {
  11907. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11908. {
  11909. check_ascii = value[0];
  11910. if( (check_ascii < 48) || (check_ascii > 57) )
  11911. {
  11912. isSuccess = ConfigurationStatus_Rejected;
  11913. }
  11914. else
  11915. {
  11916. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11917. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11918. isSuccess = ConfigurationStatus_Accepted;
  11919. }
  11920. }
  11921. else
  11922. {
  11923. isSuccess = ConfigurationStatus_Rejected;
  11924. }
  11925. }
  11926. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11927. {
  11928. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11929. {
  11930. check_ascii = value[0];
  11931. if( (check_ascii < 48) || (check_ascii > 57) )
  11932. {
  11933. isSuccess = ConfigurationStatus_Rejected;
  11934. }
  11935. else
  11936. {
  11937. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11938. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11939. isSuccess = ConfigurationStatus_Accepted;
  11940. }
  11941. }
  11942. else
  11943. {
  11944. isSuccess = ConfigurationStatus_Rejected;
  11945. }
  11946. }
  11947. if(strcmp(key, "MinimumStatusDuration") == 0)
  11948. {
  11949. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11950. {
  11951. check_ascii = value[0];
  11952. if( (check_ascii < 48) || (check_ascii > 57) )
  11953. {
  11954. isSuccess = ConfigurationStatus_Rejected;
  11955. }
  11956. else
  11957. {
  11958. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11959. {
  11960. isSuccess = ConfigurationStatus_Rejected;
  11961. }
  11962. else
  11963. {
  11964. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11966. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11967. isSuccess = ConfigurationStatus_Accepted;
  11968. }
  11969. }
  11970. }
  11971. else
  11972. {
  11973. isSuccess = ConfigurationStatus_Rejected;
  11974. }
  11975. }
  11976. if(strcmp(key, "NumberOfConnectors") == 0)
  11977. {
  11978. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11979. {
  11980. check_ascii = value[0];
  11981. if( (check_ascii < 48) || (check_ascii > 57) )
  11982. {
  11983. isSuccess = ConfigurationStatus_Rejected;
  11984. }
  11985. else
  11986. {
  11987. //Charger.ResetRetries = Integer.parseInt(value);
  11988. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11989. isSuccess = ConfigurationStatus_Accepted;
  11990. }
  11991. }
  11992. else
  11993. {
  11994. isSuccess = ConfigurationStatus_Rejected;
  11995. }
  11996. }
  11997. if(strcmp(key, "ResetRetries") == 0)
  11998. {
  11999. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12000. {
  12001. check_ascii = value[0];
  12002. if( (check_ascii < 48) || (check_ascii > 57) )
  12003. {
  12004. isSuccess = ConfigurationStatus_Rejected;
  12005. }
  12006. else
  12007. {
  12008. //Charger.ResetRetries = Integer.parseInt(value);
  12009. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12010. isSuccess = ConfigurationStatus_Accepted;
  12011. }
  12012. }
  12013. else
  12014. {
  12015. isSuccess = ConfigurationStatus_Rejected;
  12016. }
  12017. }
  12018. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12019. {
  12020. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12021. {
  12022. strcpy(str, (const char*)value);
  12023. for(int i = 0; str[i]; i++)
  12024. {
  12025. str[i] = tolower(str[i]);
  12026. }
  12027. if(strcmp(str, "notapplicable")== 0)
  12028. {
  12029. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12030. isSuccess = ConfigurationStatus_Accepted;
  12031. }
  12032. else if(strcmp(str, "unknown")== 0)
  12033. {
  12034. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12035. isSuccess = ConfigurationStatus_Accepted;
  12036. }
  12037. else if(strcmp(str, "rst")== 0)
  12038. {
  12039. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12040. isSuccess = ConfigurationStatus_Accepted;
  12041. }
  12042. else if(strcmp(str, "rts")== 0)
  12043. {
  12044. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12045. isSuccess = ConfigurationStatus_Accepted;
  12046. }
  12047. else if(strcmp(str, "srt")== 0)
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12050. isSuccess = ConfigurationStatus_Accepted;
  12051. }
  12052. else if(strcmp(str, "str")== 0)
  12053. {
  12054. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12055. isSuccess = ConfigurationStatus_Accepted;
  12056. }
  12057. else if(strcmp(str, "trs")== 0)
  12058. {
  12059. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12060. isSuccess = ConfigurationStatus_Accepted;
  12061. }
  12062. else if(strcmp(str, "tsr")== 0)
  12063. {
  12064. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12065. isSuccess = ConfigurationStatus_Accepted;
  12066. }
  12067. else
  12068. {
  12069. isSuccess = ConfigurationStatus_Rejected;
  12070. }
  12071. }
  12072. else
  12073. {
  12074. isSuccess = ConfigurationStatus_Rejected;
  12075. }
  12076. }
  12077. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12078. {
  12079. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12080. {
  12081. check_ascii = value[0];
  12082. if( (check_ascii < 48) || (check_ascii > 57) )
  12083. {
  12084. isSuccess = ConfigurationStatus_Rejected;
  12085. }
  12086. else
  12087. {
  12088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12089. isSuccess = ConfigurationStatus_Accepted;
  12090. }
  12091. }
  12092. else
  12093. {
  12094. isSuccess = ConfigurationStatus_Rejected;
  12095. }
  12096. }
  12097. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12098. {
  12099. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12100. {
  12101. strcpy(str, (const char*)value);
  12102. for(int i = 0; str[i]; i++)
  12103. {
  12104. str[i] = tolower(str[i]);
  12105. }
  12106. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12107. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12108. isSuccess = ConfigurationStatus_Accepted;
  12109. }
  12110. else
  12111. {
  12112. isSuccess = ConfigurationStatus_Rejected;
  12113. }
  12114. }
  12115. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12116. {
  12117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12118. {
  12119. strcpy(str, (const char*)value);
  12120. for(int i = 0; str[i]; i++)
  12121. {
  12122. str[i] = tolower(str[i]);
  12123. }
  12124. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12126. isSuccess = ConfigurationStatus_Accepted;
  12127. }
  12128. else
  12129. {
  12130. isSuccess = ConfigurationStatus_Rejected;
  12131. }
  12132. }
  12133. if(strcmp(key, "StopTxnAlignedData") == 0)
  12134. {
  12135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12136. {
  12137. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12138. isSuccess = ConfigurationStatus_Accepted;
  12139. }
  12140. else
  12141. {
  12142. isSuccess = ConfigurationStatus_Rejected;
  12143. }
  12144. }
  12145. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12146. {
  12147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12148. {
  12149. check_ascii = value[0];
  12150. if( (check_ascii < 48) || (check_ascii > 57) )
  12151. {
  12152. isSuccess = ConfigurationStatus_Rejected;
  12153. }
  12154. else
  12155. {
  12156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12157. isSuccess = ConfigurationStatus_Accepted;
  12158. }
  12159. }
  12160. else
  12161. {
  12162. isSuccess = ConfigurationStatus_Rejected;
  12163. }
  12164. }
  12165. if(strcmp(key, "StopTxnSampledData") == 0)
  12166. {
  12167. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12168. {
  12169. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12170. isSuccess = ConfigurationStatus_Accepted;
  12171. }
  12172. else
  12173. {
  12174. isSuccess = ConfigurationStatus_Rejected;
  12175. }
  12176. }
  12177. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12178. {
  12179. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12180. {
  12181. check_ascii = value[0];
  12182. if( (check_ascii < 48) || (check_ascii > 57) )
  12183. {
  12184. isSuccess = ConfigurationStatus_Rejected;
  12185. }
  12186. else
  12187. {
  12188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12189. isSuccess = ConfigurationStatus_Accepted;
  12190. }
  12191. }
  12192. else
  12193. {
  12194. isSuccess = ConfigurationStatus_Rejected;
  12195. }
  12196. }
  12197. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12198. {
  12199. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12200. {
  12201. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12202. isSuccess = ConfigurationStatus_Accepted;
  12203. }
  12204. else
  12205. {
  12206. isSuccess = ConfigurationStatus_Rejected;
  12207. }
  12208. }
  12209. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12210. {
  12211. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12212. {
  12213. check_ascii = value[0];
  12214. if( (check_ascii < 48) || (check_ascii > 57) )
  12215. {
  12216. isSuccess = ConfigurationStatus_Rejected;
  12217. }
  12218. else
  12219. {
  12220. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12221. isSuccess = ConfigurationStatus_Accepted;
  12222. }
  12223. }
  12224. else
  12225. {
  12226. isSuccess = ConfigurationStatus_Rejected;
  12227. }
  12228. }
  12229. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12230. {
  12231. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12232. {
  12233. check_ascii = value[0];
  12234. if( (check_ascii < 48) || (check_ascii > 57) )
  12235. {
  12236. isSuccess = ConfigurationStatus_Rejected;
  12237. }
  12238. else
  12239. {
  12240. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12241. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12242. TransactionMessageAttemptsValue = atoi(value);
  12243. isSuccess = ConfigurationStatus_Accepted;
  12244. }
  12245. }
  12246. else
  12247. {
  12248. isSuccess = ConfigurationStatus_Rejected;
  12249. }
  12250. }
  12251. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12252. {
  12253. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12254. {
  12255. check_ascii = value[0];
  12256. if( (check_ascii < 48) || (check_ascii > 57) )
  12257. {
  12258. isSuccess = ConfigurationStatus_Rejected;
  12259. }
  12260. else
  12261. {
  12262. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12264. TransactionMessageRetryIntervalValue = atoi(value);
  12265. isSuccess = ConfigurationStatus_Accepted;
  12266. }
  12267. }
  12268. else
  12269. {
  12270. isSuccess = ConfigurationStatus_Rejected;
  12271. }
  12272. }
  12273. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12274. {
  12275. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12276. {
  12277. strcpy(str, (const char*)value);
  12278. for(int i = 0; str[i]; i++)
  12279. {
  12280. str[i] = tolower(str[i]);
  12281. }
  12282. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12283. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12284. isSuccess = ConfigurationStatus_Accepted;
  12285. }
  12286. else
  12287. {
  12288. isSuccess = ConfigurationStatus_Rejected;
  12289. }
  12290. }
  12291. if(strcmp(key, "WebSocketPingInterval") == 0)
  12292. {
  12293. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12294. {
  12295. check_ascii = value[0];
  12296. if( (check_ascii < 48) || (check_ascii > 57) )
  12297. {
  12298. isSuccess = ConfigurationStatus_Rejected;
  12299. }
  12300. else
  12301. {
  12302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12303. isSuccess = ConfigurationStatus_Accepted;
  12304. }
  12305. }
  12306. else
  12307. {
  12308. isSuccess = ConfigurationStatus_Rejected;
  12309. }
  12310. }
  12311. #if 0
  12312. //For OCPP Test Case
  12313. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12316. {
  12317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12318. isSuccess = ConfigurationStatus_Accepted;
  12319. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12320. }
  12321. else
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. }
  12326. #endif
  12327. #if 1
  12328. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12329. {
  12330. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12331. {
  12332. strcpy(str, (const char*)value);
  12333. for(int i = 0; str[i]; i++)
  12334. {
  12335. str[i] = tolower(str[i]);
  12336. }
  12337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12338. isSuccess = ConfigurationStatus_Accepted;
  12339. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12340. }
  12341. else
  12342. {
  12343. isSuccess = ConfigurationStatus_Rejected;
  12344. }
  12345. }
  12346. #endif
  12347. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12348. {
  12349. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12350. {
  12351. check_ascii = value[0];
  12352. if( (check_ascii < 48) || (check_ascii > 57) )
  12353. {
  12354. isSuccess = ConfigurationStatus_Rejected;
  12355. }
  12356. else
  12357. {
  12358. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12359. isSuccess = ConfigurationStatus_Accepted;
  12360. }
  12361. }
  12362. else
  12363. {
  12364. isSuccess = ConfigurationStatus_Rejected;
  12365. }
  12366. }
  12367. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12370. {
  12371. check_ascii = value[0];
  12372. if( (check_ascii < 48) || (check_ascii > 57) )
  12373. {
  12374. isSuccess = ConfigurationStatus_Rejected;
  12375. }
  12376. else
  12377. {
  12378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12379. isSuccess = ConfigurationStatus_Accepted;
  12380. }
  12381. }
  12382. else
  12383. {
  12384. isSuccess = ConfigurationStatus_Rejected;
  12385. }
  12386. }
  12387. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12390. {
  12391. strcpy(str, (const char*)value);
  12392. for(int i = 0; str[i]; i++)
  12393. {
  12394. str[i] = tolower(str[i]);
  12395. }
  12396. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12397. isSuccess = ConfigurationStatus_Accepted;
  12398. }
  12399. else
  12400. {
  12401. isSuccess = ConfigurationStatus_Rejected;
  12402. }
  12403. }
  12404. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12405. {
  12406. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12407. {
  12408. check_ascii = value[0];
  12409. if( (check_ascii < 48) || (check_ascii > 57) )
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. else
  12414. {
  12415. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12416. isSuccess = ConfigurationStatus_Accepted;
  12417. }
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12425. {
  12426. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12427. {
  12428. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12429. isSuccess = ConfigurationStatus_Accepted;
  12430. }
  12431. else
  12432. {
  12433. isSuccess = ConfigurationStatus_Rejected;
  12434. }
  12435. }
  12436. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12437. {
  12438. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12439. {
  12440. check_ascii = value[0];
  12441. if( (check_ascii < 48) || (check_ascii > 57) )
  12442. {
  12443. isSuccess = ConfigurationStatus_Rejected;
  12444. }
  12445. else
  12446. {
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12448. isSuccess = ConfigurationStatus_Accepted;
  12449. }
  12450. }
  12451. else
  12452. {
  12453. isSuccess = ConfigurationStatus_Rejected;
  12454. }
  12455. }
  12456. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12457. {
  12458. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12459. {
  12460. strcpy(str, (const char*)value);
  12461. for(int i = 0; str[i]; i++)
  12462. {
  12463. str[i] = tolower(str[i]);
  12464. }
  12465. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12466. isSuccess = ConfigurationStatus_Accepted;
  12467. }
  12468. else
  12469. {
  12470. isSuccess = ConfigurationStatus_Rejected;
  12471. }
  12472. }
  12473. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12474. {
  12475. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12476. {
  12477. check_ascii = value[0];
  12478. if( (check_ascii < 48) || (check_ascii > 57) )
  12479. {
  12480. isSuccess = ConfigurationStatus_Rejected;
  12481. }
  12482. else
  12483. {
  12484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12485. isSuccess = ConfigurationStatus_Accepted;
  12486. }
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. return isSuccess;
  12494. }
  12495. int TransactionMessageAttemptsGet(void)
  12496. {
  12497. return TransactionMessageAttemptsValue;
  12498. }
  12499. int FirstHeartBeatResponse(void)
  12500. {
  12501. return FirstHeartBeat;
  12502. }
  12503. int TransactionMessageRetryIntervalGet(void)
  12504. {
  12505. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12506. }
  12507. int ReadHttpStatus(int sock)
  12508. {
  12509. //char c;
  12510. char buff[1024]="",*ptr=buff+1;
  12511. int bytes_received, status;
  12512. DEBUG_INFO("Begin Response ..\n");
  12513. while((bytes_received = recv(sock, ptr, 1, 0))){
  12514. if(bytes_received==-1){
  12515. perror("ReadHttpStatus");
  12516. exit(1);
  12517. }
  12518. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12519. ptr++;
  12520. }
  12521. *ptr=0;
  12522. ptr=buff+1;
  12523. sscanf(ptr,"%*s %d ", &status);
  12524. DEBUG_INFO("%s\n",ptr);
  12525. DEBUG_INFO("status=%d\n",status);
  12526. DEBUG_INFO("End Response ..\n");
  12527. return (bytes_received>0)?status:0;
  12528. }
  12529. //the only filed that it parsed is 'Content-Length'
  12530. int ParseHeader(int sock)
  12531. {
  12532. //char c;
  12533. char buff[1024]="",*ptr=buff+4;
  12534. int bytes_received;
  12535. DEBUG_INFO("Begin HEADER ..\n");
  12536. while((bytes_received = recv(sock, ptr, 1, 0))){
  12537. if(bytes_received==-1){
  12538. perror("Parse Header");
  12539. exit(1);
  12540. }
  12541. if(
  12542. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12543. (ptr[-1]=='\r') && (*ptr=='\n' )
  12544. ) break;
  12545. ptr++;
  12546. }
  12547. *ptr=0;
  12548. ptr=buff+4;
  12549. //printf("%s",ptr);
  12550. if(bytes_received){
  12551. ptr=strstr(ptr,"Content-Length:");
  12552. if(ptr){
  12553. sscanf(ptr,"%*s %d",&bytes_received);
  12554. }else
  12555. bytes_received=-1; //unknown size
  12556. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12557. }
  12558. DEBUG_INFO("End HEADER ..\n");
  12559. return bytes_received ;
  12560. }
  12561. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12562. {
  12563. char rmFileCmd[100]={0};
  12564. char FilePath[100]={0};
  12565. char ftpbuf[200];
  12566. int systemresult;
  12567. //DEBUG_INFO("filename=%s\n",filename);
  12568. //DEBUG_INFO("url=%s\n",url);
  12569. sprintf(FilePath,"/mnt/%s",filename);
  12570. if((access(FilePath,F_OK))!=-1)
  12571. {
  12572. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12573. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12574. system(rmFileCmd);
  12575. }
  12576. memset(ftpbuf, 0, sizeof(ftpbuf));
  12577. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12578. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12579. systemresult = system(ftpbuf);
  12580. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12581. if(systemresult != 0)
  12582. {
  12583. DEBUG_INFO("http DownLoad error!\n");
  12584. return FALSE;
  12585. }
  12586. return TRUE;
  12587. }
  12588. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12589. {
  12590. char rmFileCmd[100]={0};
  12591. char FilePath[100]={0};
  12592. char ftpbuf[200];
  12593. int systemresult;
  12594. //char temp[100];
  12595. sprintf(FilePath,"/mnt/%s",filename);
  12596. if((access(FilePath,F_OK))!=-1)
  12597. {
  12598. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12599. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12600. system(rmFileCmd);
  12601. }
  12602. memset(ftpbuf, 0, sizeof(ftpbuf));
  12603. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s",filename, url);
  12604. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12605. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12606. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12607. systemresult = system(ftpbuf);
  12608. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12609. if(systemresult != 0)
  12610. {
  12611. printf("wget error!\n");
  12612. return FALSE;
  12613. }
  12614. return TRUE;
  12615. }
  12616. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12617. {
  12618. char rmFileCmd[100]={0};
  12619. char FilePath[100]={0};
  12620. char ftpbuf[200];
  12621. int systemresult;
  12622. //DEBUG_INFO("filename=%s\n",filename);
  12623. //DEBUG_INFO("url=%s\n",url);
  12624. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12625. if((access(FilePath,F_OK))!=-1)
  12626. {
  12627. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12628. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12629. system(rmFileCmd);
  12630. }
  12631. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12632. if(fp == NULL)
  12633. {
  12634. DEBUG_INFO("log is NULL\n");
  12635. return FALSE;
  12636. }
  12637. else
  12638. {
  12639. fprintf(fp, "%s\n", url);
  12640. fprintf(fp, "%s\n", filename);
  12641. fclose(fp);
  12642. }
  12643. memset(ftpbuf, 0, sizeof(ftpbuf));
  12644. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12645. systemresult = system(ftpbuf);
  12646. DEBUG_INFO("systemresult = %d\n",systemresult);
  12647. if(systemresult != 0)
  12648. {
  12649. DEBUG_INFO("http upload error!\n");
  12650. return FALSE;
  12651. }
  12652. return TRUE;
  12653. }
  12654. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12655. {
  12656. struct hostent* server;
  12657. char *IPbuffer;
  12658. char ftpbuf[200];
  12659. int systemresult;
  12660. // To retrieve host information
  12661. server = gethostbyname(location);
  12662. // To convert an Internet network
  12663. // address into ASCII string
  12664. IPbuffer = inet_ntoa(*((struct in_addr*)
  12665. server->h_addr_list[0]));
  12666. memset(ftpbuf, 0, sizeof(ftpbuf));
  12667. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12668. /* format : ftpput -u username -p passwd IP target source*/
  12669. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12670. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12671. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12672. systemresult = system(ftpbuf);
  12673. DEBUG_INFO("systemresult=%d\n",systemresult);
  12674. if(systemresult != 0)
  12675. {
  12676. DEBUG_INFO("ftpput error!\n");
  12677. return FALSE;
  12678. }
  12679. return TRUE;
  12680. }
  12681. /**
  12682. * Place the contents of the specified file into a memory buffer
  12683. *
  12684. * @param[in] filename The path and name of the file to read
  12685. * @param[out] filebuffer A pointer to the contents in memory
  12686. * @return status 0 success, 1 on failure
  12687. */
  12688. int get_file_contents(const char* filename, char** outbuffer) {
  12689. FILE* file = NULL;
  12690. long filesize;
  12691. const int blocksize = 1;
  12692. size_t readsize;
  12693. char* filebuffer;
  12694. // Open the file
  12695. file = fopen(filename, "r");
  12696. if (NULL == file)
  12697. {
  12698. printf("'%s' not opened\n", filename);
  12699. exit(EXIT_FAILURE);
  12700. }
  12701. // Determine the file size
  12702. fseek(file, 0, SEEK_END);
  12703. filesize = ftell(file);
  12704. rewind (file);
  12705. // Allocate memory for the file contents
  12706. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12707. *outbuffer = filebuffer;
  12708. if (filebuffer == NULL)
  12709. {
  12710. fputs ("malloc out-of-memory", stderr);
  12711. exit(EXIT_FAILURE);
  12712. }
  12713. // Read in the file
  12714. readsize = fread(filebuffer, blocksize, filesize, file);
  12715. if (readsize != filesize)
  12716. {
  12717. fputs ("didn't read file completely",stderr);
  12718. exit(EXIT_FAILURE);
  12719. }
  12720. // Clean exit
  12721. fclose(file);
  12722. return EXIT_SUCCESS;
  12723. }
  12724. static int selectSqlCount = 0;
  12725. static int callback(void *data, int argc, char **argv, char **azColName){
  12726. int i;
  12727. //printf("%s: ", (const char*)data);
  12728. selectSqlCount = argc;
  12729. for(i = 0; i<argc; i++){
  12730. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12731. }
  12732. //printf("\n");
  12733. return 0;
  12734. }
  12735. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12736. //int i;
  12737. //printf("%s:\n", (const char*)data);
  12738. localversion = argv[5] ? atoi(argv[5]) : 0;
  12739. //printf("localversion=%d\n", localversion);
  12740. return 0;
  12741. }
  12742. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12743. //int i;
  12744. //printf("%s:\n", (const char*)data);
  12745. //idTag
  12746. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12747. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12748. //parentIdTag
  12749. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12750. //expir_date
  12751. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12752. //status
  12753. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12754. //version
  12755. idTagQuery.listVersionInt = atoi(argv[5]);
  12756. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12757. return 0;
  12758. }
  12759. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12760. {
  12761. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12762. // printf("localversion=%d\n", localversion);
  12763. return 0;
  12764. }
  12765. //=========================================
  12766. // Sqlite3 related function
  12767. //=========================================
  12768. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12769. {
  12770. for (int i = 0; i < n_columns; i++)
  12771. {
  12772. DEBUG_INFO("%s/t", col_values[i]);
  12773. }
  12774. DEBUG_INFO("/n");
  12775. return 0;
  12776. }
  12777. void OCPP_getListVerion()
  12778. {
  12779. int rc = 0;
  12780. // const char* data = "Callback function called";
  12781. char sql[100];
  12782. char zErrMsg[100];
  12783. memset(sql, 0, 100);
  12784. memset(zErrMsg, 0, 100);
  12785. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12786. /* Execute SQL statement */
  12787. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12788. if( rc != SQLITE_OK )
  12789. {
  12790. DEBUG_INFO("SQL error: %s", zErrMsg);
  12791. }
  12792. }
  12793. void OCPP_getIdTag(char idTag[])
  12794. {
  12795. int rc = 0;
  12796. // const char* data = "Callback function called";
  12797. char sql[100];
  12798. char zErrMsg[100];
  12799. memset(sql, 0, 100);
  12800. memset(zErrMsg, 0, 100);
  12801. memset(idTagAuthorization, 0, sizeof(idTagAuthorization));
  12802. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12803. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12804. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12805. /* Execute SQL statement */
  12806. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12807. if( rc != SQLITE_OK )
  12808. {
  12809. DEBUG_INFO("SQL error: %s", zErrMsg);
  12810. }
  12811. //return ver;
  12812. }
  12813. void OCPP_get_TableAuthlocalAllData(void)
  12814. {
  12815. int rc = 0;
  12816. char sql[100];
  12817. char zErrMsg[100];
  12818. memset(sql, 0, 100);
  12819. memset(zErrMsg, 0, 100);
  12820. sprintf(sql,"select * from ocpp_auth_local ");
  12821. /* Execute SQL statement */
  12822. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12823. if( rc != SQLITE_OK )
  12824. {
  12825. DEBUG_INFO("SQL error: %s", zErrMsg);
  12826. }
  12827. //return ver;
  12828. }
  12829. int OCPP_cleanLocalList()
  12830. {
  12831. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12832. char *errMsg = 0;
  12833. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12834. if (SQLITE_OK != rc)
  12835. {
  12836. DEBUG_INFO("%s\n",errMsg);
  12837. return FALSE;
  12838. }
  12839. return TRUE;
  12840. }
  12841. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12842. {
  12843. int isSuccess = FALSE;
  12844. int ret = 0;
  12845. //const char* data = "Callback function called";
  12846. char sql[300];
  12847. char zErrMsg[200];
  12848. memset(sql, 0, 300);
  12849. memset(zErrMsg, 0, 200);
  12850. 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);
  12851. //* Execute SQL statement */
  12852. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12853. if( ret != SQLITE_OK )
  12854. {
  12855. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12856. return isSuccess;
  12857. }
  12858. memset(sql, 0, 300);
  12859. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12860. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12861. if( ret != SQLITE_OK )
  12862. {
  12863. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12864. return isSuccess;
  12865. }
  12866. isSuccess = TRUE;
  12867. return isSuccess;
  12868. }
  12869. void OCPP_deleteIdTag(char idTag[])
  12870. {
  12871. //int ver = 0;
  12872. //int isSuccess = FALSE;
  12873. int rc = 0;
  12874. char sql[100];
  12875. char zErrMsg[100];
  12876. memset(sql, 0, 100);
  12877. memset(zErrMsg, 0, 100);
  12878. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12879. //* Execute SQL statement */
  12880. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12881. if( rc != SQLITE_OK )
  12882. {
  12883. DEBUG_INFO("SQL error: %s", zErrMsg);
  12884. }
  12885. }
  12886. int GetOcppServerURL()
  12887. {
  12888. int result = FALSE;
  12889. memset(OcppProtocol, 0, sizeof(OcppProtocol));
  12890. memset(OcppHost, 0, sizeof(OcppHost));
  12891. memset(OcppTempPath, 0, sizeof(OcppTempPath));
  12892. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12893. {
  12894. #if 1
  12895. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12896. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12897. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12898. #endif
  12899. result = TRUE;
  12900. goto End;
  12901. }
  12902. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12903. {
  12904. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12905. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12906. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12907. result = TRUE;
  12908. goto End;
  12909. }
  12910. else
  12911. {
  12912. strcpy(OcppHost,"");
  12913. }
  12914. End:
  12915. return result;
  12916. }
  12917. int GetOcppPath()
  12918. {
  12919. int result = FALSE;
  12920. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12921. {
  12922. if(OcppTempPath == NULL)
  12923. {
  12924. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12925. }
  12926. else
  12927. {
  12928. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12929. }
  12930. result = TRUE;
  12931. goto End;
  12932. }
  12933. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12934. {
  12935. if(OcppTempPath == NULL)
  12936. {
  12937. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12938. }
  12939. else
  12940. {
  12941. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12942. }
  12943. result = TRUE;
  12944. goto End;
  12945. }
  12946. else
  12947. {
  12948. strcpy(OcppPath,"");
  12949. }
  12950. End:
  12951. return result;
  12952. }
  12953. int GetOcppPort()
  12954. {
  12955. return OcppPort;
  12956. }
  12957. int GetOcppConnStatus(void)
  12958. {
  12959. return ShmOCPP16Data->OcppConnStatus;
  12960. }
  12961. void SetOcppConnStatus(uint8_t status)
  12962. {
  12963. ShmOCPP16Data->OcppConnStatus = status;
  12964. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12965. }
  12966. int GetHeartBeatWithNOResponse(void)
  12967. {
  12968. return HeartBeatWithNOResponse;
  12969. }
  12970. void SetHeartBeatWithNOResponse(void)
  12971. {
  12972. HeartBeatWithNOResponse = 0;
  12973. }
  12974. void GetStartTransactionIdTag(int gun_index)
  12975. {
  12976. memset(StartTransactionIdTagTemp, 0 ,sizeof(StartTransactionIdTagTemp));
  12977. strcpy(StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12978. DEBUG_INFO("gun_index=%d StartTransactionIdTagTemp=%s\n",gun_index,StartTransactionIdTagTemp);
  12979. }
  12980. int GetTransactionId(int gunindex, unsigned char idTag[])
  12981. {
  12982. char ch;
  12983. FILE *fptr1;
  12984. int temptransactionId;
  12985. char str[100]={0};
  12986. temptransactionId = 0;
  12987. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12988. {
  12989. DEBUG_INFO("test 1 \n");
  12990. return temptransactionId;
  12991. }
  12992. /*------ Read the file ----------------*/
  12993. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12994. if (!fptr1)
  12995. {
  12996. DEBUG_INFO("test 2 \n");
  12997. //printf(" File not found or unable to open the input file!!\n");
  12998. return temptransactionId;
  12999. }
  13000. ch=fgetc(fptr1);
  13001. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13002. rewind(fptr1);
  13003. if(ch!=EOF)
  13004. {
  13005. // printf("%c",ch);
  13006. while (fgets(str, 100, fptr1) != NULL)
  13007. {
  13008. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13009. if(str[0]=='\0')
  13010. {
  13011. break;
  13012. }
  13013. char *revbuf[8] = {0}; //存放分割後的子字串
  13014. int num = 0;//分割後子字串的個數
  13015. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13016. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13017. {
  13018. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13019. {
  13020. temptransactionId = atoi(revbuf[2]);
  13021. break;
  13022. }
  13023. }
  13024. }
  13025. }
  13026. fclose(fptr1);
  13027. /*------- End of reading ---------------*/
  13028. return temptransactionId;
  13029. }
  13030. void SetTransactionIdZero(int transactionId)
  13031. {
  13032. char ch;
  13033. FILE *fptr1, *fptr2;
  13034. int temptransactionId = 0;
  13035. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13036. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13037. if (!fptr1)
  13038. {
  13039. //printf(" File not found or unable to open the input file!!\n");
  13040. return ;
  13041. }
  13042. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13043. if (!fptr2)
  13044. {
  13045. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13046. fclose(fptr1);
  13047. return ;
  13048. }
  13049. ch=fgetc(fptr1);
  13050. rewind(fptr1);
  13051. if(ch!=EOF)
  13052. {
  13053. // copy all contents to the temporary file except the specific line
  13054. while (fgets(str, 100, fptr1) != NULL)
  13055. {
  13056. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13057. if(str[0]=='\0')
  13058. {
  13059. break;
  13060. }
  13061. char *revbuf[8] = {0};
  13062. int num = 0;
  13063. strcpy(strtemp, str);
  13064. splitstring(str,",",revbuf,&num);
  13065. if(revbuf[2][0] != '\0')
  13066. {
  13067. temptransactionId = atoi(revbuf[2]);
  13068. if(transactionId != temptransactionId)
  13069. {
  13070. fprintf(fptr2, "%s\n", strtemp);
  13071. }
  13072. }
  13073. }
  13074. }
  13075. fclose(fptr1);
  13076. fclose(fptr2);
  13077. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13078. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13079. /*------ Read the file ----------------*/
  13080. }
  13081. int InternetDisconnect(void)
  13082. {
  13083. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13084. }
  13085. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13086. void storeTempStopTransaction(int gun_index)
  13087. {
  13088. char guid[37]={0};
  13089. int tempIndex = 0;
  13090. DEBUG_INFO("storeTempStopTransaction...\n");
  13091. memset(queuedata, 0, sizeof(queuedata));
  13092. //ENERGY_ACTIVE_IMPORT_REGISTER
  13093. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13094. if(gunType[gun_index] == 'J')
  13095. {
  13096. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13097. {
  13098. tempIndex = ((gun_index==2) ? 1: 0);
  13099. }
  13100. else
  13101. {
  13102. tempIndex = gun_index;
  13103. }
  13104. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13105. {
  13106. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13107. {
  13108. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  13109. }
  13110. }// END OF CHAdeMO_QUANTITY
  13111. }
  13112. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13113. {
  13114. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13115. {
  13116. tempIndex = ((gun_index==2) ? 1: 0);
  13117. }
  13118. else
  13119. {
  13120. tempIndex = gun_index;
  13121. }
  13122. for (int index = 0; index < CCS_QUANTITY; index++)
  13123. {
  13124. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13125. {
  13126. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  13127. }
  13128. }// END OF CCS_QUANTITY
  13129. }
  13130. else if(gunType[gun_index] == 'G')
  13131. {
  13132. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13133. {
  13134. tempIndex = ((gun_index==2) ? 1: 0);
  13135. }
  13136. else
  13137. {
  13138. tempIndex = gun_index;
  13139. }
  13140. for (int index = 0; index < GB_QUANTITY; index++)
  13141. {
  13142. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13143. {
  13144. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  13145. }
  13146. }// END OF GB_QUANTITY
  13147. }
  13148. else
  13149. {
  13150. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13151. {
  13152. tempIndex = 2;
  13153. }
  13154. else
  13155. {
  13156. tempIndex = gun_index;
  13157. }
  13158. for (int index = 0; index < AC_QUANTITY; index++)
  13159. {
  13160. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13161. {
  13162. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  13163. }
  13164. }// END OF AC_QUANTITY
  13165. }
  13166. //Stop Transaction Time
  13167. struct timeval tmnow;
  13168. struct tm *tm;
  13169. char buf[28];//, usec_buf[6];
  13170. gettimeofday(&tmnow, NULL);
  13171. time_t t;
  13172. t = time(NULL);
  13173. /*UTC time and date*/
  13174. tm = gmtime(&t);
  13175. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13176. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13177. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13179. random_uuid(guid);
  13180. /***********************************transactionData******************************************************/
  13181. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13182. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13183. //=================================
  13184. //1. Transaction_Begin
  13185. //=================================
  13186. // Energy.Active.Export.Interval
  13187. //idx_sample=0;
  13188. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f",(float)(ShmOCPP16Data->StartTransaction[gun_index].MeterStart)); // MeterStart is 0~6553.5 kWh
  13189. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13190. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13191. 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*/]);
  13192. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13193. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13196. }
  13197. else
  13198. {
  13199. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13200. }
  13201. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13202. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13203. //=================================
  13204. //2. Transaction_End
  13205. //=================================
  13206. //2.1 Current.Export
  13207. //idx_sample=1;
  13208. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13209. if(gunType[gun_index] == 'J')
  13210. {
  13211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13212. {
  13213. tempIndex = ((gun_index==2) ? 1: 0);
  13214. }
  13215. else
  13216. {
  13217. tempIndex = gun_index;
  13218. }
  13219. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13220. {
  13221. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13222. {
  13223. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13224. }
  13225. }// End of for CHAdeMO_QUANTITY
  13226. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13227. }
  13228. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13229. {
  13230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13231. {
  13232. tempIndex = ((gun_index==2) ? 1: 0);
  13233. }
  13234. else
  13235. {
  13236. tempIndex = gun_index;
  13237. }
  13238. for (int index = 0; index < CCS_QUANTITY; index++)
  13239. {
  13240. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13241. {
  13242. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13243. }
  13244. }// End of for CCS_QUANTITY
  13245. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13246. }
  13247. else if(gunType[gun_index] == 'G')
  13248. {
  13249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13250. {
  13251. tempIndex = ((gun_index==2) ? 1: 0);
  13252. }
  13253. else
  13254. {
  13255. tempIndex = gun_index;
  13256. }
  13257. for (int index = 0; index < GB_QUANTITY; index++)
  13258. {
  13259. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13260. {
  13261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13262. }
  13263. }// End of for GB_QUANTITY
  13264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13265. }
  13266. else
  13267. {
  13268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13269. {
  13270. tempIndex = 2;
  13271. }
  13272. else
  13273. {
  13274. tempIndex = gun_index;
  13275. }
  13276. for (int index = 0; index < AC_QUANTITY; index++)
  13277. {
  13278. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13279. {
  13280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13281. }
  13282. }// End of for AC_QUANTITY
  13283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13284. }
  13285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13287. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13288. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13289. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13290. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13291. //2.2 Energy.Active.Export.Interval
  13292. //idx_sample=2;
  13293. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13294. if(gunType[gun_index] == 'J')
  13295. {
  13296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13297. {
  13298. tempIndex = ((gun_index==2) ? 1: 0);
  13299. }
  13300. else
  13301. {
  13302. tempIndex = gun_index;
  13303. }
  13304. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13305. {
  13306. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13307. {
  13308. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13309. }
  13310. }// END OF CHAdeMO_QUANTITY
  13311. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13312. }
  13313. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13314. {
  13315. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13316. {
  13317. tempIndex = ((gun_index==2) ? 1: 0);
  13318. }
  13319. else
  13320. {
  13321. tempIndex = gun_index;
  13322. }
  13323. for (int index = 0; index < CCS_QUANTITY; index++)
  13324. {
  13325. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13326. {
  13327. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13328. }
  13329. }// END OF CCS_QUANTITY
  13330. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13331. }
  13332. else if(gunType[gun_index] == 'G')
  13333. {
  13334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13335. {
  13336. tempIndex = ((gun_index==2) ? 1: 0);
  13337. }
  13338. else
  13339. {
  13340. tempIndex = gun_index;
  13341. }
  13342. for (int index = 0; index < GB_QUANTITY; index++)
  13343. {
  13344. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13345. {
  13346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13347. }
  13348. }// END OF GB_QUANTITY
  13349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13350. }
  13351. else
  13352. {
  13353. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13354. {
  13355. tempIndex = 2;
  13356. }
  13357. else
  13358. {
  13359. tempIndex = gun_index;
  13360. }
  13361. for (int index = 0; index < AC_QUANTITY; index++)
  13362. {
  13363. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13364. {
  13365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13366. }
  13367. }// END OF AC_QUANTITY
  13368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13369. }
  13370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13372. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13373. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13374. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13376. //2.3 Power.Active.Export
  13377. //idx_sample=3;
  13378. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13379. if(gunType[gun_index] == 'J')
  13380. {
  13381. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13382. {
  13383. tempIndex = ((gun_index==2) ? 1: 0);
  13384. }
  13385. else
  13386. {
  13387. tempIndex = gun_index;
  13388. }
  13389. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13390. {
  13391. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13392. {
  13393. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13394. }
  13395. } // End for CHAdeMO_QUANTITY
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13397. }
  13398. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13399. {
  13400. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13401. {
  13402. tempIndex = ((gun_index==2) ? 1: 0);
  13403. }
  13404. else
  13405. {
  13406. tempIndex = gun_index;
  13407. }
  13408. for (int index = 0; index < CCS_QUANTITY; index++)
  13409. {
  13410. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13411. {
  13412. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13413. }
  13414. } // END for CCS_QUANTITY
  13415. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13416. }
  13417. else if(gunType[gun_index] == 'G')
  13418. {
  13419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13420. {
  13421. tempIndex = ((gun_index==2) ? 1: 0);
  13422. }
  13423. else
  13424. {
  13425. tempIndex = gun_index;
  13426. }
  13427. for (int index = 0; index < GB_QUANTITY; index++)
  13428. {
  13429. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13430. {
  13431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13432. }
  13433. }// END for GB_QUANTITY
  13434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13435. }
  13436. else
  13437. {
  13438. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13439. {
  13440. tempIndex = 2;
  13441. }
  13442. else
  13443. {
  13444. tempIndex = gun_index;
  13445. }
  13446. for (int index = 0; index < AC_QUANTITY; index++)
  13447. {
  13448. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13449. {
  13450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13451. }
  13452. } // END for AC_QUANTITY
  13453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13454. }
  13455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13457. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13458. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13459. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13460. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13461. //2.4 Voltage
  13462. //idx_sample=4;
  13463. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13464. if(gunType[gun_index] == 'J')
  13465. {
  13466. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13467. {
  13468. tempIndex = ((gun_index==2) ? 1: 0);
  13469. }
  13470. else
  13471. {
  13472. tempIndex = gun_index;
  13473. }
  13474. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13475. {
  13476. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13477. {
  13478. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13479. }
  13480. } // END OF FOR CHAdeMO_QUANTITY
  13481. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13482. }
  13483. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13484. {
  13485. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13486. {
  13487. tempIndex = ((gun_index==2) ? 1: 0);
  13488. }
  13489. else
  13490. {
  13491. tempIndex = gun_index;
  13492. }
  13493. for (int index = 0; index < CCS_QUANTITY; index++)
  13494. {
  13495. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13496. {
  13497. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13498. }
  13499. } // END OF FOR CCS_QUANTITY
  13500. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13501. }
  13502. else if(gunType[gun_index] == 'G')
  13503. {
  13504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13505. {
  13506. tempIndex = ((gun_index==2) ? 1: 0);
  13507. }
  13508. else
  13509. {
  13510. tempIndex = gun_index;
  13511. }
  13512. for (int index = 0; index < GB_QUANTITY; index++)
  13513. {
  13514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13517. }
  13518. } // END OF FOR GB_QUANTITY
  13519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13520. }
  13521. else
  13522. {
  13523. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13524. {
  13525. tempIndex = 2;
  13526. }
  13527. else
  13528. {
  13529. tempIndex = gun_index;
  13530. }
  13531. for (int index = 0; index < AC_QUANTITY; index++)
  13532. {
  13533. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13534. {
  13535. 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
  13536. }
  13537. } // END OF FOR AC_QUANTITY
  13538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13539. }
  13540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13542. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13543. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13545. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13546. //2.5 SoC
  13547. //idx_sample=5;
  13548. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13549. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13550. {
  13551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13552. {
  13553. tempIndex = ((gun_index==2) ? 1: 0);
  13554. }
  13555. else
  13556. {
  13557. tempIndex = gun_index;
  13558. }
  13559. if(gunType[gun_index] == 'J')
  13560. {
  13561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13562. {
  13563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13564. {
  13565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13566. }
  13567. }
  13568. }
  13569. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13570. {
  13571. for (int index = 0; index < CCS_QUANTITY; index++)
  13572. {
  13573. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13574. {
  13575. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13576. }
  13577. }
  13578. }
  13579. else if(gunType[gun_index] == 'G')
  13580. {
  13581. for (int index = 0; index < GB_QUANTITY; index++)
  13582. {
  13583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13584. {
  13585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13586. }
  13587. }
  13588. }
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13594. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13595. } // END FOR DC CASE
  13596. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13597. {
  13598. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13599. ,gun_index
  13600. ,MESSAGE_TYPE_CALL
  13601. ,guid
  13602. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13603. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13604. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13605. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13606. ,"PowerLoss"
  13607. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13608. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13609. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13610. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13611. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13612. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13613. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13614. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13615. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13616. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13617. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13618. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13619. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13620. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13621. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13622. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13623. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13624. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13625. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13626. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13627. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13628. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13629. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13630. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13631. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13632. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13633. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13634. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13635. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13636. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13637. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13638. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13639. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13640. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13641. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13642. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13643. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13644. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13645. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13646. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13647. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13648. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13649. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13650. );
  13651. }
  13652. else
  13653. {
  13654. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13655. ,gun_index
  13656. ,MESSAGE_TYPE_CALL
  13657. ,guid
  13658. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13659. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13660. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13661. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13662. ,"PowerLoss"
  13663. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13664. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13665. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13666. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13667. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13668. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13669. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13670. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13671. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13672. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13673. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13674. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13675. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13676. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13677. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13678. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13679. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13680. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13681. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13682. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13683. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13684. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13685. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13686. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13687. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13688. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13689. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13690. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13691. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13692. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13693. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13694. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13695. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13696. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13697. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13698. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13699. );
  13700. }
  13701. // Check File "TempStopTransaction" Exist
  13702. if((access("/Storage/OCPP/TempStopTransaction",F_OK))!=-1)
  13703. {
  13704. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13705. fclose(fopen("/Storage/OCPP/TempStopTransaction", "w"));
  13706. }
  13707. else
  13708. {
  13709. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13710. FILE *log = fopen("/Storage/OCPP/TempStopTransaction", "w+");
  13711. if(log == NULL)
  13712. {
  13713. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13714. return ;
  13715. }
  13716. else
  13717. {
  13718. fclose(log);
  13719. }
  13720. }
  13721. //Add TempStopTransaction | Update TempStopTransaction
  13722. // open file for writing
  13723. FILE *outfile;
  13724. outfile = fopen ("/Storage/OCPP/TempStopTransaction", "a");
  13725. //DEBUG_INFO("data = %s\n", queuedata);
  13726. fputs(queuedata, outfile);
  13727. fputs("\n", outfile);
  13728. fclose (outfile);
  13729. }
  13730. void checkTempStopTransaction(int gun_index)
  13731. {
  13732. FILE *fptr1;
  13733. char ch;
  13734. char str[1200]={0};
  13735. char guid[37]={0};
  13736. char tempdata[65]={0};
  13737. char connectorStr[2]={0};
  13738. fptr1 = fopen("/Storage/OCPP/TempStopTransaction", "r");
  13739. //TempStopTransaction格式: 槍號,StopTransaction封包
  13740. if (!fptr1)
  13741. {
  13742. //printf(" File not found or unable to open the input file!!\n");
  13743. return ;
  13744. }
  13745. ch=fgetc(fptr1);
  13746. //printf(" Now the content of the file %s is : \n",fname);
  13747. rewind(fptr1);
  13748. if(ch!=EOF)
  13749. {
  13750. // copy all contents to the temporary file except the specific line
  13751. while (fgets(str, 1200, fptr1) != NULL)
  13752. {
  13753. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13754. if(str[0]=='\0')
  13755. {
  13756. break;
  13757. }
  13758. //TempStopTransaction格式: 槍號,StopTransaction封包
  13759. strncpy(connectorStr, str, 1);
  13760. if(atoi(connectorStr) != gun_index)
  13761. {
  13762. DEBUG_INFO("atoi(connectorStr)=%d\n",atoi(connectorStr));
  13763. return ;
  13764. }
  13765. //random_uuid(guid);
  13766. strncpy(guid, str+4, 36); //copy guid
  13767. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13768. if(hashmap_operation(0, guid, tempdata) == 1)
  13769. {
  13770. DEBUG_INFO("StopTransaction mapitem pass\n");
  13771. }
  13772. queue_operation(4, guid, str+2 );//addq(guid, queuedata); ---> remove temporally
  13773. memset(str,0,sizeof str);
  13774. }
  13775. }
  13776. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13777. fclose(fptr1);
  13778. remove("/Storage/OCPP/TempStopTransaction"); // remove the original file
  13779. }
  13780. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13781. {
  13782. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13783. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13784. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13785. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13786. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13787. }
  13788. int GetWebSocketPingInterval(void)
  13789. {
  13790. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13791. }
  13792. int GetServerSign(void)
  13793. {
  13794. return server_sign;
  13795. }
  13796. void SetServerSign(int value)
  13797. {
  13798. server_sign = value;
  13799. }
  13800. int GetBootNotificationInterval(void)
  13801. {
  13802. return BootNotificationInterval;
  13803. }
  13804. int GetInternetConn(void)
  13805. {
  13806. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  13807. }
  13808. void InitialSystemValue(void)
  13809. {
  13810. int connectorIndex = 0;
  13811. //int valueASCII = 0;
  13812. server_cycle_Status = 120;
  13813. gunTotalNumber=0;
  13814. SystemInitial = 0;
  13815. localversion=0;
  13816. BootNotificationInterval = 0;
  13817. authorizeRetryTimes = 0;
  13818. GunStatusInterval = 10;
  13819. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  13820. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  13821. //Hear Beat
  13822. HeartBeatWithNOResponse = 0;
  13823. HeartBeatCountPerHour = 0;
  13824. HeartBeatWaitTime = 10;
  13825. FirstHeartBeat = 0;
  13826. FirmwareStatusNotificationStatus = 3; // Idle
  13827. DiagnosticsStatusNotificationStatus = 0; // Idle
  13828. memset(CurrentChargingProfileScheduleStr, 0, sizeof(CurrentChargingProfileScheduleStr));
  13829. memset(statusModeChage, 0, sizeof(statusModeChage));
  13830. memset(ChademoPreviousSystemStatus, 0, sizeof(ChademoPreviousSystemStatus));
  13831. memset(CcsPreviousSystemStatus, 0, sizeof(CcsPreviousSystemStatus));
  13832. memset(GbPreviousSystemStatus, 0, sizeof(GbPreviousSystemStatus));
  13833. memset(AcPreviousSystemStatus, 0, sizeof(AcPreviousSystemStatus));
  13834. memset(ChademoPreviousConnectorPlugIn, 0, sizeof(ChademoPreviousConnectorPlugIn));
  13835. memset(CcsPreviousConnectorPlugIn, 0, sizeof(CcsPreviousConnectorPlugIn));
  13836. memset(GbPreviousConnectorPlugIn, 0, sizeof(GbPreviousConnectorPlugIn));
  13837. memset(AcPreviousConnectorPlugIn, 0, sizeof(AcPreviousConnectorPlugIn));
  13838. memset(gunType, 0, sizeof(gunType));
  13839. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13840. {
  13841. //check connector / socket type (index: 8, 9, 10)
  13842. for(int index=7; index <10 ; index++)
  13843. {
  13844. if(index != 8)
  13845. {
  13846. // DC Connector
  13847. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  13848. {
  13849. SystemInitial = SystemInitial + 1;
  13850. gunTotalNumber = gunTotalNumber + 1;
  13851. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13852. connectorIndex = connectorIndex + 1;
  13853. }
  13854. }
  13855. else
  13856. {
  13857. // AC Connector
  13858. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13859. {
  13860. SystemInitial = SystemInitial + 1;
  13861. gunTotalNumber = gunTotalNumber + 1;
  13862. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13863. connectorIndex = connectorIndex + 1;
  13864. }
  13865. }
  13866. }
  13867. //DEBUG_INFO("DC ...\n");
  13868. }
  13869. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  13870. {
  13871. //check connector / socket type (index: 8, 9, 10)
  13872. for(int index=7; index <10 ; index++)
  13873. {
  13874. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  13875. {
  13876. SystemInitial = SystemInitial + 1;
  13877. gunTotalNumber = gunTotalNumber + 1;
  13878. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  13879. connectorIndex = connectorIndex + 1;
  13880. DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  13881. }
  13882. }
  13883. DEBUG_INFO("gunTotalNumber: %d\n", gunTotalNumber);
  13884. DEBUG_INFO("connectorIndex: %d\n", connectorIndex);
  13885. DEBUG_INFO("SystemInitial: %d\n", SystemInitial);
  13886. //DEBUG_INFO("AC ...\n");
  13887. }
  13888. //Status && ConnectorPlugIn Setting
  13889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13890. {
  13891. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  13892. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  13893. }
  13894. for (int index = 0; index < CCS_QUANTITY; index++)
  13895. {
  13896. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  13897. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  13898. }
  13899. for (int index = 0; index < GB_QUANTITY; index++)
  13900. {
  13901. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  13902. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  13903. }
  13904. for (int index = 0; index < AC_QUANTITY; index++)
  13905. {
  13906. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  13907. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  13908. }
  13909. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  13910. {
  13911. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  13912. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  13913. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  13914. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  13915. }
  13916. // Charger PRE_SYS_MODE
  13917. memset(PRE_SYS_MODE, 0, sizeof(PRE_SYS_MODE));
  13918. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  13919. clientTime.Heartbeat=time((time_t*)NULL);
  13920. sleep(1);
  13921. }
  13922. void LWS_Send(char * str)
  13923. {
  13924. //=====================================================
  13925. // Check InternetConn 0: disconnected, 1: connected
  13926. //====================================================
  13927. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  13928. {
  13929. DEBUG_INFO("\n offline now !!!\n");
  13930. return;
  13931. }
  13932. pthread_mutex_lock(&lock);
  13933. memset(SendBuffer, 0, SendBufLen);
  13934. sprintf((char *)SendBuffer, "%s", str);
  13935. pthread_mutex_unlock(&lock);
  13936. lws_callback_on_writable(wsi_client);
  13937. lws_service(context, 100);//timeout_ms
  13938. }