MessageHandler.c 709 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  73. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  74. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  75. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  76. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  77. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  78. static int TransactionMessageAttemptsValue = 0;
  79. static int TransactionMessageRetryIntervalValue = 0;
  80. static int TempMeterValueInterval = 0;
  81. static struct OCPPAuthLocalElemet
  82. {
  83. int listVersionInt;
  84. char idTagstr[20];
  85. char parentIdTag[20];
  86. char expiryDate[30];
  87. char idTagstatus[16];
  88. }idTagQuery;
  89. //=============================================
  90. // OCPP HeartBeat Response Not Receive Counts
  91. //============================================
  92. static int HeartBeatWithNOResponse = 0;
  93. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  94. extern struct Charger_Info Charger;
  95. extern sqlite3 *db;
  96. int TransactionMessageAttemptsGet(void);
  97. int TransactionMessageRetryIntervalGet(void);
  98. int GetOcppConnStatus(void);
  99. void SetOcppConnStatus(uint8_t status);
  100. int setKeyValue(char *key, char *value);
  101. void OCPP_get_TableAuthlocalAllData(void);
  102. void processUnkownKey(void);
  103. struct StructOCPPMeterValue
  104. {
  105. unsigned char TimeStamp[28];
  106. struct StructSampledValue SampledValue[10];
  107. };
  108. struct ClientTime
  109. {
  110. unsigned int Heartbeat;
  111. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  112. unsigned int StartTransaction;
  113. unsigned int StopTransaction;
  114. unsigned int MeterValues[CONNECTOR_QUANTITY];
  115. }clientTime;
  116. typedef union
  117. {
  118. //Operations Initiated by Central System
  119. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  120. struct
  121. {
  122. //CsMsgValue[0]
  123. unsigned char StatusNotificationReq:1; //bit 0,
  124. unsigned char StatusNotificationConf:1; //bit 1,
  125. unsigned char TriggerMeterValue:1; //bit 2,
  126. unsigned char :5; //bit 5~7
  127. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  128. }CpinitiateMsg;
  129. CpinitiateMsg cpinitateMsg;
  130. //GetConfiguration Array
  131. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  132. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  133. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  134. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  135. #if 0
  136. static char *ChargePointErrorCodeStr[] = {
  137. MACROSTR(ConnectorLockFailure),
  138. MACROSTR(EVCommunicationError),
  139. MACROSTR(GroundFailure),
  140. MACROSTR(HighTemperature),
  141. MACROSTR(InternalError),
  142. MACROSTR(LocalListConflict),
  143. MACROSTR(NoError),
  144. MACROSTR(OtherError),
  145. MACROSTR(OverCurrentFailure),
  146. MACROSTR(OverVoltage),
  147. MACROSTR(PowerMeterFailure),
  148. MACROSTR(PowerSwitchFailure),
  149. MACROSTR(ReaderFailure),
  150. MACROSTR(ResetFailure),
  151. MACROSTR(UnderVoltage),
  152. MACROSTR(WeakSignal)
  153. };
  154. #endif
  155. static char * ChargePointStatusStr[] = {
  156. MACROSTR(Available),
  157. MACROSTR(Preparing),
  158. MACROSTR(Charging),
  159. MACROSTR(SuspendedEVSE),
  160. MACROSTR(SuspendedEV),
  161. MACROSTR(Finishing),
  162. MACROSTR(Reserved),
  163. MACROSTR(Unavailable),
  164. MACROSTR(Faulted)
  165. };
  166. static char *RegistrationStatusStr[] = {
  167. MACROSTR(Accepted),
  168. MACROSTR(Pending),
  169. MACROSTR(Rejected)
  170. };
  171. static char *AvailabilityTypeStr[] = {
  172. MACROSTR(Inoperative),
  173. MACROSTR(Operative)
  174. };
  175. static char *AvailabilityStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected),
  178. MACROSTR(Scheduled)
  179. };
  180. static char *ConfigurationStatusStr[] = {
  181. MACROSTR(Accepted),
  182. MACROSTR(Rejected),
  183. MACROSTR(RebootRequired),
  184. MACROSTR(NotSupported)
  185. };
  186. static char *ClearCacheStatusStr[] = {
  187. MACROSTR(Accepted),
  188. MACROSTR(Rejected)
  189. };
  190. static char *ChargingProfilePurposeTypeStr[] = {
  191. MACROSTR(ChargePointMaxProfile),
  192. MACROSTR(TxDefaultProfile),
  193. MACROSTR(TxProfile)
  194. };
  195. static char *ChargingProfileStatusStr[] = {
  196. MACROSTR(Accepted),
  197. MACROSTR(Rejected),
  198. MACROSTR(NotSupported)
  199. };
  200. static char *ClearChargingProfileStatusStr[] = {
  201. MACROSTR(Accepted),
  202. MACROSTR(Unknown)
  203. };
  204. static char *GetCompositeScheduleStatusStr[] = {
  205. MACROSTR(Accepted),
  206. MACROSTR(Rejected)
  207. };
  208. static char *UpdateTypeStr[] = {
  209. MACROSTR(Differential),
  210. MACROSTR(Full)
  211. };
  212. static char *UpdateStatusStr[] = {
  213. MACROSTR(Accepted),
  214. MACROSTR(Failed),
  215. MACROSTR(NotSupported),
  216. MACROSTR(VersionMismatch)
  217. };
  218. static char *RemoteStartStopStatusStr[] = {
  219. MACROSTR(Accepted),
  220. MACROSTR(Rejected)
  221. };
  222. static char *ReservationStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Faulted),
  225. MACROSTR(Occupied),
  226. MACROSTR(Rejected),
  227. MACROSTR(Unavailable)
  228. };
  229. static char *ResetTypeStr[] = {
  230. MACROSTR(Hard),
  231. MACROSTR(Soft)
  232. };
  233. static char *ResetStatusStr[] = {
  234. MACROSTR(Accepted),
  235. MACROSTR(Rejected)
  236. };
  237. static char * DiagnosticsStatusStr[] = {
  238. MACROSTR(Idle),
  239. MACROSTR(Uploaded),
  240. MACROSTR(UploadFailed),
  241. MACROSTR(Uploading)
  242. };
  243. static char * FirmwareStatusStr[] = {
  244. MACROSTR(Downloaded),
  245. MACROSTR(DownloadFailed),
  246. MACROSTR(Downloading),
  247. MACROSTR(Idle),
  248. MACROSTR(InstallationFailed),
  249. MACROSTR(Installing),
  250. MACROSTR(Installed)
  251. };
  252. static char * MessageTriggerStr[] = {
  253. MACROSTR(BootNotification),
  254. MACROSTR(DiagnosticsStatusNotification),
  255. MACROSTR(FirmwareStatusNotification),
  256. MACROSTR(Heartbeat),
  257. MACROSTR(MeterValues),
  258. MACROSTR(StatusNotification)
  259. };
  260. static char * TriggerMessageStatusStr[] = {
  261. MACROSTR(Accepted),
  262. MACROSTR(Rejected),
  263. MACROSTR(NotImplemented)
  264. };
  265. static char * UnlockStatusStr[] = {
  266. MACROSTR(Unlocked),
  267. MACROSTR(UnlockFailed),
  268. MACROSTR(NotSupported)
  269. };
  270. #if 0
  271. static char * StopTransactionReasonStr[] = {
  272. MACROSTR(EmergencyStop),
  273. MACROSTR(EVDisconnected),
  274. MACROSTR(HardReset),
  275. MACROSTR(Local),
  276. MACROSTR(Other),
  277. MACROSTR(PowerLoss),
  278. MACROSTR(Reboot),
  279. MACROSTR(Remote),
  280. MACROSTR(SoftReset),
  281. MACROSTR(UnlockCommand),
  282. MACROSTR(DeAuthorized)
  283. };
  284. #endif
  285. static char * CancelReservationStatusStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(Rejected)
  288. };
  289. static char * ReadingContextStr[] = {
  290. MACROSTR(Interruption.Begin),
  291. MACROSTR(Interruption.End),
  292. MACROSTR(Other),
  293. MACROSTR(Sample.Clock),
  294. MACROSTR(Sample.Periodic),
  295. MACROSTR(Transaction.Begin),
  296. MACROSTR(Transaction.End),
  297. MACROSTR(Trigger)
  298. };
  299. static char * ValueFormatStr[] = {
  300. MACROSTR(Raw),
  301. MACROSTR(SignedData)
  302. };
  303. static char * MeasurandStr[] = {
  304. MACROSTR(Current.Export),
  305. MACROSTR(Current.Import),
  306. MACROSTR(Current.Offered),
  307. MACROSTR(Energy.Active.Export.Register),
  308. MACROSTR(Energy.Active.Import.Register),
  309. MACROSTR(Energy.Reactive.Export.Register),
  310. MACROSTR(Energy.Reactive.Import.Register),
  311. MACROSTR(Energy.Active.Export.Interval),
  312. MACROSTR(Energy.Active.Import.Interval),
  313. MACROSTR(Energy.Reactive.Export.Interval),
  314. MACROSTR(Energy.Reactive.Import.Interval),
  315. MACROSTR(Frequency),
  316. MACROSTR(Power.Active.Export),
  317. MACROSTR(Power.Active.Import),
  318. MACROSTR(Power.Factor),
  319. MACROSTR(Power.Offered),
  320. MACROSTR(Power.Reactive.ExportMACROSTR),
  321. MACROSTR(Power.Reactive.Import),
  322. MACROSTR(RPM),
  323. MACROSTR(SoC),
  324. MACROSTR(Temperature),
  325. MACROSTR(Voltage)
  326. };
  327. static char * LocationStr[] = {
  328. MACROSTR(Body),
  329. MACROSTR(Cable),
  330. MACROSTR(EV),
  331. MACROSTR(Inlet),
  332. MACROSTR(Outlet)
  333. };
  334. static char * PhaseStr[] = {
  335. MACROSTR(L1),
  336. MACROSTR(L2),
  337. MACROSTR(L3),
  338. MACROSTR(N),
  339. MACROSTR(L1-N),
  340. MACROSTR(L2-N),
  341. MACROSTR(L3-N),
  342. MACROSTR(L1-L2),
  343. MACROSTR(L2-L3),
  344. MACROSTR(L3-L1)
  345. };
  346. static char * UnitOfMeasureStr[] = {
  347. MACROSTR(Wh),
  348. MACROSTR(kWh),
  349. MACROSTR(varh),
  350. MACROSTR(kvarh),
  351. MACROSTR(W),
  352. MACROSTR(kW),
  353. MACROSTR(VA),
  354. MACROSTR(kVA),
  355. MACROSTR(var),
  356. MACROSTR(kvar),
  357. MACROSTR(A),
  358. MACROSTR(V),
  359. MACROSTR(Celsius),
  360. MACROSTR(Fahrenheit),
  361. MACROSTR(K),
  362. MACROSTR(Percent)
  363. };
  364. //==========================================
  365. // Check time passed since today
  366. //==========================================
  367. long long DiffTimebWithNow(struct timeb ST)
  368. {
  369. //return milli-second
  370. struct timeb ET;
  371. long long StartTime,StopTime;
  372. ftime(&ET);
  373. StartTime=(long long)ST.time;
  374. StopTime=(long long)ET.time;
  375. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  376. }
  377. int getTimePassSinceToday()
  378. {
  379. int result = -1;
  380. time_t t;
  381. struct tm *tmStartToday;
  382. struct timeb tbStartToday;
  383. t=time(NULL);
  384. tmStartToday=localtime(&t);
  385. tmStartToday->tm_hour = 0;
  386. tmStartToday->tm_min = 0;
  387. tmStartToday->tm_sec = 0;
  388. tbStartToday.time = mktime(tmStartToday);
  389. tbStartToday.millitm = 0;
  390. result = DiffTimebWithNow(tbStartToday)/1000;
  391. return result;
  392. }
  393. //==========================================
  394. // GetCompositeSchedule logic related function
  395. //==========================================
  396. int DiffTimebSec(struct timeb ST, struct timeb ET)
  397. {
  398. //return milli-second
  399. unsigned int StartTime,StopTime;
  400. StartTime=(unsigned int)ST.time;
  401. StopTime=(unsigned int)ET.time;
  402. return (StopTime-StartTime);
  403. }
  404. int DiffTimebWithNowSec(struct timeb ST)
  405. {
  406. //return milli-second
  407. struct timeb ET;
  408. unsigned int StartTime,StopTime;
  409. ftime(&ET);
  410. StartTime=(unsigned int)ST.time;
  411. StopTime=(unsigned int)ET.time;
  412. return (StopTime-StartTime);
  413. }
  414. int getStartStop(uint8_t *start, uint8_t *stop)
  415. {
  416. int result = -1;
  417. struct tm tmStart;
  418. struct timeb tbStart;
  419. struct tm tmStop;
  420. struct timeb tbStop;
  421. 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) &&
  422. (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))
  423. {
  424. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  425. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  426. tmStart.tm_year -= 1900;
  427. tmStart.tm_mon -= 1;
  428. tbStart.time = mktime(&tmStart);
  429. tbStart.millitm = 0;
  430. tmStop.tm_year -= 1900;
  431. tmStop.tm_mon -= 1;
  432. tbStop.time = mktime(&tmStop);
  433. tbStop.millitm = 0;
  434. result = DiffTimebSec(tbStart, tbStop);
  435. //DEBUG_INFO("getStartStop(): %d\n", result);
  436. }
  437. else
  438. {
  439. DEBUG_WARN("Start or stop date parsing error.\r\n");
  440. }
  441. return result;
  442. }
  443. int isOvertNow(uint8_t *start)
  444. {
  445. int result = YES;
  446. struct tm tmStart;
  447. struct timeb tbStart;
  448. 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))
  449. {
  450. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  451. tmStart.tm_year -= 1900;
  452. tmStart.tm_mon -= 1;
  453. tbStart.time = mktime(&tmStart);
  454. tbStart.millitm = 0;
  455. if(DiffTimebWithNowSec(tbStart) <= 0)
  456. result = NO;
  457. }
  458. else
  459. {
  460. DEBUG_WARN("Start date parsing error.\r\n");
  461. }
  462. return result;
  463. }
  464. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  465. {
  466. int result = -1;
  467. struct tm tmStart;
  468. struct timeb tbStart;
  469. struct tm tmStop;
  470. struct timeb tbStop;
  471. 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) &&
  472. (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))
  473. {
  474. tmStart.tm_year -= 1900;
  475. tmStart.tm_mon -= 1;
  476. tbStart.time = mktime(&tmStart);
  477. tbStart.millitm = 0;
  478. tmStop.tm_year -= 1900;
  479. tmStop.tm_mon -= 1;
  480. tbStop.time = mktime(&tmStop);
  481. tbStop.millitm = 0;
  482. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  483. }
  484. return result;
  485. }
  486. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  487. {
  488. FILE *fp;
  489. char profileFileName[128];
  490. char *line = NULL;
  491. size_t len = 0;
  492. time_t CurrentTime;
  493. struct tm *tmComposite;
  494. struct StructChargingProfile maxProfile;
  495. struct StructChargingProfile defaultTxProfile;
  496. struct StructChargingProfile txProfile;
  497. struct StructChargingSchedulePeriod tmpPeriod;
  498. uint8_t limitMax=0;
  499. uint8_t limitDef=0;
  500. uint8_t limitTx=0;
  501. int compositePeriodIdx = 0;
  502. CurrentTime = time(NULL);
  503. tmComposite=localtime(&CurrentTime);
  504. 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);
  505. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  506. compositeProfile->ChargingSchedule.Duration = durationReq;
  507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  508. {
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  510. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  511. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  512. }
  513. compositeProfile->ChargingProfileId = 0;
  514. compositeProfile->StackLevel = 99 ;
  515. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  516. maxProfile.ChargingProfileId = -1;
  517. defaultTxProfile.ChargingProfileId = -1;
  518. txProfile.ChargingProfileId = -1;
  519. maxProfile.ChargingSchedule.Duration = -1;
  520. defaultTxProfile.ChargingSchedule.Duration = -1;
  521. txProfile.ChargingSchedule.Duration = -1;
  522. system("yes|rm /tmp/*.json");
  523. system("cp /Storage/OCPP/*.json /tmp");
  524. /*
  525. * Search valid charging profile
  526. */
  527. //DEBUG_INFO("====================================\n");
  528. // Search tx profile
  529. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  530. if((access(profileFileName, F_OK))!=-1)
  531. {
  532. fp = fopen(profileFileName, "r");
  533. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  534. {
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  536. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  537. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  538. }
  539. txProfile.ChargingProfileId = -1;
  540. txProfile.StackLevel = -1;
  541. while(getline(&line, &len, fp) != -1)
  542. {
  543. json_object *obj = NULL;
  544. obj = json_tokener_parse(line);
  545. if(is_error(obj))
  546. {
  547. DEBUG_ERROR("Parse txProfile from file error.\n");
  548. }
  549. else
  550. {
  551. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  552. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  553. )
  554. {
  555. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  556. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  557. )
  558. {
  559. struct tm tmFrom, tmTo;
  560. struct timeb tbFrom, tbTo;
  561. 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) &&
  562. (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))
  563. {
  564. tmFrom.tm_year -= 1900;
  565. tmFrom.tm_mon -= 1;
  566. tbFrom.time = mktime(&tmFrom);
  567. tmTo.tm_year -= 1900;
  568. tmTo.tm_mon -= 1;
  569. tbTo.time = mktime(&tmTo);
  570. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  571. {
  572. if(txProfile.ChargingProfileId == -1)
  573. DEBUG_INFO("TxProfile found.\n");
  574. else
  575. DEBUG_INFO("TxProfile updated.\n");
  576. // Required item
  577. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  578. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  579. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  580. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  581. 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++)
  582. {
  583. 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"));
  584. 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")));
  585. 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?
  586. 3:
  587. 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")));
  588. }
  589. // Optional item
  590. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  591. {
  592. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  593. }
  594. else
  595. {
  596. sprintf((char*)txProfile.ValidFrom, " ");
  597. }
  598. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  599. {
  600. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  601. }
  602. else
  603. {
  604. sprintf((char*)txProfile.ValidTo, " ");
  605. }
  606. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  607. {
  608. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  609. }
  610. else
  611. {
  612. sprintf((char*)txProfile.RecurrencyKind, " ");
  613. }
  614. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  615. {
  616. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  617. }
  618. else
  619. {
  620. txProfile.TransactionId = -1;
  621. }
  622. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  623. {
  624. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  625. }
  626. else
  627. {
  628. txProfile.ChargingSchedule.Duration = 86400;
  629. }
  630. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  631. {
  632. 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")));
  633. }
  634. else
  635. {
  636. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  637. }
  638. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  639. {
  640. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  641. }
  642. else
  643. {
  644. txProfile.ChargingSchedule.MinChargingRate = -1;
  645. }
  646. }
  647. }
  648. }
  649. else
  650. {
  651. if(txProfile.ChargingProfileId == -1)
  652. DEBUG_INFO("TxProfile found.\n");
  653. else
  654. DEBUG_INFO("TxProfile updated.\n");
  655. // Required item
  656. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  657. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  658. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  659. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  660. 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++)
  661. {
  662. 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"));
  663. 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")));
  664. 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?
  665. 3:
  666. 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")));
  667. }
  668. // Optional item
  669. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  670. {
  671. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  672. }
  673. else
  674. {
  675. sprintf((char*)txProfile.ValidFrom, " ");
  676. }
  677. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  678. {
  679. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  680. }
  681. else
  682. {
  683. sprintf((char*)txProfile.ValidTo, " ");
  684. }
  685. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  686. {
  687. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  688. }
  689. else
  690. {
  691. sprintf((char*)txProfile.RecurrencyKind, " ");
  692. }
  693. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  694. {
  695. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  696. }
  697. else
  698. {
  699. txProfile.TransactionId = -1;
  700. }
  701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  702. {
  703. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  704. }
  705. else
  706. {
  707. txProfile.ChargingSchedule.Duration = 86400;
  708. }
  709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  710. {
  711. 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")));
  712. }
  713. else
  714. {
  715. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  716. }
  717. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  718. {
  719. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  720. }
  721. else
  722. {
  723. txProfile.ChargingSchedule.MinChargingRate = -1;
  724. }
  725. }
  726. }
  727. }
  728. json_object_put(obj);
  729. }
  730. fclose(fp);
  731. /*
  732. if(txProfile.ChargingProfileId != -1)
  733. {
  734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  741. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  746. {
  747. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  748. {
  749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  752. }
  753. }
  754. }
  755. else
  756. DEBUG_INFO("TxProfile not found.\n");*/
  757. }
  758. // Search default tx profile
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  760. if((access(profileFileName, F_OK))==-1)
  761. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  762. if((access(profileFileName, F_OK))!=-1)
  763. {
  764. fp = fopen(profileFileName, "r");
  765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  766. {
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  768. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  769. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  770. }
  771. defaultTxProfile.ChargingProfileId = -1;
  772. defaultTxProfile.StackLevel = -1;
  773. while(getline(&line, &len, fp) != -1)
  774. {
  775. json_object *obj = NULL;
  776. obj = json_tokener_parse(line);
  777. if(is_error(obj))
  778. {
  779. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  780. }
  781. else
  782. {
  783. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  784. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  785. )
  786. {
  787. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  788. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  789. )
  790. {
  791. struct tm tmFrom, tmTo;
  792. struct timeb tbFrom, tbTo;
  793. 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) &&
  794. (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))
  795. {
  796. tmFrom.tm_year -= 1900;
  797. tmFrom.tm_mon -= 1;
  798. tbFrom.time = mktime(&tmFrom);
  799. tmTo.tm_year -= 1900;
  800. tmTo.tm_mon -= 1;
  801. tbTo.time = mktime(&tmTo);
  802. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  803. {
  804. if(defaultTxProfile.ChargingProfileId == -1)
  805. DEBUG_INFO("TxDefaultProfile found.\n");
  806. else
  807. DEBUG_INFO("TxDefaultProfile updated.\n");
  808. // Required item
  809. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  810. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  811. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  812. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  813. 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++)
  814. {
  815. 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"));
  816. 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")));
  817. 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?
  818. 3:
  819. 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")));
  820. }
  821. // Optional item
  822. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  823. {
  824. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  825. }
  826. else
  827. {
  828. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  829. }
  830. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  831. {
  832. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  833. }
  834. else
  835. {
  836. sprintf((char*)defaultTxProfile.ValidTo, " ");
  837. }
  838. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  839. {
  840. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  841. }
  842. else
  843. {
  844. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  845. }
  846. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  847. {
  848. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  849. }
  850. else
  851. {
  852. defaultTxProfile.TransactionId = -1;
  853. }
  854. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  855. {
  856. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  857. }
  858. else
  859. {
  860. defaultTxProfile.ChargingSchedule.Duration = 86400;
  861. }
  862. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  863. {
  864. 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")));
  865. }
  866. else
  867. {
  868. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  869. }
  870. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  871. {
  872. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  873. }
  874. else
  875. {
  876. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  877. }
  878. }
  879. }
  880. }
  881. else
  882. {
  883. if(defaultTxProfile.ChargingProfileId == -1)
  884. DEBUG_INFO("TxDefaultProfile found.\n");
  885. else
  886. DEBUG_INFO("TxDefaultProfile updated.\n");
  887. // Required item
  888. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  889. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  890. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  891. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  892. 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++)
  893. {
  894. 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"));
  895. 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")));
  896. 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?
  897. 3:
  898. 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")));
  899. }
  900. // Optional item
  901. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  902. {
  903. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  904. }
  905. else
  906. {
  907. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  908. }
  909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  910. {
  911. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  912. }
  913. else
  914. {
  915. sprintf((char*)defaultTxProfile.ValidTo, " ");
  916. }
  917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  918. {
  919. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  920. }
  921. else
  922. {
  923. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  924. }
  925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  926. {
  927. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  928. }
  929. else
  930. {
  931. defaultTxProfile.TransactionId = -1;
  932. }
  933. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  934. {
  935. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  936. }
  937. else
  938. {
  939. defaultTxProfile.ChargingSchedule.Duration = 86400;
  940. }
  941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  942. {
  943. 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")));
  944. }
  945. else
  946. {
  947. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  948. }
  949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  950. {
  951. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  952. }
  953. else
  954. {
  955. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  956. }
  957. }
  958. }
  959. }
  960. json_object_put(obj);
  961. }
  962. fclose(fp);
  963. /*
  964. if(defaultTxProfile.ChargingProfileId != -1)
  965. {
  966. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  967. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  968. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  969. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  970. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  971. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  972. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  973. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  974. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  975. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  976. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  977. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  978. {
  979. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  980. {
  981. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  982. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  983. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  984. }
  985. }
  986. }
  987. else
  988. DEBUG_INFO("TxDefaultProfile not found.\n");
  989. DEBUG_INFO("------------------------------------\n");*/
  990. }
  991. // Search max profile
  992. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  993. if((access(profileFileName, F_OK))!=-1)
  994. {
  995. fp = fopen(profileFileName, "r");
  996. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  997. {
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  999. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  1000. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  1001. }
  1002. maxProfile.ChargingProfileId = -1;
  1003. maxProfile.StackLevel = -1;
  1004. while(getline(&line, &len, fp) != -1)
  1005. {
  1006. json_object *obj = NULL;
  1007. obj = json_tokener_parse(line);
  1008. if(is_error(obj))
  1009. {
  1010. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1011. }
  1012. else
  1013. {
  1014. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1015. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1016. )
  1017. {
  1018. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1019. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1020. )
  1021. {
  1022. struct tm tmFrom, tmTo;
  1023. struct timeb tbFrom, tbTo;
  1024. 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) &&
  1025. (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))
  1026. {
  1027. tmFrom.tm_year -= 1900;
  1028. tmFrom.tm_mon -= 1;
  1029. tbFrom.time = mktime(&tmFrom);
  1030. tmTo.tm_year -= 1900;
  1031. tmTo.tm_mon -= 1;
  1032. tbTo.time = mktime(&tmTo);
  1033. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1034. {
  1035. if(maxProfile.ChargingProfileId == -1)
  1036. DEBUG_INFO("MaxProfile found.\n");
  1037. else
  1038. DEBUG_INFO("MaxProfile updated.\n");
  1039. // Required item
  1040. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1041. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1042. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1043. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1044. 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++)
  1045. {
  1046. 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"));
  1047. 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")));
  1048. 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?
  1049. 3:
  1050. 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")));
  1051. }
  1052. // Optional item
  1053. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1054. {
  1055. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1056. }
  1057. else
  1058. {
  1059. sprintf((char*)maxProfile.ValidFrom, " ");
  1060. }
  1061. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1062. {
  1063. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1064. }
  1065. else
  1066. {
  1067. sprintf((char*)maxProfile.ValidTo, " ");
  1068. }
  1069. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1070. {
  1071. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1072. }
  1073. else
  1074. {
  1075. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1076. }
  1077. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1078. {
  1079. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1080. }
  1081. else
  1082. {
  1083. maxProfile.TransactionId = -1;
  1084. }
  1085. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1086. {
  1087. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1088. }
  1089. else
  1090. {
  1091. maxProfile.ChargingSchedule.Duration = 86400;
  1092. }
  1093. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1094. {
  1095. 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")));
  1096. }
  1097. else
  1098. {
  1099. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1100. }
  1101. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1102. {
  1103. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1104. }
  1105. else
  1106. {
  1107. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. if(maxProfile.ChargingProfileId == -1)
  1115. DEBUG_INFO("MaxProfile found.\n");
  1116. else
  1117. DEBUG_INFO("MaxProfile updated.\n");
  1118. // Required item
  1119. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1120. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1121. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1122. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1123. 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++)
  1124. {
  1125. 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"));
  1126. 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")));
  1127. 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?
  1128. 3:
  1129. 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")));
  1130. }
  1131. // Optional item
  1132. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1133. {
  1134. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1135. }
  1136. else
  1137. {
  1138. sprintf((char*)maxProfile.ValidFrom, " ");
  1139. }
  1140. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1141. {
  1142. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1143. }
  1144. else
  1145. {
  1146. sprintf((char*)maxProfile.ValidTo, " ");
  1147. }
  1148. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1149. {
  1150. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1151. }
  1152. else
  1153. {
  1154. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1155. }
  1156. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1157. {
  1158. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1159. }
  1160. else
  1161. {
  1162. maxProfile.TransactionId = -1;
  1163. }
  1164. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1165. {
  1166. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1167. }
  1168. else
  1169. {
  1170. maxProfile.ChargingSchedule.Duration = 86400;
  1171. }
  1172. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1173. {
  1174. 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")));
  1175. }
  1176. else
  1177. {
  1178. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1179. }
  1180. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1181. {
  1182. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1183. }
  1184. else
  1185. {
  1186. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. json_object_put(obj);
  1192. }
  1193. fclose(fp);
  1194. /*
  1195. if(maxProfile.ChargingProfileId !=-1)
  1196. {
  1197. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1198. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1199. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1200. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1201. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1202. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1203. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1204. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1205. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1206. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1207. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1208. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1209. {
  1210. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1211. {
  1212. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1213. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1214. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1215. }
  1216. }
  1217. }
  1218. else
  1219. DEBUG_INFO("MaxProfile not found.\n");
  1220. DEBUG_INFO("------------------------------------\n");*/
  1221. }
  1222. /*
  1223. * Align found profile start schedule & periods
  1224. */
  1225. //DEBUG_INFO("====================================\n");
  1226. /*
  1227. // For local test usage, force modify found profile start schedule info
  1228. 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);
  1229. 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);
  1230. 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);
  1231. */
  1232. if(txProfile.ChargingProfileId != -1)
  1233. {
  1234. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1235. {
  1236. if(txProfile.ChargingSchedule.Duration != -1)
  1237. {
  1238. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1239. 0:
  1240. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1241. }
  1242. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1243. {
  1244. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1245. {
  1246. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1247. 0:
  1248. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1249. if(idxPeriod > 0)
  1250. {
  1251. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1252. {
  1253. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1260. {
  1261. if(txProfile.ChargingSchedule.Duration != -1)
  1262. {
  1263. 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?
  1264. 0:
  1265. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1266. }
  1267. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1268. {
  1269. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1270. {
  1271. 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?
  1272. 0:
  1273. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1274. if(idxPeriod > 0)
  1275. {
  1276. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1277. {
  1278. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. }
  1284. else
  1285. {
  1286. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1287. {
  1288. if(txProfile.ChargingSchedule.Duration != -1)
  1289. {
  1290. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1291. 0:
  1292. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1293. }
  1294. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1295. {
  1296. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1297. {
  1298. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1299. 0:
  1300. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1301. if(idxPeriod > 0)
  1302. {
  1303. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1304. {
  1305. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. if(txProfile.ChargingSchedule.Duration != -1)
  1314. {
  1315. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1316. 0:
  1317. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1318. }
  1319. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1320. {
  1321. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1322. {
  1323. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1324. 0:
  1325. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1326. if(idxPeriod > 0)
  1327. {
  1328. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1329. {
  1330. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. /*
  1338. DEBUG_INFO("txProfile after align.\n");
  1339. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1340. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1341. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1342. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1343. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1344. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1345. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1346. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1347. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1348. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1349. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1350. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1351. {
  1352. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1353. {
  1354. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1355. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1356. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1357. }
  1358. }*/
  1359. }
  1360. if(defaultTxProfile.ChargingProfileId != -1)
  1361. {
  1362. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1363. {
  1364. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1365. {
  1366. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1367. 0:
  1368. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1369. }
  1370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1371. {
  1372. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1373. {
  1374. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1375. 0:
  1376. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1380. }
  1381. if(idxPeriod > 0)
  1382. {
  1383. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1384. {
  1385. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1392. {
  1393. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1394. {
  1395. 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?
  1396. 0:
  1397. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1398. }
  1399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1400. {
  1401. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1402. {
  1403. 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?
  1404. 0:
  1405. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1409. }
  1410. if(idxPeriod > 0)
  1411. {
  1412. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1413. {
  1414. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1415. }
  1416. }
  1417. }
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1423. {
  1424. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1425. {
  1426. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1427. 0:
  1428. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1429. }
  1430. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1431. {
  1432. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1433. {
  1434. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1435. 0:
  1436. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1440. }
  1441. if(idxPeriod > 0)
  1442. {
  1443. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1444. {
  1445. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. else
  1452. {
  1453. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1454. {
  1455. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1456. 0:
  1457. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1458. }
  1459. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1460. {
  1461. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1462. {
  1463. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1464. 0:
  1465. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1469. }
  1470. if(idxPeriod > 0)
  1471. {
  1472. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1473. {
  1474. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1475. }
  1476. }
  1477. }
  1478. }
  1479. }
  1480. }
  1481. /*
  1482. DEBUG_INFO("defaultTxProfile after align.\n");
  1483. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1484. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1485. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1486. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1487. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1488. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1489. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1490. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1491. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1492. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1493. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1494. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1495. {
  1496. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1497. {
  1498. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1499. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1500. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1501. }
  1502. }
  1503. DEBUG_INFO("------------------------------------\n");*/
  1504. }
  1505. if(maxProfile.ChargingProfileId != -1)
  1506. {
  1507. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1508. {
  1509. if(maxProfile.ChargingSchedule.Duration != -1)
  1510. {
  1511. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1512. 0:
  1513. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1514. }
  1515. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1516. {
  1517. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1518. {
  1519. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1520. 0:
  1521. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1522. if(idxPeriod > 0)
  1523. {
  1524. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1525. {
  1526. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1527. }
  1528. }
  1529. }
  1530. }
  1531. }
  1532. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1533. {
  1534. if(maxProfile.ChargingSchedule.Duration != -1)
  1535. {
  1536. 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?
  1537. 0:
  1538. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1539. }
  1540. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1541. {
  1542. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1543. {
  1544. 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?
  1545. 0:
  1546. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1547. if(idxPeriod > 0)
  1548. {
  1549. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1550. {
  1551. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. }
  1557. else
  1558. {
  1559. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1560. {
  1561. if(maxProfile.ChargingSchedule.Duration != -1)
  1562. {
  1563. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1564. 0:
  1565. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1566. }
  1567. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1568. {
  1569. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1570. {
  1571. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1572. 0:
  1573. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1574. if(idxPeriod > 0)
  1575. {
  1576. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1577. {
  1578. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. else
  1585. {
  1586. if(maxProfile.ChargingSchedule.Duration != -1)
  1587. {
  1588. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1589. 0:
  1590. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1591. }
  1592. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1593. {
  1594. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1595. {
  1596. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1597. 0:
  1598. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1599. if(idxPeriod > 0)
  1600. {
  1601. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1602. {
  1603. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1604. }
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. /*
  1611. DEBUG_INFO("MaxProfile after align.\n");
  1612. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1613. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1614. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1615. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1616. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1617. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1618. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1619. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1620. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1621. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1622. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1623. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1624. {
  1625. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1626. {
  1627. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1628. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1629. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1630. }
  1631. }
  1632. DEBUG_INFO("------------------------------------\n");*/
  1633. }
  1634. /*
  1635. * Merge to conposite schedule
  1636. */
  1637. //DEBUG_INFO("====================================\n");
  1638. // Find each profile period quantity
  1639. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1640. {
  1641. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1642. limitMax = idx+1;
  1643. }
  1644. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1645. {
  1646. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1647. limitDef = idx+1;
  1648. }
  1649. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1650. {
  1651. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1652. limitTx = idx+1;
  1653. }
  1654. // TxProfile found, composite schedule based on it
  1655. if(txProfile.ChargingProfileId != -1)
  1656. {
  1657. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1658. {
  1659. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1660. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1661. (txProfile.ChargingSchedule.Duration > 0))
  1662. {
  1663. if(maxProfile.ChargingProfileId != -1)
  1664. {
  1665. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1666. {
  1667. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1668. {
  1669. if((maxProfile.ChargingSchedule.Duration > 0))
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1674. }
  1675. else
  1676. {
  1677. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1678. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1679. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1680. }
  1681. }
  1682. if(idxMaxPeriod == (limitMax-1))
  1683. {
  1684. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1685. {
  1686. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1687. {
  1688. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1689. compositePeriodIdx++;
  1690. }
  1691. else
  1692. {
  1693. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1694. }
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else
  1700. {
  1701. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1702. {
  1703. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1704. compositePeriodIdx++;
  1705. }
  1706. else
  1707. {
  1708. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1709. }
  1710. }
  1711. }
  1712. if(idxTxPeriod == (limitTx-1))
  1713. {
  1714. if(defaultTxProfile.ChargingProfileId != -1)
  1715. {
  1716. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1717. {
  1718. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1719. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1720. (defaultTxProfile.ChargingSchedule.Duration>0))
  1721. {
  1722. if(maxProfile.ChargingProfileId != -1)
  1723. {
  1724. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1725. {
  1726. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1727. {
  1728. if((maxProfile.ChargingSchedule.Duration > 0))
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1733. }
  1734. else
  1735. {
  1736. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1737. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1738. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1739. }
  1740. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1741. {
  1742. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1743. {
  1744. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1745. compositePeriodIdx++;
  1746. }
  1747. else
  1748. {
  1749. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1759. {
  1760. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1761. compositePeriodIdx++;
  1762. }
  1763. else
  1764. {
  1765. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. }
  1773. }
  1774. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1775. else if(defaultTxProfile.ChargingProfileId != -1)
  1776. {
  1777. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1778. {
  1779. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1780. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1781. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1782. {
  1783. if(maxProfile.ChargingProfileId != -1)
  1784. {
  1785. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1786. {
  1787. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1788. {
  1789. if((maxProfile.ChargingSchedule.Duration > 0))
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1794. }
  1795. else
  1796. {
  1797. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1798. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1799. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1800. }
  1801. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1802. {
  1803. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1804. {
  1805. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1806. compositePeriodIdx++;
  1807. }
  1808. else
  1809. {
  1810. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1811. }
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. else
  1818. {
  1819. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1820. {
  1821. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1822. compositePeriodIdx++;
  1823. }
  1824. else
  1825. {
  1826. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. // Fill other period by MaxProfile
  1833. if(maxProfile.ChargingProfileId != -1)
  1834. {
  1835. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1836. {
  1837. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1838. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1839. (maxProfile.ChargingSchedule.Duration > 0))
  1840. {
  1841. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1842. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1845. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1849. {
  1850. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1851. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1852. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1853. }
  1854. if(tmpPeriod.Limit != -1)
  1855. {
  1856. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1857. {
  1858. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1859. {
  1860. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1861. compositePeriodIdx++;
  1862. }
  1863. else
  1864. {
  1865. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1873. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1874. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1876. {
  1877. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1878. {
  1879. compositeProfile->ChargingProfileId = 1;
  1880. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1881. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1882. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1883. }
  1884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1885. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1886. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1887. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1888. }
  1889. if(line)
  1890. free(line);
  1891. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1892. }
  1893. //==========================================
  1894. // Init all share memory
  1895. //==========================================
  1896. int InitShareMemory()
  1897. {
  1898. int result = PASS;
  1899. int MeterSMId;
  1900. //creat ShmSysConfigAndInfo
  1901. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1902. {
  1903. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1904. result = FAIL;
  1905. }
  1906. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1907. {
  1908. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1909. result = FAIL;
  1910. }
  1911. else
  1912. {}
  1913. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1914. {
  1915. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1916. result = FAIL;
  1917. }
  1918. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1919. {
  1920. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1921. result = FAIL;
  1922. }
  1923. else
  1924. {}
  1925. //creat ShmPsuData
  1926. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1927. {
  1928. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1932. {
  1933. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1934. result = FAIL;
  1935. }
  1936. else
  1937. {}
  1938. //creat ShmOCPP16Data
  1939. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1940. {
  1941. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1942. result = FAIL;
  1943. }
  1944. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1945. {
  1946. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1947. result = FAIL;
  1948. }
  1949. else
  1950. {}
  1951. /****************************** For Initial Settings************************************************/
  1952. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1954. // allocate Configuration memory address
  1955. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1956. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1957. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1958. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1959. //offline MeterValue Interval
  1960. TempMeterValueInterval = 0;
  1961. return result;
  1962. }
  1963. int ProcessShareMemory()
  1964. {
  1965. if(InitShareMemory() == FAIL)
  1966. {
  1967. DEBUG_ERROR("InitShareMemory NG\n");
  1968. if(ShmStatusCodeData!=NULL)
  1969. {
  1970. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1971. }
  1972. sleep(5);
  1973. return FAIL;
  1974. }
  1975. return PASS;
  1976. }
  1977. //---------------------common routine---------------------------//
  1978. int isOFFline(void)
  1979. {
  1980. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1981. {
  1982. if(TempMeterValueInterval >= 2 )
  1983. {
  1984. TempMeterValueInterval = 0;
  1985. return TRUE;
  1986. }
  1987. else
  1988. {
  1989. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1990. return FALSE;
  1991. }
  1992. }
  1993. else
  1994. {
  1995. return FALSE;
  1996. }
  1997. }
  1998. //---------------------------------------------
  1999. // new:
  2000. // enum SYSTEM_STATUS
  2001. // {
  2002. // SYS_MODE_BOOTING = 0,
  2003. // SYS_MODE_IDLE = 1,
  2004. // SYS_MODE_AUTHORIZING = 2,
  2005. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2006. // SYS_MODE_REASSIGN = 4,
  2007. // SYS_MODE_PREPARING = 5,
  2008. // SYS_MODE_PREPARE_FOR_EV = 6,
  2009. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2010. // SYS_MODE_CHARGING = 8,
  2011. // SYS_MODE_TERMINATING = 9,
  2012. // SYS_MODE_COMPLETE = 10,
  2013. // SYS_MODE_ALARM = 11,
  2014. // SYS_MODE_FAULT = 12,
  2015. // SYS_MODE_RESERVATION = 13,
  2016. // SYS_MODE_BOOKING = 14,
  2017. // SYS_MODE_MAINTAIN = 15,
  2018. // SYS_MODE_DEBUG = 16,
  2019. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2020. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2021. // SYS_MODE_UPDATE = 19
  2022. // };
  2023. //
  2024. //
  2025. //-----------------------------------------
  2026. void CheckSystemValue(void)
  2027. {
  2028. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2029. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2030. char filenmae[100]={0};
  2031. char str[100]={0};
  2032. int tempIndex = 0;
  2033. //===============================
  2034. // send Heartbeat
  2035. //===============================
  2036. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2037. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2038. {
  2039. clientTime.Heartbeat=time((time_t*)NULL);
  2040. if(server_sign == TRUE)
  2041. {
  2042. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2043. }
  2044. else
  2045. {
  2046. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2047. }
  2048. }
  2049. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2050. {
  2051. //parameter for test
  2052. sendHeartbeatRequest(0);
  2053. //==============================================
  2054. // Reset Waiting Time
  2055. //==============================================
  2056. HeartBeatWithNOResponse += 1;
  2057. }
  2058. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2059. {
  2060. //===============================
  2061. // CSU Trigger Reset Conf
  2062. //===============================
  2063. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2064. {
  2065. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2066. }
  2067. //===============================
  2068. // CSU Trigger Authorize Request
  2069. //===============================
  2070. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2071. {
  2072. sendAuthorizeRequest(0);
  2073. authorizeRetryTimes = authorizeRetryTimes + 1;
  2074. if(authorizeRetryTimes < 3)
  2075. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2076. }
  2077. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2078. {
  2079. authorizeRetryTimes = 0;
  2080. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2081. server_sign = FALSE;
  2082. }
  2083. 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))
  2084. {
  2085. sendAuthorizeRequest(0);
  2086. }
  2087. //===============================
  2088. // CSU Trigger Smart Charging Profilw
  2089. //===============================
  2090. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2091. {
  2092. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2093. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2094. }
  2095. //==============================================
  2096. // Charger start transaction
  2097. //==============================================
  2098. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2099. {
  2100. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2101. sendStartTransactionRequest(gun_index);
  2102. clientTime.StartTransaction = time((time_t*)NULL);
  2103. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2104. }
  2105. //==============================================
  2106. // Charger stop transaction
  2107. //==============================================
  2108. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2109. {
  2110. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2111. sendStopTransactionRequest(gun_index);
  2112. clientTime.StopTransaction = time((time_t*)NULL);
  2113. }
  2114. //==============================================
  2115. // Charger status report
  2116. //==============================================
  2117. //--- Check Mode Change ---//
  2118. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2119. if(gunType[gun_index] == 'J')
  2120. {
  2121. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2122. {
  2123. tempIndex = ((gun_index==2) ? 1: 0);
  2124. }
  2125. else
  2126. {
  2127. tempIndex = gun_index;
  2128. }
  2129. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2130. {
  2131. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2132. {
  2133. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2134. {
  2135. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2136. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2137. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2138. statusModeChage[gun_index] = TRUE;
  2139. }
  2140. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2141. {
  2142. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2143. if((access(filenmae,F_OK))!=-1)
  2144. {
  2145. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2146. sprintf(str,"rm -f %s",filenmae);
  2147. system(str);
  2148. }
  2149. }
  2150. #if 1 // for TempStopTransaction
  2151. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2152. {
  2153. checkTempStopTransaction(gun_index);
  2154. }
  2155. #endif
  2156. }
  2157. }
  2158. }
  2159. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2160. {
  2161. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2162. {
  2163. tempIndex = ((gun_index==2) ? 1: 0);
  2164. }
  2165. else
  2166. {
  2167. tempIndex = gun_index;
  2168. }
  2169. for (int index = 0; index < CCS_QUANTITY; index++)
  2170. {
  2171. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2172. {
  2173. if((SystemInitial > 0) || (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]*/ )
  2174. {
  2175. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2176. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2177. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2178. statusModeChage[gun_index] = TRUE;
  2179. }
  2180. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2181. {
  2182. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2183. if((access(filenmae,F_OK))!=-1)
  2184. {
  2185. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2186. sprintf(str,"rm -f %s",filenmae);
  2187. system(str);
  2188. }
  2189. }
  2190. #if 1 // for TempStopTransaction
  2191. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2192. {
  2193. checkTempStopTransaction(gun_index);
  2194. }
  2195. #endif
  2196. }
  2197. }
  2198. }
  2199. else if(gunType[gun_index] == 'G')
  2200. {
  2201. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2202. {
  2203. tempIndex = ((gun_index==2) ? 1: 0);
  2204. }
  2205. else
  2206. {
  2207. tempIndex = gun_index;
  2208. }
  2209. for (int index = 0; index < GB_QUANTITY; index++)
  2210. {
  2211. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2212. {
  2213. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2214. {
  2215. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2216. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2217. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2218. statusModeChage[gun_index] = TRUE;
  2219. }
  2220. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2221. {
  2222. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2223. if((access(filenmae,F_OK))!=-1)
  2224. {
  2225. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2226. sprintf(str,"rm -f %s",filenmae);
  2227. system(str);
  2228. }
  2229. }
  2230. #if 1 // for TempStopTransaction
  2231. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2232. {
  2233. checkTempStopTransaction(gun_index);
  2234. }
  2235. #endif
  2236. }
  2237. }
  2238. }
  2239. else if(gunType[gun_index] == 'O')
  2240. {
  2241. tempIndex = gun_index;
  2242. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2243. {
  2244. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2245. {
  2246. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2247. {
  2248. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2249. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2250. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2251. statusModeChage[gun_index] = TRUE;
  2252. }
  2253. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  2254. {
  2255. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2256. if((access(filenmae,F_OK))!=-1)
  2257. {
  2258. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2259. sprintf(str,"rm -f %s",filenmae);
  2260. system(str);
  2261. }
  2262. }
  2263. #if 1 // for TempStopTransaction
  2264. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2265. {
  2266. checkTempStopTransaction(gun_index);
  2267. }
  2268. #endif
  2269. }
  2270. }
  2271. }
  2272. else
  2273. {
  2274. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2275. {
  2276. tempIndex = 2;
  2277. }
  2278. else
  2279. {
  2280. tempIndex = gun_index;
  2281. }
  2282. for (int index = 0; index < AC_QUANTITY; index++)
  2283. {
  2284. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2285. {
  2286. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2287. {
  2288. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2289. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2290. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2291. statusModeChage[gun_index] = TRUE;
  2292. }
  2293. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2294. {
  2295. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2296. if((access(filenmae,F_OK))!=-1)
  2297. {
  2298. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2299. sprintf(str,"rm -f %s",filenmae);
  2300. system(str);
  2301. }
  2302. }
  2303. #if 1 // for TempStopTransaction
  2304. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2305. {
  2306. checkTempStopTransaction(gun_index);
  2307. }
  2308. #endif
  2309. }
  2310. }// END
  2311. }
  2312. if(isWebsocketSendable &&
  2313. (((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]) > 10)))) )
  2314. {
  2315. if(SystemInitial > 0)
  2316. SystemInitial -= 1;
  2317. sendStatusNotificationRequest(gun_index);
  2318. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2319. statusModeChage[gun_index] = FALSE;
  2320. }
  2321. //==============================================
  2322. // Meter report
  2323. //==============================================
  2324. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2325. {
  2326. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2327. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2328. }
  2329. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2330. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2331. {
  2332. //check Transaction active
  2333. if(gunType[gun_index] == 'J')
  2334. {
  2335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2336. {
  2337. tempIndex = ((gun_index==2) ? 1: 0);
  2338. }
  2339. else
  2340. {
  2341. tempIndex = gun_index;
  2342. }
  2343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2344. {
  2345. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2346. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2347. {
  2348. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2349. {
  2350. reqSampleMeter[gun_index] = 1;
  2351. }
  2352. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2353. {
  2354. reqClockAlignMeter[gun_index] = 1;
  2355. }
  2356. }
  2357. }// End for CHAdeMO
  2358. }
  2359. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2360. {
  2361. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2362. {
  2363. tempIndex = ((gun_index==2) ? 1: 0);
  2364. }
  2365. else
  2366. {
  2367. tempIndex = gun_index;
  2368. }
  2369. for (int index = 0; index < CCS_QUANTITY; index++)
  2370. {
  2371. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2372. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2373. {
  2374. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2375. {
  2376. reqSampleMeter[gun_index] = 1;
  2377. }
  2378. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2379. {
  2380. reqClockAlignMeter[gun_index] = 1;
  2381. }
  2382. }
  2383. } // End for CCS
  2384. }
  2385. else if(gunType[gun_index] == 'G')
  2386. {
  2387. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2388. {
  2389. tempIndex = ((gun_index==2) ? 1: 0);
  2390. }
  2391. else
  2392. {
  2393. tempIndex = gun_index;
  2394. }
  2395. for (int index = 0; index < GB_QUANTITY; index++)
  2396. {
  2397. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2398. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2399. {
  2400. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2401. {
  2402. reqSampleMeter[gun_index] = 1;
  2403. }
  2404. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2405. {
  2406. reqClockAlignMeter[gun_index] = 1;
  2407. }
  2408. }
  2409. }// End for GB
  2410. }
  2411. else if(gunType[gun_index] == 'O')
  2412. {
  2413. tempIndex = gun_index;
  2414. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2415. {
  2416. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2417. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2418. {
  2419. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2420. {
  2421. reqSampleMeter[gun_index] = 1;
  2422. }
  2423. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2424. {
  2425. reqClockAlignMeter[gun_index] = 1;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. else
  2431. {
  2432. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2433. {
  2434. tempIndex = 2;
  2435. }
  2436. else
  2437. {
  2438. tempIndex = gun_index;
  2439. }
  2440. for (int index = 0; index < AC_QUANTITY; index++)
  2441. {
  2442. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2443. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2444. {
  2445. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2446. {
  2447. reqSampleMeter[gun_index] = 1;
  2448. }
  2449. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2450. {
  2451. reqClockAlignMeter[gun_index] = 1;
  2452. }
  2453. }
  2454. }//End for AC
  2455. }
  2456. if(reqSampleMeter[gun_index] == 1)
  2457. {
  2458. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2459. storeTempStopTransaction(gun_index);
  2460. }
  2461. else if(reqClockAlignMeter[gun_index] == 1)
  2462. {
  2463. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2464. }
  2465. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2466. sleep(1);
  2467. }
  2468. //==============================================
  2469. // Check Connector reserved
  2470. //==============================================
  2471. //===============================
  2472. // Check if Reserve is expired
  2473. //===============================
  2474. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2475. {
  2476. double diff_t;
  2477. struct tm tp;
  2478. // current time
  2479. time_t t = time(NULL);
  2480. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2481. tp.tm_isdst = -1;
  2482. time_t utc = mktime(&tp);
  2483. diff_t = difftime(utc, t);
  2484. if(diff_t <= 0)
  2485. {
  2486. DEBUG_INFO("reserve expired.\n");
  2487. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2488. }
  2489. }//END OF Check if Reserve is expired
  2490. //==========================================
  2491. // csu trigger FirmwareStatusNotificationReq
  2492. //==========================================
  2493. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2494. {
  2495. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2496. }
  2497. //==========================================
  2498. // csu trigger CancelReservationConf
  2499. //==========================================
  2500. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2501. {
  2502. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2503. }
  2504. //==========================================
  2505. // csu trigger ChangeAvailabilityConf
  2506. //==========================================
  2507. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2508. {
  2509. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2510. }
  2511. //==========================================
  2512. // csu trigger UnlockConnectorConf
  2513. //==========================================
  2514. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2515. {
  2516. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2517. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2518. }
  2519. //==========================================
  2520. // csu trigger ReserveNowConf
  2521. //==========================================
  2522. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2523. {
  2524. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2525. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2526. }
  2527. //==========================================
  2528. // csu trigger DataTransferReq
  2529. //==========================================
  2530. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2531. {
  2532. sendDataTransferRequest(gun_index);
  2533. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2534. }
  2535. }
  2536. }
  2537. //==========================================
  2538. // send request routine
  2539. //==========================================
  2540. int sendAuthorizeRequest(int gun_index)
  2541. {
  2542. mtrace();
  2543. int result = FAIL;
  2544. char message[100]={0};
  2545. char guid[37];
  2546. char tempdata[65]={0};
  2547. DEBUG_INFO("sendAuthorizeRequest...\n");
  2548. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2549. //Local Authorize
  2550. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2551. {
  2552. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2553. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2554. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2555. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2556. result = PASS;
  2557. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2558. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2559. authorizeRetryTimes = 0;
  2560. return result;
  2561. }
  2562. 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))||
  2563. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2564. {
  2565. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2566. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2567. {
  2568. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2569. {
  2570. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2571. }
  2572. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2573. {
  2574. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2575. }
  2576. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2577. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2578. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2579. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2580. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2581. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2582. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2583. authorizeRetryTimes = 0;
  2584. return result;
  2585. }
  2586. else
  2587. {
  2588. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2589. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2590. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2591. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2592. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2593. else
  2594. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2595. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2596. result = PASS;
  2597. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2598. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2599. authorizeRetryTimes = 0;
  2600. return result;
  2601. }
  2602. }
  2603. //initailize struct Authorize
  2604. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2605. //get data from shared memory
  2606. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2607. random_uuid(guid);
  2608. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2609. LWS_Send(message);
  2610. sprintf(tempdata, "Authorize,%d", gun_index);
  2611. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2612. {
  2613. result = PASS;
  2614. DEBUG_INFO("Authorize mapItem pass\n");
  2615. }
  2616. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2617. return result;
  2618. }
  2619. int sendBootNotificationRequest(void)
  2620. {
  2621. mtrace();
  2622. int result = FAIL;
  2623. char message[500]={0}, payload[700]={0};
  2624. char guid[37]={0};
  2625. char tempdata[65]={0};
  2626. /*
  2627. int IsGunCharging = FALSE;
  2628. //check Transaction active
  2629. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2630. {
  2631. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2632. {
  2633. IsGunCharging = TRUE;
  2634. }
  2635. }
  2636. for (int index = 0; index < CCS_QUANTITY; index++)
  2637. {
  2638. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2639. {
  2640. IsGunCharging = TRUE;
  2641. }
  2642. }
  2643. for (int index = 0; index < GB_QUANTITY; index++)
  2644. {
  2645. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2646. {
  2647. IsGunCharging = TRUE;
  2648. }
  2649. }
  2650. for (int index = 0; index < AC_QUANTITY; index++)
  2651. {
  2652. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2653. {
  2654. IsGunCharging = TRUE;
  2655. }
  2656. }
  2657. if(IsGunCharging == TRUE)
  2658. {
  2659. server_sign = TRUE;
  2660. return result;
  2661. }
  2662. */
  2663. // Fill BootNotification fields
  2664. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2665. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2666. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2667. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2668. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2669. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2670. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2671. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2672. ShmOCPP16Data->ChargeBoxId
  2673. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2674. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2675. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2676. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2677. ,ShmOCPP16Data->BootNotification.CpIccid
  2678. ,ShmOCPP16Data->BootNotification.CpImsi);
  2679. random_uuid(guid);
  2680. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2681. LWS_Send(message);
  2682. sprintf(tempdata, "BootNotification,0");
  2683. 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*/)
  2684. {
  2685. result = PASS;
  2686. }
  2687. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2688. strcpy(queuedata,message);
  2689. return result;
  2690. }
  2691. int sendDataTransferRequest(int gun_index)
  2692. {
  2693. mtrace();
  2694. char message[1000]={0};
  2695. char guid[37]={0};
  2696. char tempdata[65]={0};
  2697. int result = FAIL;
  2698. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2699. random_uuid(guid);
  2700. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2701. MESSAGE_TYPE_CALL,
  2702. guid,
  2703. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2704. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2705. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2706. LWS_Send(message);
  2707. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2708. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2709. {
  2710. result = PASS;
  2711. DEBUG_INFO("DataTransfer mapItem pass\n");
  2712. }
  2713. return result;
  2714. }
  2715. int sendDiagnosticsStatusNotificationRequest(char *status)
  2716. {
  2717. mtrace();
  2718. int result = FAIL;
  2719. char message[110]={0};
  2720. char guid[37]={0};
  2721. char tempdata[65]={0};
  2722. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2723. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2724. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2725. random_uuid(guid);
  2726. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2727. LWS_SendNow(message);
  2728. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2729. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2730. {
  2731. result = PASS;
  2732. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2733. }
  2734. //#ifdef SystemLogMessage
  2735. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2736. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2737. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2738. //#endif
  2739. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2740. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2741. //record status
  2742. if(strcmp(status,"Idle")==0)
  2743. {
  2744. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2745. }
  2746. else if(strcmp(status,"Uploaded")==0)
  2747. {
  2748. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2749. }
  2750. else if(strcmp(status,"UploadFailed")==0)
  2751. {
  2752. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2753. }
  2754. else if(strcmp(status,"Uploading")==0)
  2755. {
  2756. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2757. }
  2758. return result;
  2759. }
  2760. int sendFirmwareStatusNotificationRequest(char *status)
  2761. {
  2762. mtrace();
  2763. int result = FAIL;
  2764. char message[110]={0};
  2765. char guid[37]={0};
  2766. char tempdata[65]={0};
  2767. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2768. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2769. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2770. random_uuid(guid);
  2771. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2772. LWS_SendNow(message);
  2773. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2774. 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*/)
  2775. {
  2776. result = PASS;
  2777. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2778. }
  2779. //#ifdef SystemLogMessage
  2780. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2781. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2782. //#endif
  2783. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2784. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2785. //record status
  2786. if(strcmp(status,"Downloaded")==0)
  2787. {
  2788. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2789. }
  2790. else if(strcmp(status,"DownloadFailed")==0)
  2791. {
  2792. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2793. }
  2794. else if(strcmp(status,"Downloading")==0)
  2795. {
  2796. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2797. }
  2798. else if(strcmp(status,"Idle")==0)
  2799. {
  2800. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2801. }
  2802. else if(strcmp(status,"InstallationFailed")==0)
  2803. {
  2804. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2805. }
  2806. else if(strcmp(status,"Installing")==0)
  2807. {
  2808. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2809. }
  2810. else if(strcmp(status,"Installed")==0)
  2811. {
  2812. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2813. }
  2814. return result;
  2815. }
  2816. int sendHeartbeatRequest(int gun_index)
  2817. {
  2818. mtrace();
  2819. int result = FAIL;
  2820. char message[80]={0};
  2821. char guid[37]={0};
  2822. char tempdata[65]={0};
  2823. random_uuid(guid);
  2824. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2825. , MESSAGE_TYPE_CALL
  2826. , guid );
  2827. LWS_Send(message);
  2828. sprintf(tempdata, "Heartbeat,%d", 0);
  2829. 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*/)
  2830. {
  2831. result = PASS;
  2832. }
  2833. return result;
  2834. }
  2835. int sendStartTransactionRequest(int gun_index)
  2836. {
  2837. mtrace();
  2838. int result = FAIL;
  2839. char message[250]={0};
  2840. char guid[37]={0};
  2841. struct timeval tmnow;
  2842. struct tm *tm;
  2843. char buf[28];//, usec_buf[6];
  2844. char tempdata[65]={0};
  2845. int tempIndex = 0;
  2846. DEBUG_INFO("sendStartTransactionRequest...\n");
  2847. gettimeofday(&tmnow, NULL);
  2848. time_t t;
  2849. t = time(NULL);
  2850. /*UTC time and date*/
  2851. tm = gmtime(&t);
  2852. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2853. #if 0 // remove temporally
  2854. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2855. strcat(buf,".");
  2856. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2857. strcat(buf,usec_buf);
  2858. #endif
  2859. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2860. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2861. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2862. // clear StartTransaction Response
  2863. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2864. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2865. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2866. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2867. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2868. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2869. if(gunType[gun_index] == 'J')
  2870. {
  2871. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2872. {
  2873. tempIndex = ((gun_index==2) ? 1: 0);
  2874. }
  2875. else
  2876. {
  2877. tempIndex = gun_index;
  2878. }
  2879. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2880. {
  2881. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2882. {
  2883. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2884. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2885. }
  2886. }
  2887. }
  2888. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2889. {
  2890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2891. {
  2892. tempIndex = ((gun_index==2) ? 1: 0);
  2893. }
  2894. else
  2895. {
  2896. tempIndex = gun_index;
  2897. }
  2898. for (int index = 0; index < CCS_QUANTITY; index++)
  2899. {
  2900. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2901. {
  2902. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2903. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2904. }
  2905. }
  2906. }
  2907. else if(gunType[gun_index] == 'G')
  2908. {
  2909. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2910. {
  2911. tempIndex = ((gun_index==2) ? 1: 0);
  2912. }
  2913. else
  2914. {
  2915. tempIndex = gun_index;
  2916. }
  2917. for (int index = 0; index < GB_QUANTITY; index++)
  2918. {
  2919. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2920. {
  2921. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2922. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2923. }
  2924. }
  2925. }
  2926. else if(gunType[gun_index] == 'O')
  2927. {
  2928. tempIndex = gun_index;
  2929. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2930. {
  2931. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2932. {
  2933. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  2934. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  2935. }
  2936. }
  2937. }
  2938. else
  2939. {
  2940. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2941. {
  2942. tempIndex = 2;
  2943. }
  2944. else
  2945. {
  2946. tempIndex = gun_index;
  2947. }
  2948. for (int index = 0; index < AC_QUANTITY; index++)
  2949. {
  2950. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2951. {
  2952. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2953. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2954. }
  2955. }
  2956. }
  2957. random_uuid(guid);
  2958. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2959. {
  2960. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2961. , gun_index +1
  2962. , MESSAGE_TYPE_CALL
  2963. , guid
  2964. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2965. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2966. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2967. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2968. }
  2969. else
  2970. {
  2971. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2972. , gun_index +1
  2973. , MESSAGE_TYPE_CALL
  2974. , guid
  2975. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2976. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2977. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2978. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2979. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2980. }
  2981. #if 1
  2982. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2983. 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*/)
  2984. {
  2985. result = PASS;
  2986. }
  2987. #endif
  2988. strcpy(queuedata, message);
  2989. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2990. return result;
  2991. }
  2992. int sendStatusNotificationRequest(int gun_index)
  2993. {
  2994. mtrace();
  2995. int result = FAIL;
  2996. char message[600]={0};
  2997. char guid[37];
  2998. int currentStatus = 0;
  2999. struct timeval tmnow;
  3000. struct tm *tm;
  3001. char buf[28];//, usec_buf[6];
  3002. char tempdata[65]={0};
  3003. int tempIndex = 0;
  3004. gettimeofday(&tmnow, NULL);
  3005. time_t t;
  3006. t = time(NULL);
  3007. /*UTC time and date*/
  3008. tm = gmtime(&t);
  3009. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3010. #if 0 // remove temporally
  3011. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3012. strcat(buf,".");
  3013. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3014. strcat(buf,usec_buf);
  3015. #endif
  3016. printf("%s",buf);
  3017. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3018. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3019. // it's option
  3020. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3021. /*
  3022. enum _SYSTEM_STATUS
  3023. {
  3024. S_BOOTING = 0,
  3025. S_IDLE, = 1
  3026. S_AUTHORIZING, =2
  3027. S_REASSIGN_CHECK, =3
  3028. S_REASSIGN, =4
  3029. S_PRECHARGE, =5
  3030. S_PREPARING_FOR_EV, =6
  3031. S_PREPARING_FOR_EVSE, =7
  3032. S_CHARGING, =8
  3033. S_TERMINATING, =9
  3034. S_COMPLETE, =10
  3035. S_ALARM, =11
  3036. S_FAULT =12
  3037. }
  3038. */
  3039. //check Transaction active
  3040. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3041. if(gunType[gun_index] == 'J')
  3042. {
  3043. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3044. {
  3045. tempIndex = ((gun_index==2) ? 1: 0);
  3046. }
  3047. else
  3048. {
  3049. tempIndex = gun_index;
  3050. }
  3051. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3052. {
  3053. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3054. {
  3055. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3056. {
  3057. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3058. {
  3059. currentStatus = 1; //OCPP Status: Preparing
  3060. }
  3061. else
  3062. {
  3063. currentStatus = 0; //OCPP Status: Available
  3064. }
  3065. }
  3066. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3067. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3068. ) //S_PRECHARGE
  3069. {
  3070. currentStatus = 1; //OCPP Status: Preparing
  3071. }
  3072. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3073. {
  3074. currentStatus = 2; //OCPP Status: Charging
  3075. }
  3076. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3077. {
  3078. currentStatus = 5; //OCPP Status: Finishing
  3079. }
  3080. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3081. {
  3082. currentStatus = 4; //OCPP Status: SuspendedEV
  3083. }
  3084. 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
  3085. {
  3086. currentStatus = 7; //OCPP Status: Unavailable
  3087. }
  3088. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3089. {
  3090. currentStatus = 8; //OCPP Status: Faulted
  3091. }
  3092. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3093. {
  3094. currentStatus = 6; //OCPP Status: Reserved
  3095. }
  3096. } //end of the same index
  3097. }//end of for CHAdeMO_QUANTITY
  3098. }
  3099. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3100. {
  3101. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3102. {
  3103. tempIndex = ((gun_index==2) ? 1: 0);
  3104. }
  3105. else
  3106. {
  3107. tempIndex = gun_index;
  3108. }
  3109. for (int index = 0; index < CCS_QUANTITY; index++)
  3110. {
  3111. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3112. {
  3113. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3114. {
  3115. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3116. {
  3117. currentStatus = 1; //OCPP Status: Preparing
  3118. }
  3119. else
  3120. {
  3121. currentStatus = 0; //OCPP Status: Available
  3122. }
  3123. }
  3124. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3125. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3126. ) //S_PRECHARGE
  3127. {
  3128. currentStatus = 1; //OCPP Status: Preparing
  3129. }
  3130. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3131. {
  3132. currentStatus = 2; //OCPP Status: Charging
  3133. }
  3134. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3135. {
  3136. currentStatus = 5; //OCPP Status: Finishing
  3137. }
  3138. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3139. {
  3140. currentStatus = 4; //OCPP Status: SuspendedEV
  3141. }
  3142. 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
  3143. {
  3144. currentStatus = 7; //OCPP Status : Unavailable
  3145. }
  3146. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3147. {
  3148. currentStatus = 8; //OCPP Status: Faulted
  3149. }
  3150. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3151. {
  3152. currentStatus = 6; //OCPP Status: Reserved
  3153. }
  3154. } //end of the same index
  3155. } // end of for CCS_QUANTITY
  3156. }
  3157. else if(gunType[gun_index] == 'G')
  3158. {
  3159. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3160. {
  3161. tempIndex = ((gun_index==2) ? 1: 0);
  3162. }
  3163. else
  3164. {
  3165. tempIndex = gun_index;
  3166. }
  3167. for (int index = 0; index < GB_QUANTITY; index++)
  3168. {
  3169. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3170. {
  3171. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3172. {
  3173. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3174. {
  3175. currentStatus = 1; //OCPP Status: Preparing
  3176. }
  3177. else
  3178. {
  3179. currentStatus = 0; //OCPP Status: Available
  3180. }
  3181. }
  3182. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3183. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3184. ) //S_PRECHARGE
  3185. {
  3186. currentStatus = 1; //OCPP Status: Preparing
  3187. }
  3188. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3189. {
  3190. currentStatus = 2; //OCPP Status: Charging
  3191. }
  3192. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3193. {
  3194. currentStatus = 5; //OCPP Status: Finishing
  3195. }
  3196. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3197. {
  3198. currentStatus = 4; //OCPP Status: SuspendedEV
  3199. }
  3200. 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
  3201. {
  3202. currentStatus = 7; //OCPP Status: Unavailable
  3203. }
  3204. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3205. {
  3206. currentStatus = 8; //OCPP Status: Faulted
  3207. }
  3208. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3209. {
  3210. currentStatus = 6; //OCPP Status: Reserved
  3211. }
  3212. } //end of the same index
  3213. } // end of for GB_QUANTITY
  3214. }
  3215. else if(gunType[gun_index] == 'O')
  3216. {
  3217. tempIndex = gun_index;
  3218. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3219. {
  3220. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3221. {
  3222. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3223. {
  3224. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3225. {
  3226. currentStatus = 1; //OCPP Status: Preparing
  3227. }
  3228. else
  3229. {
  3230. currentStatus = 0; //OCPP Status: Available
  3231. }
  3232. }
  3233. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3234. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3235. ) //S_PRECHARGE
  3236. {
  3237. currentStatus = 1; //OCPP Status: Preparing
  3238. }
  3239. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3240. {
  3241. currentStatus = 2; //OCPP Status: Charging
  3242. }
  3243. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3244. {
  3245. currentStatus = 5; //OCPP Status: Finishing
  3246. }
  3247. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3248. {
  3249. currentStatus = 4; //OCPP Status: SuspendedEV
  3250. }
  3251. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3252. {
  3253. currentStatus = 7; //OCPP Status: Unavailable
  3254. }
  3255. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3256. {
  3257. currentStatus = 8; //OCPP Status: Faulted
  3258. }
  3259. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3260. {
  3261. currentStatus = 6; //OCPP Status: Reserved
  3262. }
  3263. } //end of the same index
  3264. }
  3265. }
  3266. else
  3267. {
  3268. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3269. {
  3270. tempIndex = 2;
  3271. }
  3272. else
  3273. {
  3274. tempIndex = gun_index;
  3275. }
  3276. for (int index = 0; index < AC_QUANTITY; index++)
  3277. {
  3278. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3279. {
  3280. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3281. {
  3282. 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))
  3283. {
  3284. currentStatus = 1; //OCPP Status: Preparing
  3285. }
  3286. else
  3287. {
  3288. currentStatus = 0; //OCPP Status: Available
  3289. }
  3290. }
  3291. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3292. {
  3293. currentStatus = 1; //OCPP Status: Preparing
  3294. }
  3295. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3296. {
  3297. currentStatus = 2; //OCPP Status: Charging
  3298. }
  3299. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3300. {
  3301. currentStatus = 5; //OCPP Status: Finishing
  3302. }
  3303. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3304. {
  3305. currentStatus = 4; //OCPP Status: SuspendedEV
  3306. }
  3307. 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
  3308. {
  3309. currentStatus = 7; //OCPP Status: Unavailable
  3310. }
  3311. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3312. {
  3313. currentStatus = 8; //OCPP Status: Faulted
  3314. }
  3315. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3316. {
  3317. currentStatus = 6; //OCPP Status: Reserved
  3318. }
  3319. }//end of the same index
  3320. }//end of for AC_QUANTITY
  3321. }
  3322. //it's option
  3323. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3324. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3325. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3326. random_uuid(guid);
  3327. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3328. , MESSAGE_TYPE_CALL
  3329. , guid
  3330. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3331. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3332. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3333. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3334. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3335. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3336. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3337. if((server_sign == TRUE))
  3338. {
  3339. LWS_Send(message);
  3340. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3341. 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*/)
  3342. {
  3343. //DEBUG_ERROR("statusNotification mapitem pass");
  3344. result = PASS;
  3345. }
  3346. }
  3347. else
  3348. {
  3349. result = PASS;
  3350. }
  3351. return result;
  3352. }
  3353. int sendStopTransactionRequest(int gun_index)
  3354. {
  3355. mtrace();
  3356. int result = FAIL;
  3357. //char message[1500]={0};
  3358. char guid[37]={0};
  3359. char tempdata[65]={0};
  3360. int tempIndex = 0;
  3361. char TempStopTransaction[256];
  3362. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3363. //int idx_sample=0;
  3364. DEBUG_INFO("sendStopTransactionRequest \n");
  3365. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3366. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3367. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3368. if(gunType[gun_index] == 'J')
  3369. {
  3370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3371. {
  3372. tempIndex = ((gun_index==2) ? 1: 0);
  3373. }
  3374. else
  3375. {
  3376. tempIndex = gun_index;
  3377. }
  3378. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3379. {
  3380. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3381. {
  3382. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3383. }
  3384. }// END OF CHAdeMO_QUANTITY
  3385. }
  3386. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3387. {
  3388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3389. {
  3390. tempIndex = ((gun_index==2) ? 1: 0);
  3391. }
  3392. else
  3393. {
  3394. tempIndex = gun_index;
  3395. }
  3396. for (int index = 0; index < CCS_QUANTITY; index++)
  3397. {
  3398. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3399. {
  3400. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3401. }
  3402. }// END OF CCS_QUANTITY
  3403. }
  3404. else if(gunType[gun_index] == 'G')
  3405. {
  3406. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3407. {
  3408. tempIndex = ((gun_index==2) ? 1: 0);
  3409. }
  3410. else
  3411. {
  3412. tempIndex = gun_index;
  3413. }
  3414. for (int index = 0; index < GB_QUANTITY; index++)
  3415. {
  3416. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3417. {
  3418. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3419. }
  3420. }// END OF GB_QUANTITY
  3421. }
  3422. else if(gunType[gun_index] == 'O')
  3423. {
  3424. tempIndex = gun_index;
  3425. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3426. {
  3427. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3428. {
  3429. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3430. }
  3431. }// END OF GB_QUANTITY
  3432. }
  3433. else
  3434. {
  3435. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3436. {
  3437. tempIndex = 2;
  3438. }
  3439. else
  3440. {
  3441. tempIndex = gun_index;
  3442. }
  3443. for (int index = 0; index < AC_QUANTITY; index++)
  3444. {
  3445. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3446. {
  3447. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3448. }
  3449. }// END OF AC_QUANTITY
  3450. }
  3451. //====================================== Stop Transaction Time =====================================================
  3452. struct timeval tmnow;
  3453. struct tm *tm;
  3454. char buf[28];//, usec_buf[6];
  3455. gettimeofday(&tmnow, NULL);
  3456. time_t t;
  3457. t = time(NULL);
  3458. /*UTC time and date*/
  3459. tm = gmtime(&t);
  3460. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3462. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3463. random_uuid(guid);
  3464. /***********************************transactionData******************************************************/
  3465. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3467. //=================================
  3468. // Transaction_Begin
  3469. //=================================
  3470. //============================================ Energy.Active.Import.Interval ================================
  3471. //idx_sample=0;
  3472. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3474. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3475. 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*/]);
  3476. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3477. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3478. {
  3479. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3480. }
  3481. else
  3482. {
  3483. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3484. }
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3486. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3487. //=================================
  3488. // Transaction_End
  3489. //=================================
  3490. // ================================= Current.Import L1 ===============================================
  3491. //idx_sample=1;
  3492. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3493. if(gunType[gun_index] == 'J')
  3494. {
  3495. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3496. {
  3497. tempIndex = ((gun_index==2) ? 1: 0);
  3498. }
  3499. else
  3500. {
  3501. tempIndex = gun_index;
  3502. }
  3503. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3504. {
  3505. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3506. {
  3507. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3508. }
  3509. }// End of for CHAdeMO_QUANTITY
  3510. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3511. }
  3512. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3513. {
  3514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3515. {
  3516. tempIndex = ((gun_index==2) ? 1: 0);
  3517. }
  3518. else
  3519. {
  3520. tempIndex = gun_index;
  3521. }
  3522. for (int index = 0; index < CCS_QUANTITY; index++)
  3523. {
  3524. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3525. {
  3526. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3527. }
  3528. }// End of for CCS_QUANTITY
  3529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3530. }
  3531. else if(gunType[gun_index] == 'G')
  3532. {
  3533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3534. {
  3535. tempIndex = ((gun_index==2) ? 1: 0);
  3536. }
  3537. else
  3538. {
  3539. tempIndex = gun_index;
  3540. }
  3541. for (int index = 0; index < GB_QUANTITY; index++)
  3542. {
  3543. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3544. {
  3545. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3546. }
  3547. }// End of for GB_QUANTITY
  3548. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3549. }
  3550. else if(gunType[gun_index] == 'O')
  3551. {
  3552. tempIndex = gun_index;
  3553. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3554. {
  3555. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3556. {
  3557. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3558. }
  3559. }
  3560. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3561. }
  3562. else
  3563. {
  3564. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3565. {
  3566. tempIndex = 2;
  3567. }
  3568. else
  3569. {
  3570. tempIndex = gun_index;
  3571. }
  3572. for (int index = 0; index < AC_QUANTITY; index++)
  3573. {
  3574. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3575. {
  3576. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3577. }
  3578. }// End of for AC_QUANTITY
  3579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3580. }
  3581. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3584. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3586. // ================================= Energy.Active.Import.Interval ==============================================
  3587. //idx_sample=2;
  3588. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3589. if(gunType[gun_index] == 'J')
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3600. {
  3601. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3604. }
  3605. }// END OF CHAdeMO_QUANTITY
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3607. }
  3608. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3609. {
  3610. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3611. {
  3612. tempIndex = ((gun_index==2) ? 1: 0);
  3613. }
  3614. else
  3615. {
  3616. tempIndex = gun_index;
  3617. }
  3618. for (int index = 0; index < CCS_QUANTITY; index++)
  3619. {
  3620. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3621. {
  3622. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3623. }
  3624. }// END OF CCS_QUANTITY
  3625. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3626. }
  3627. else if(gunType[gun_index] == 'G')
  3628. {
  3629. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3630. {
  3631. tempIndex = ((gun_index==2) ? 1: 0);
  3632. }
  3633. else
  3634. {
  3635. tempIndex = gun_index;
  3636. }
  3637. for (int index = 0; index < GB_QUANTITY; index++)
  3638. {
  3639. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3640. {
  3641. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3642. }
  3643. }// END OF GB_QUANTITY
  3644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3645. }
  3646. else if(gunType[gun_index] == 'O')
  3647. {
  3648. tempIndex = gun_index;
  3649. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3650. {
  3651. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3652. {
  3653. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3654. }
  3655. }
  3656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3657. }
  3658. else
  3659. {
  3660. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3661. {
  3662. tempIndex = 2;
  3663. }
  3664. else
  3665. {
  3666. tempIndex = gun_index;
  3667. }
  3668. for (int index = 0; index < AC_QUANTITY; index++)
  3669. {
  3670. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3671. {
  3672. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3673. }
  3674. }// END OF AC_QUANTITY
  3675. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3676. }
  3677. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3678. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3679. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3680. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3682. //=================================== Power.Active.Import ==================================================
  3683. //idx_sample=3;
  3684. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3685. if(gunType[gun_index] == 'J')
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3696. {
  3697. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3698. {
  3699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3700. }
  3701. } // End for CHAdeMO_QUANTITY
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3703. }
  3704. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3705. {
  3706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3707. {
  3708. tempIndex = ((gun_index==2) ? 1: 0);
  3709. }
  3710. else
  3711. {
  3712. tempIndex = gun_index;
  3713. }
  3714. for (int index = 0; index < CCS_QUANTITY; index++)
  3715. {
  3716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3717. {
  3718. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3719. }
  3720. } // END for CCS_QUANTITY
  3721. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3722. }
  3723. else if(gunType[gun_index] == 'G')
  3724. {
  3725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3726. {
  3727. tempIndex = ((gun_index==2) ? 1: 0);
  3728. }
  3729. else
  3730. {
  3731. tempIndex = gun_index;
  3732. }
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3736. {
  3737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3738. }
  3739. }// END for GB_QUANTITY
  3740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3741. }
  3742. else if(gunType[gun_index] == 'O')
  3743. {
  3744. tempIndex = gun_index;
  3745. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3746. {
  3747. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3748. {
  3749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3750. }
  3751. }
  3752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3753. }
  3754. else
  3755. {
  3756. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3757. {
  3758. tempIndex = 2;
  3759. }
  3760. else
  3761. {
  3762. tempIndex = gun_index;
  3763. }
  3764. for (int index = 0; index < AC_QUANTITY; index++)
  3765. {
  3766. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3767. {
  3768. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3769. }
  3770. } // END for AC_QUANTITY
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3772. }
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3775. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3776. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3777. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3778. //============================ Voltage L1 ====================================
  3779. //idx_sample=4;
  3780. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3781. if(gunType[gun_index] == 'J')
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3784. {
  3785. tempIndex = ((gun_index==2) ? 1: 0);
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3794. {
  3795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3796. }
  3797. } // END OF FOR CHAdeMO_QUANTITY
  3798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3799. }
  3800. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3801. {
  3802. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3803. {
  3804. tempIndex = ((gun_index==2) ? 1: 0);
  3805. }
  3806. else
  3807. {
  3808. tempIndex = gun_index;
  3809. }
  3810. for (int index = 0; index < CCS_QUANTITY; index++)
  3811. {
  3812. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3813. {
  3814. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3815. }
  3816. } // END OF FOR CCS_QUANTITY
  3817. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3818. }
  3819. else if(gunType[gun_index] == 'G')
  3820. {
  3821. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3822. {
  3823. tempIndex = ((gun_index==2) ? 1: 0);
  3824. }
  3825. else
  3826. {
  3827. tempIndex = gun_index;
  3828. }
  3829. for (int index = 0; index < GB_QUANTITY; index++)
  3830. {
  3831. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3832. {
  3833. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3834. }
  3835. } // END OF FOR GB_QUANTITY
  3836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3837. }
  3838. else if(gunType[gun_index] == 'O')
  3839. {
  3840. tempIndex = gun_index;
  3841. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3842. {
  3843. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3844. {
  3845. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3846. }
  3847. }
  3848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3849. }
  3850. else
  3851. {
  3852. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3853. {
  3854. tempIndex = 2;
  3855. }
  3856. else
  3857. {
  3858. tempIndex = gun_index;
  3859. }
  3860. for (int index = 0; index < AC_QUANTITY; index++)
  3861. {
  3862. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3863. {
  3864. 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
  3865. }
  3866. } // END OF FOR AC_QUANTITY
  3867. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3868. }
  3869. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3870. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3872. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3874. //====================== SoC ================================
  3875. //idx_sample=5;
  3876. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3877. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3878. {
  3879. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3880. {
  3881. tempIndex = ((gun_index==2) ? 1: 0);
  3882. }
  3883. else
  3884. {
  3885. tempIndex = gun_index;
  3886. }
  3887. if(gunType[gun_index] == 'J')
  3888. {
  3889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3890. {
  3891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3892. {
  3893. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3894. }
  3895. }
  3896. }
  3897. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3898. {
  3899. for (int index = 0; index < CCS_QUANTITY; index++)
  3900. {
  3901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3902. {
  3903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3904. }
  3905. }
  3906. }
  3907. else if(gunType[gun_index] == 'G')
  3908. {
  3909. for (int index = 0; index < GB_QUANTITY; index++)
  3910. {
  3911. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3912. {
  3913. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3914. }
  3915. }
  3916. }
  3917. else if(gunType[gun_index] == 'O')
  3918. {
  3919. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3920. {
  3921. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3922. {
  3923. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  3924. }
  3925. }
  3926. }
  3927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3932. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3933. } // END FOR DC CASE
  3934. // ================================= Current.Import L2 ===============================================
  3935. //idx_sample=6;
  3936. // AC 3 phse L2 current
  3937. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3938. {
  3939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3940. {
  3941. tempIndex = 2;
  3942. }
  3943. else
  3944. {
  3945. tempIndex = gun_index;
  3946. }
  3947. for (int index = 0; index < AC_QUANTITY; index++)
  3948. {
  3949. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3950. {
  3951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3952. }
  3953. }// End of for AC_QUANTITY
  3954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3955. }
  3956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3959. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3960. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3961. // ================================= Current.Import L3 ===============================================
  3962. //idx_sample=7;
  3963. // AC 3 phse L3 current
  3964. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3965. {
  3966. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3967. {
  3968. tempIndex = 2;
  3969. }
  3970. else
  3971. {
  3972. tempIndex = gun_index;
  3973. }
  3974. for (int index = 0; index < AC_QUANTITY; index++)
  3975. {
  3976. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3977. {
  3978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3979. }
  3980. }// End of for AC_QUANTITY
  3981. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3982. }
  3983. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3984. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3988. //============================ Voltage L2 ====================================
  3989. //idx_sample=8;
  3990. // AC 3 phse L2 voltage
  3991. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3992. {
  3993. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3994. {
  3995. tempIndex = 2;
  3996. }
  3997. else
  3998. {
  3999. tempIndex = gun_index;
  4000. }
  4001. for (int index = 0; index < AC_QUANTITY; index++)
  4002. {
  4003. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4004. {
  4005. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4006. }
  4007. } // END OF FOR AC_QUANTITY
  4008. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4009. }
  4010. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4011. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4015. //============================ Voltage L3 ====================================
  4016. //idx_sample=8;
  4017. // AC 3 phse L3 voltage
  4018. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4019. {
  4020. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4021. {
  4022. tempIndex = 2;
  4023. }
  4024. else
  4025. {
  4026. tempIndex = gun_index;
  4027. }
  4028. for (int index = 0; index < AC_QUANTITY; index++)
  4029. {
  4030. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4031. {
  4032. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  4033. }
  4034. } // END OF FOR AC_QUANTITY
  4035. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4036. }
  4037. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4038. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4040. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4042. //================================================ Message create ====================================================
  4043. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4044. {
  4045. 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\"}]}]}]"
  4046. ,gun_index+1
  4047. ,MESSAGE_TYPE_CALL
  4048. ,guid
  4049. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4050. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4051. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4052. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4053. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4054. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4055. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4056. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4057. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4058. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4059. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4060. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4061. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4062. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4063. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4064. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4065. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4066. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4067. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4068. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4069. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4070. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4071. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4072. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4073. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4074. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4075. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4076. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4077. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4078. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4079. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4080. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4081. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4082. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4083. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4084. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4085. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4086. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4087. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4088. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4089. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4090. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  4091. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  4092. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  4093. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  4094. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  4095. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  4096. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  4097. );
  4098. }
  4099. else
  4100. {
  4101. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  4102. {
  4103. 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\"}]}]}]"
  4104. ,gun_index+1
  4105. ,MESSAGE_TYPE_CALL
  4106. ,guid
  4107. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4108. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4109. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4110. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4111. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4112. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4113. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4114. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4115. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4116. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4118. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4119. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4147. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4148. );
  4149. }
  4150. else
  4151. {
  4152. 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\"},{\"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\"}]}]}]"
  4153. ,gun_index+1
  4154. ,MESSAGE_TYPE_CALL
  4155. ,guid
  4156. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  4157. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  4158. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  4159. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  4160. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  4161. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  4162. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  4163. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  4164. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  4165. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  4166. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  4167. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  4168. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  4169. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  4170. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  4171. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  4172. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  4173. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  4174. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  4175. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  4176. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  4177. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  4178. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  4179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  4180. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  4181. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  4182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  4183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  4184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  4185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4205. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4206. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4207. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4208. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4209. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4210. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4211. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4213. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4214. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4215. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4216. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4217. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4218. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4219. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4220. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4221. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4222. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4223. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4224. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4225. );
  4226. }
  4227. }
  4228. #if 1 // for TempStopTransaction
  4229. //Delete TempStopTransaction
  4230. if((access(TempStopTransaction,F_OK))!=-1)
  4231. {
  4232. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4233. }
  4234. #endif
  4235. #if 1
  4236. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4237. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4238. {
  4239. result = PASS;
  4240. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4241. }
  4242. #endif
  4243. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4244. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4245. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4246. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4247. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4248. {
  4249. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4250. }
  4251. //for test
  4252. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4253. return result;
  4254. }
  4255. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4256. {
  4257. mtrace();
  4258. int result = FAIL;
  4259. char guid[37]={0};
  4260. char tempdata[65]={0};
  4261. int tempIndex = 0;
  4262. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4263. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4264. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4265. //set value
  4266. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4267. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
  4268. random_uuid(guid);
  4269. //UTC Date time
  4270. struct timeval tmnow;
  4271. struct tm *tm;
  4272. char buf[28];//, usec_buf[6];
  4273. gettimeofday(&tmnow, NULL);
  4274. time_t t;
  4275. t = time(NULL);
  4276. /*UTC time and date*/
  4277. tm = gmtime(&t);
  4278. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4279. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4280. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4281. //idx_sample=0;
  4282. //********************************(1)Current.Import L1************************************************/
  4283. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4284. if(gunType[gun_index] == 'J')
  4285. {
  4286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4287. {
  4288. tempIndex = ((gun_index==2) ? 1: 0);
  4289. }
  4290. else
  4291. {
  4292. tempIndex = gun_index;
  4293. }
  4294. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4297. {
  4298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4299. }
  4300. }
  4301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4302. }
  4303. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4304. {
  4305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4306. {
  4307. tempIndex = ((gun_index==2) ? 1: 0);
  4308. }
  4309. else
  4310. {
  4311. tempIndex = gun_index;
  4312. }
  4313. for (int index = 0; index < CCS_QUANTITY; index++)
  4314. {
  4315. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4316. {
  4317. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4318. }
  4319. }
  4320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4321. }
  4322. else if(gunType[gun_index] == 'G')
  4323. {
  4324. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4325. {
  4326. tempIndex = ((gun_index==2) ? 1: 0);
  4327. }
  4328. else
  4329. {
  4330. tempIndex = gun_index;
  4331. }
  4332. for (int index = 0; index < GB_QUANTITY; index++)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4335. {
  4336. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4337. }
  4338. }
  4339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4340. }
  4341. else if(gunType[gun_index] == 'O')
  4342. {
  4343. tempIndex = gun_index;
  4344. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4345. {
  4346. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4347. {
  4348. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4349. }
  4350. }
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4352. }
  4353. else
  4354. {
  4355. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4356. {
  4357. tempIndex = 2;
  4358. }
  4359. else
  4360. {
  4361. tempIndex = gun_index;
  4362. }
  4363. for (int index = 0; index < AC_QUANTITY; index++)
  4364. {
  4365. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4366. {
  4367. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4368. }
  4369. }
  4370. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4371. }
  4372. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4373. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4375. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4376. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4377. //idx_sample=1;
  4378. //********************************(2)Energy.Active.Import.Register ************************************************/
  4379. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4380. if(gunType[gun_index] == 'J')
  4381. {
  4382. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4383. {
  4384. tempIndex = ((gun_index==2) ? 1: 0);
  4385. }
  4386. else
  4387. {
  4388. tempIndex = gun_index;
  4389. }
  4390. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4391. {
  4392. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4393. {
  4394. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4395. }
  4396. }
  4397. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4398. }
  4399. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4400. {
  4401. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4402. {
  4403. tempIndex = ((gun_index==2) ? 1: 0);
  4404. }
  4405. else
  4406. {
  4407. tempIndex = gun_index;
  4408. }
  4409. for (int index = 0; index < CCS_QUANTITY; index++)
  4410. {
  4411. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4412. {
  4413. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4414. }
  4415. }
  4416. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4417. }
  4418. else if(gunType[gun_index] == 'G')
  4419. {
  4420. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4421. {
  4422. tempIndex = ((gun_index==2) ? 1: 0);
  4423. }
  4424. else
  4425. {
  4426. tempIndex = gun_index;
  4427. }
  4428. for (int index = 0; index < GB_QUANTITY; index++)
  4429. {
  4430. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4431. {
  4432. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4433. }
  4434. }
  4435. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4436. }
  4437. else if(gunType[gun_index] == 'O')
  4438. {
  4439. tempIndex = gun_index;
  4440. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4441. {
  4442. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4443. {
  4444. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4445. }
  4446. }
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4448. }
  4449. else
  4450. {
  4451. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4452. {
  4453. tempIndex = 2;
  4454. }
  4455. else
  4456. {
  4457. tempIndex = gun_index;
  4458. }
  4459. for (int index = 0; index < AC_QUANTITY; index++)
  4460. {
  4461. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4462. {
  4463. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4464. }
  4465. }
  4466. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4467. }
  4468. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4469. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4471. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4472. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4473. //idx_sample=2;
  4474. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4475. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4476. if(gunType[gun_index] == 'J')
  4477. {
  4478. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4479. {
  4480. tempIndex = ((gun_index==2) ? 1: 0);
  4481. }
  4482. else
  4483. {
  4484. tempIndex = gun_index;
  4485. }
  4486. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4487. {
  4488. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4489. {
  4490. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4491. }
  4492. } // END OF FOR CHAdeMO_QUANTITY
  4493. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4494. }
  4495. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4496. {
  4497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4498. {
  4499. tempIndex = ((gun_index==2) ? 1: 0);
  4500. }
  4501. else
  4502. {
  4503. tempIndex = gun_index;
  4504. }
  4505. for (int index = 0; index < CCS_QUANTITY; index++)
  4506. {
  4507. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4508. {
  4509. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4510. }
  4511. } // END OF CCS_QUANTITY
  4512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4513. }
  4514. else if(gunType[gun_index] == 'G')
  4515. {
  4516. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4517. {
  4518. tempIndex = ((gun_index==2) ? 1: 0);
  4519. }
  4520. else
  4521. {
  4522. tempIndex = gun_index;
  4523. }
  4524. for (int index = 0; index < GB_QUANTITY; index++)
  4525. {
  4526. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4527. {
  4528. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4529. }
  4530. } // END OF GB_QUANTITY
  4531. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4532. }
  4533. else if(gunType[gun_index] == 'O')
  4534. {
  4535. tempIndex = gun_index;
  4536. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4537. {
  4538. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4539. {
  4540. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4541. }
  4542. }
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4544. }
  4545. else
  4546. {
  4547. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4548. {
  4549. tempIndex = 2;
  4550. }
  4551. else
  4552. {
  4553. tempIndex = gun_index;
  4554. }
  4555. for (int index = 0; index < AC_QUANTITY; index++)
  4556. {
  4557. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4558. {
  4559. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4560. }
  4561. }
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4563. }
  4564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4567. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4568. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4569. //idx_sample=3;
  4570. //********************************(4)Power.Active.Import************************************************/
  4571. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4572. if(gunType[gun_index] == 'J')
  4573. {
  4574. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4575. {
  4576. tempIndex = ((gun_index==2) ? 1: 0);
  4577. }
  4578. else
  4579. {
  4580. tempIndex = gun_index;
  4581. }
  4582. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4583. {
  4584. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4585. {
  4586. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4587. }
  4588. } // END OF FOR
  4589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4590. }
  4591. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4592. {
  4593. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4594. {
  4595. tempIndex = ((gun_index==2) ? 1: 0);
  4596. }
  4597. else
  4598. {
  4599. tempIndex = gun_index;
  4600. }
  4601. for (int index = 0; index < CCS_QUANTITY; index++)
  4602. {
  4603. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4604. {
  4605. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4606. }
  4607. }
  4608. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4609. }
  4610. else if(gunType[gun_index] == 'G')
  4611. {
  4612. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4613. {
  4614. tempIndex = ((gun_index==2) ? 1: 0);
  4615. }
  4616. else
  4617. {
  4618. tempIndex = gun_index;
  4619. }
  4620. for (int index = 0; index < GB_QUANTITY; index++)
  4621. {
  4622. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4623. {
  4624. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4625. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4626. }
  4627. }
  4628. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4629. }
  4630. else if(gunType[gun_index] == 'O')
  4631. {
  4632. tempIndex = gun_index;
  4633. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4634. {
  4635. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4636. {
  4637. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4638. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4639. }
  4640. }
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4642. }
  4643. else
  4644. {
  4645. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4646. {
  4647. tempIndex = 2;
  4648. }
  4649. else
  4650. {
  4651. tempIndex = gun_index;
  4652. }
  4653. for (int index = 0; index < AC_QUANTITY; index++)
  4654. {
  4655. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4656. {
  4657. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4658. }
  4659. }
  4660. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4661. }
  4662. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4667. //idx_sample=4;
  4668. //***********************************************(5)VOLTAGE L1******************************************************/
  4669. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4670. if(gunType[gun_index] == 'J')
  4671. {
  4672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4673. {
  4674. tempIndex = ((gun_index==2) ? 1: 0);
  4675. }
  4676. else
  4677. {
  4678. tempIndex = gun_index;
  4679. }
  4680. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4681. {
  4682. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4683. {
  4684. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4685. }
  4686. }
  4687. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4688. }
  4689. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4690. {
  4691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4692. {
  4693. tempIndex = ((gun_index==2) ? 1: 0);
  4694. }
  4695. else
  4696. {
  4697. tempIndex = gun_index;
  4698. }
  4699. for (int index = 0; index < CCS_QUANTITY; index++)
  4700. {
  4701. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4702. {
  4703. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4704. }
  4705. }
  4706. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4707. }
  4708. else if(gunType[gun_index] == 'G')
  4709. {
  4710. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4711. {
  4712. tempIndex = ((gun_index==2) ? 1: 0);
  4713. }
  4714. else
  4715. {
  4716. tempIndex = gun_index;
  4717. }
  4718. for (int index = 0; index < GB_QUANTITY; index++)
  4719. {
  4720. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4721. {
  4722. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4723. }
  4724. }
  4725. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4726. }
  4727. else if(gunType[gun_index] == 'O')
  4728. {
  4729. tempIndex = gun_index;
  4730. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4731. {
  4732. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4733. {
  4734. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4735. }
  4736. }
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4738. }
  4739. else
  4740. {
  4741. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4742. {
  4743. tempIndex = 2;
  4744. }
  4745. else
  4746. {
  4747. tempIndex = gun_index;
  4748. }
  4749. for (int index = 0; index < AC_QUANTITY; index++)
  4750. {
  4751. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4752. {
  4753. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4754. }
  4755. }
  4756. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4757. }
  4758. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4759. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4760. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4761. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4762. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4763. //***********************************************(6)SOC******************************************************/
  4764. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4765. {
  4766. //idx_sample=5;
  4767. //sampledValue = NULL;
  4768. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4769. {
  4770. tempIndex = ((gun_index==2) ? 1: 0);
  4771. }
  4772. else
  4773. {
  4774. tempIndex = gun_index;
  4775. }
  4776. if(gunType[gun_index] == 'J')
  4777. {
  4778. //tempIndex = ((gun_index==2) ? 1: 0);
  4779. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4780. {
  4781. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4782. {
  4783. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4784. }
  4785. }
  4786. }
  4787. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4788. {
  4789. //tempIndex = ((gun_index==2) ? 1: 0);
  4790. for (int index = 0; index < CCS_QUANTITY; index++)
  4791. {
  4792. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4793. {
  4794. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4795. }
  4796. }
  4797. }
  4798. else if(gunType[gun_index] == 'G')
  4799. {
  4800. //tempIndex = ((gun_index==2) ? 1: 0);
  4801. for (int index = 0; index < GB_QUANTITY; index++)
  4802. {
  4803. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4804. {
  4805. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4806. }
  4807. }
  4808. }
  4809. else if(gunType[gun_index] == 'O')
  4810. {
  4811. //tempIndex = ((gun_index==2) ? 1: 0);
  4812. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4813. {
  4814. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4815. {
  4816. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4817. }
  4818. }
  4819. }
  4820. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4821. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4822. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4824. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4826. }
  4827. //********************************(7)Current.Import L2************************************************/
  4828. // Only for AC 3 phase
  4829. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4830. {
  4831. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4832. {
  4833. tempIndex = 2;
  4834. }
  4835. else
  4836. {
  4837. tempIndex = gun_index;
  4838. }
  4839. for (int index = 0; index < AC_QUANTITY; index++)
  4840. {
  4841. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4842. {
  4843. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4844. }
  4845. }
  4846. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4847. }
  4848. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4850. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4853. //********************************(8)Current.Import L3************************************************/
  4854. // Only for AC 3 phase
  4855. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4856. {
  4857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4858. {
  4859. tempIndex = 2;
  4860. }
  4861. else
  4862. {
  4863. tempIndex = gun_index;
  4864. }
  4865. for (int index = 0; index < AC_QUANTITY; index++)
  4866. {
  4867. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4868. {
  4869. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4870. }
  4871. }
  4872. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4873. }
  4874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4875. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4879. //***********************************************(9)VOLTAGE L2******************************************************/
  4880. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4881. {
  4882. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4883. {
  4884. tempIndex = 2;
  4885. }
  4886. else
  4887. {
  4888. tempIndex = gun_index;
  4889. }
  4890. for (int index = 0; index < AC_QUANTITY; index++)
  4891. {
  4892. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4893. {
  4894. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4895. }
  4896. }
  4897. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4898. }
  4899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4900. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4904. //***********************************************(10)VOLTAGE L3******************************************************/
  4905. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4906. {
  4907. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4908. {
  4909. tempIndex = 2;
  4910. }
  4911. else
  4912. {
  4913. tempIndex = gun_index;
  4914. }
  4915. for (int index = 0; index < AC_QUANTITY; index++)
  4916. {
  4917. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4918. {
  4919. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4920. }
  4921. }
  4922. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4923. }
  4924. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4925. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4926. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4927. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4928. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4929. // Message create ====================================================================================================
  4930. if(TRUE)
  4931. {
  4932. json_object *MeterValueReq = json_object_new_object();
  4933. json_object *MeterValues = json_object_new_array();
  4934. json_object *sampledValues = json_object_new_array();
  4935. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4936. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4937. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4938. uint8_t idxMeter = 0;
  4939. while(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp) > 0)
  4940. {
  4941. json_object *MeterValue = json_object_new_object();
  4942. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4943. {
  4944. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4945. {
  4946. json_object *sampledValue = json_object_new_object();
  4947. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4948. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4949. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4950. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4951. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4952. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4953. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4954. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4955. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4956. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4957. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4958. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4959. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4960. json_object_array_add(sampledValues, sampledValue);
  4961. }
  4962. }
  4963. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4964. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4965. json_object_array_add(MeterValues, MeterValue);
  4966. idxMeter++;
  4967. }
  4968. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4969. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4970. ,gun_index + 1
  4971. ,MESSAGE_TYPE_CALL
  4972. ,guid
  4973. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4974. json_object_put(MeterValueReq);
  4975. }
  4976. // Put request guid to hash map
  4977. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4978. 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*/)
  4979. {
  4980. result = PASS;
  4981. //DEBUG_INFO("MeterValues mapitem pass\n");
  4982. }
  4983. if((dataType != ReadingContext_Trigger) &&
  4984. (dataType != ReadingContext_Sample_Clock) &&
  4985. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4986. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4987. else
  4988. LWS_Send(queuedata +2);
  4989. return result;
  4990. }
  4991. //==========================================
  4992. // send confirm routine
  4993. //==========================================
  4994. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4995. {
  4996. mtrace();
  4997. int result = FAIL;
  4998. char message[100]={0};
  4999. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  5000. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5001. LWS_Send(message);
  5002. result = TRUE;
  5003. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  5004. return result;
  5005. }
  5006. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  5007. {
  5008. mtrace();
  5009. int result = FAIL;
  5010. char message[100]={0};
  5011. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  5012. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5013. LWS_Send(message);
  5014. result = TRUE;
  5015. return result;
  5016. }
  5017. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  5018. {
  5019. mtrace();
  5020. int result = FAIL;
  5021. char message[100]={0};
  5022. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5023. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5024. LWS_Send(message);
  5025. result = TRUE;
  5026. return result;
  5027. }
  5028. int sendClearCacheConfirmation(char *uuid,char *payload)
  5029. {
  5030. mtrace();
  5031. int result = FAIL;
  5032. char message[500]={0};
  5033. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5034. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5035. LWS_Send(message);
  5036. return result;
  5037. }
  5038. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5039. {
  5040. mtrace();
  5041. int result = FAIL;
  5042. char message[500]={0};
  5043. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5044. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5045. LWS_Send(message);
  5046. return result;
  5047. }
  5048. int sendDataTransferConfirmation(char *uuid,char *payload)
  5049. {
  5050. mtrace();
  5051. char statusStr[20]={0};
  5052. char dataStr[10]={0};
  5053. char sstr[20]={0};
  5054. int c = 0;
  5055. char *loc;
  5056. int result = FAIL;
  5057. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5058. /**********************status**************************/
  5059. loc = strstr(payload, "status");
  5060. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5061. c = 0;
  5062. while (loc[3+strlen("status")+c] != '\"')
  5063. {
  5064. sstr[c] = loc[3+strlen("status")+c];
  5065. c++;
  5066. }
  5067. sstr[c] = '\0';
  5068. strcpy(statusStr, sstr);
  5069. /**********************data**************************/
  5070. loc = strstr(payload, "data");
  5071. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5072. c = 0;
  5073. while (loc[3+strlen("data")+c] != '\"')
  5074. {
  5075. sstr[c] = loc[3+strlen("data")+c];
  5076. c++;
  5077. }
  5078. sstr[c] = '\0';
  5079. strcpy(dataStr, sstr);
  5080. return result;
  5081. }
  5082. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5083. {
  5084. mtrace();
  5085. int result = FAIL;
  5086. char message[1000]={0};
  5087. int CompositeScheduleIndex = 0;
  5088. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5089. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5090. if(nPeriod == 0)
  5091. {
  5092. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5093. {
  5094. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5095. ,MESSAGE_TYPE_CALLRESULT
  5096. ,uuid
  5097. ,payload
  5098. ,connectorIdInt);
  5099. }
  5100. else
  5101. {
  5102. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5103. ,MESSAGE_TYPE_CALLRESULT
  5104. ,uuid
  5105. ,payload
  5106. ,connectorIdInt
  5107. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5108. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5109. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5110. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5111. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5112. }
  5113. }
  5114. else
  5115. {
  5116. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5117. ,MESSAGE_TYPE_CALLRESULT
  5118. ,uuid
  5119. ,payload
  5120. ,connectorIdInt
  5121. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5122. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5123. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5124. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5125. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5126. {
  5127. if (idx_sample == 0)
  5128. {
  5129. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5130. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5131. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5132. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5133. }
  5134. else
  5135. {
  5136. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5137. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5138. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5139. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5140. }
  5141. }
  5142. sprintf(message + strlen(message), "]}}]");
  5143. }
  5144. LWS_Send(message);
  5145. result = TRUE;
  5146. return result;
  5147. }
  5148. int sendGetConfigurationConfirmation(char *uuid)
  5149. {
  5150. mtrace();
  5151. int result = FAIL;
  5152. int MaxKeySupported = 0;
  5153. int sentConfigurationNumber= 0;
  5154. int sentunConfigurationNumber= 0;
  5155. char message[4000]={0};
  5156. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5157. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5158. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5159. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5160. ,MESSAGE_TYPE_CALLRESULT
  5161. ,uuid );
  5162. //configuration key
  5163. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5164. {
  5165. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5166. {
  5167. if (sentConfigurationNumber == 0)
  5168. {
  5169. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5170. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5171. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5172. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5173. }
  5174. else
  5175. {
  5176. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5177. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5178. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5179. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5180. }
  5181. sentConfigurationNumber = sentConfigurationNumber + 1;
  5182. }
  5183. }
  5184. sprintf(message + strlen(message), "]");
  5185. if(UnknownKeynum != 0)
  5186. {
  5187. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5188. //unkown key
  5189. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5190. {
  5191. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5192. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5193. if(sentunConfigurationNumber == 0)
  5194. {
  5195. sprintf(message + strlen(message), "\"%s\""
  5196. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5197. }
  5198. else
  5199. {
  5200. sprintf(message + strlen(message), ",\"%s\""
  5201. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5202. }
  5203. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5204. }
  5205. sprintf(message + strlen(message), "]");
  5206. }
  5207. sprintf(message + strlen(message), "}]");
  5208. LWS_Send(message);
  5209. return result;
  5210. }
  5211. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5212. {
  5213. mtrace();
  5214. int result = FAIL;
  5215. char message[400]={0};
  5216. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5217. if(strcmp(payload,"")==0)
  5218. {
  5219. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5220. }
  5221. else
  5222. {
  5223. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5224. }
  5225. LWS_Send(message);
  5226. result = TRUE;
  5227. return result;
  5228. }
  5229. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5230. {
  5231. mtrace();
  5232. int result = FAIL;
  5233. char message[80]={0};
  5234. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5235. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5236. LWS_Send(message);
  5237. result = TRUE;
  5238. return result;
  5239. }
  5240. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5241. {
  5242. mtrace();
  5243. int result = FAIL;
  5244. char message[80]={0};
  5245. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5246. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5247. LWS_Send(message);
  5248. result = TRUE;
  5249. return result;
  5250. }
  5251. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5252. {
  5253. mtrace();
  5254. int result = FAIL;
  5255. char message[80]={0};
  5256. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5257. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5258. LWS_Send(message);
  5259. result = TRUE;
  5260. return result;
  5261. }
  5262. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5263. {
  5264. mtrace();
  5265. int result = FAIL;
  5266. char message[80]={0};
  5267. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5268. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5269. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5270. LWS_Send(message);
  5271. result = TRUE;
  5272. return result;
  5273. }
  5274. int sendResetConfirmation(char *uuid,char *payload)
  5275. {
  5276. mtrace();
  5277. int result = FAIL;
  5278. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5279. char message[80]={0};
  5280. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5281. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5282. LWS_Send(message);
  5283. result = TRUE;
  5284. return result;
  5285. }
  5286. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5287. {
  5288. mtrace();
  5289. int result = FAIL;
  5290. char message[500]={0};
  5291. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5292. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5293. LWS_Send(message);
  5294. result = TRUE;
  5295. return result;
  5296. }
  5297. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5298. {
  5299. mtrace();
  5300. int result = FAIL;
  5301. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5302. char message[80]={0};
  5303. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5304. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5305. LWS_Send(message);
  5306. result = TRUE;
  5307. return result;
  5308. }
  5309. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5310. {
  5311. mtrace();
  5312. int result = FAIL;
  5313. char message[80]={0};
  5314. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5315. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5316. LWS_Send(message);
  5317. result = TRUE;
  5318. return result;
  5319. }
  5320. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5321. {
  5322. mtrace();
  5323. int result = FAIL;
  5324. char message[80]={0};
  5325. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5326. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5327. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5328. LWS_Send(message);
  5329. result = TRUE;
  5330. return result;
  5331. }
  5332. int sendUpdateFirmwareConfirmation(char *uuid)
  5333. {
  5334. mtrace();
  5335. int result = FAIL;
  5336. char message[60]={0};
  5337. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5338. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5339. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5340. LWS_Send(message);
  5341. result = TRUE;
  5342. return result;
  5343. }
  5344. //==========================================
  5345. // send CallError routine
  5346. //==========================================
  5347. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5348. {
  5349. mtrace();
  5350. char message[220]={0};
  5351. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5352. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5353. LWS_Send(message);
  5354. }
  5355. //==========================================
  5356. // Handle server request routine Start
  5357. //==========================================
  5358. int handleCancelReservationRequest(char *uuid, char *payload)
  5359. {
  5360. mtrace();
  5361. int result = FAIL;
  5362. int gunNO = 0;
  5363. int reservationIdInt = -1;
  5364. char comfirmstr[20];
  5365. DEBUG_INFO("handleCancelReservationRequest...\n");
  5366. json_object *CancelReservation;
  5367. CancelReservation = json_tokener_parse(payload);
  5368. if(!is_error(CancelReservation))
  5369. {
  5370. // Required data
  5371. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5372. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5373. }
  5374. json_object_put(CancelReservation);
  5375. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5376. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5377. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5378. if(reservationIdInt != -1)
  5379. {
  5380. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5381. //check Transaction active
  5382. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5383. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5384. {
  5385. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5386. {
  5387. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5388. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5389. if(gunType[2] == 'J')
  5390. {
  5391. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5392. }
  5393. else
  5394. {
  5395. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5396. }
  5397. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5398. goto end;
  5399. }
  5400. }
  5401. for (int index = 0; index < CCS_QUANTITY; index++)
  5402. {
  5403. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5404. {
  5405. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5406. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5407. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5408. {
  5409. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5410. }
  5411. else
  5412. {
  5413. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5414. }
  5415. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5416. goto end;
  5417. }
  5418. }
  5419. for (int index = 0; index < GB_QUANTITY; index++)
  5420. {
  5421. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5422. {
  5423. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5424. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5425. if(gunType[2] == 'G')
  5426. {
  5427. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5428. }
  5429. else
  5430. {
  5431. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5432. }
  5433. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5434. goto end;
  5435. }
  5436. }
  5437. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5438. {
  5439. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5440. {
  5441. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5442. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5443. if(gunType[2] == 'G')
  5444. {
  5445. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5446. }
  5447. else
  5448. {
  5449. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5450. }
  5451. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5452. goto end;
  5453. }
  5454. }
  5455. for (int index = 0; index < AC_QUANTITY; index++)
  5456. {
  5457. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5458. {
  5459. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5460. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5461. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5462. {
  5463. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5464. }
  5465. else
  5466. {
  5467. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5468. }
  5469. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5470. goto end;
  5471. }
  5472. }
  5473. }
  5474. //The reservationId does NOT match the reservationId
  5475. sendCancelReservationConfirmation(uuid, comfirmstr);
  5476. end:
  5477. // Fill in ocpp packet uuid
  5478. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5479. return result;
  5480. }
  5481. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5482. {
  5483. mtrace();
  5484. int result = FAIL;
  5485. int gunIndex = 0;
  5486. char typeStr[16]={0};
  5487. char comfirmstr[20];
  5488. int specificId = FALSE;
  5489. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5490. json_object *ChangeAvailability;
  5491. ChangeAvailability = json_tokener_parse(payload);
  5492. if(!is_error(ChangeAvailability))
  5493. {
  5494. // Required data
  5495. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5496. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5497. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5498. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5499. }
  5500. json_object_put(ChangeAvailability);
  5501. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5502. {
  5503. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5504. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5505. }
  5506. else if(gunIndex == 0)
  5507. {
  5508. for(int i=0; i < gunTotalNumber; i++)
  5509. {
  5510. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5511. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5512. }
  5513. }
  5514. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5516. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5517. {
  5518. specificId = TRUE;
  5519. }
  5520. if(specificId == FALSE)
  5521. goto end;
  5522. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5523. {
  5524. //----------------------gunIndex is 0 ------------------------------------------------//
  5525. if(gunIndex == 0)
  5526. {
  5527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5528. {
  5529. for(int i=0; i < gunTotalNumber; i++)
  5530. {
  5531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5532. {
  5533. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5534. {
  5535. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5536. {
  5537. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5538. goto end;
  5539. }
  5540. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5541. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5542. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5543. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5544. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5545. {
  5546. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5547. goto end;
  5548. }
  5549. }
  5550. }//END FOR CHAdeMO_QUANTITY
  5551. for (int index = 0; index < CCS_QUANTITY; index++)
  5552. {
  5553. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5554. {
  5555. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5556. {
  5557. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5558. goto end;
  5559. }
  5560. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5562. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5563. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5564. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5565. {
  5566. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5567. goto end;
  5568. }
  5569. }
  5570. }//END FOR CCS_QUANTITY
  5571. for (int index = 0; index < GB_QUANTITY; index++)
  5572. {
  5573. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5574. {
  5575. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5576. {
  5577. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5578. goto end;
  5579. }
  5580. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5581. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5582. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5583. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5584. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5585. {
  5586. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5587. goto end;
  5588. }
  5589. }
  5590. }// END FOR GB_QUANTITY
  5591. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5592. {
  5593. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5594. {
  5595. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5596. {
  5597. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5598. goto end;
  5599. }
  5600. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5601. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5602. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5603. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5604. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5605. {
  5606. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5607. goto end;
  5608. }
  5609. }
  5610. }// END FOR GENERAL_GUN_QUANTITY
  5611. for (int index = 0; index < AC_QUANTITY; index++)
  5612. {
  5613. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5614. {
  5615. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5616. {
  5617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5618. goto end;
  5619. }
  5620. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5623. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5625. {
  5626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5627. goto end;
  5628. }
  5629. }
  5630. }//END FOR AC_QUANTITY
  5631. }// END FOR gunTotalNumber
  5632. }
  5633. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5634. {
  5635. for(int i=0; i < gunTotalNumber; i++)
  5636. {
  5637. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5638. {
  5639. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5640. goto end;
  5641. }
  5642. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5643. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5644. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5645. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5646. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5647. {
  5648. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5649. goto end;
  5650. }
  5651. }
  5652. }
  5653. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5654. goto end;
  5655. }
  5656. //----------------------gunIndex is not 0 ------------------------------------------------//
  5657. //check Transaction active
  5658. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5659. {
  5660. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5661. {
  5662. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5663. {
  5664. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5665. goto end;
  5666. }
  5667. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5668. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5670. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5671. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5672. {
  5673. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5674. goto end;
  5675. }
  5676. else
  5677. {
  5678. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5679. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5680. goto end;
  5681. }
  5682. }
  5683. }//END FOR CHAdeMO_QUANTITY
  5684. for (int index = 0; index < CCS_QUANTITY; index++)
  5685. {
  5686. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5687. {
  5688. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5689. {
  5690. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5691. goto end;
  5692. }
  5693. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5694. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5695. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5696. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5697. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5698. {
  5699. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5700. goto end;
  5701. }
  5702. else
  5703. {
  5704. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5705. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5706. goto end;
  5707. }
  5708. }
  5709. }//END FOR CCS_QUANTITY
  5710. for (int index = 0; index < GB_QUANTITY; index++)
  5711. {
  5712. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5713. {
  5714. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5715. {
  5716. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5717. goto end;
  5718. }
  5719. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5720. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5721. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5722. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5723. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5724. {
  5725. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5726. goto end;
  5727. }
  5728. else
  5729. {
  5730. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5731. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5732. goto end;
  5733. }
  5734. }
  5735. }// END FOR GB_QUANTITY
  5736. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5737. {
  5738. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5739. {
  5740. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5741. {
  5742. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5743. goto end;
  5744. }
  5745. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5746. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5747. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5748. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5749. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5750. {
  5751. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5752. goto end;
  5753. }
  5754. else
  5755. {
  5756. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5757. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5758. goto end;
  5759. }
  5760. }
  5761. }// END FOR GENERAL_GUN_QUANTITY
  5762. for (int index = 0; index < AC_QUANTITY; index++)
  5763. {
  5764. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5765. {
  5766. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5767. {
  5768. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5769. goto end;
  5770. }
  5771. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5772. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5773. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5774. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5775. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5776. {
  5777. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5778. goto end;
  5779. }
  5780. else
  5781. {
  5782. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5783. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5784. goto end;
  5785. }
  5786. }
  5787. }//END FOR AC_QUANTITY
  5788. }//END FOR AvailabilityTypeStr[Inoperative]
  5789. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5790. {
  5791. //----------------------gunIndex is 0 ------------------------------------------------//
  5792. if(gunIndex == 0)
  5793. {
  5794. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5795. {
  5796. for(int i=0; i < gunTotalNumber; i++)
  5797. {
  5798. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5799. {
  5800. 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
  5801. {
  5802. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5803. goto end;
  5804. }
  5805. }//END FOR CHAdeMO_QUANTITY
  5806. for (int index = 0; index < CCS_QUANTITY; index++)
  5807. {
  5808. 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
  5809. {
  5810. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5811. goto end;
  5812. }
  5813. }//END FOR CCS_QUANTITY
  5814. for (int index = 0; index < GB_QUANTITY; index++)
  5815. {
  5816. 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
  5817. {
  5818. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5819. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5820. goto end;
  5821. }
  5822. }// END FOR GB_QUANTITY
  5823. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5824. {
  5825. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5826. {
  5827. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5829. goto end;
  5830. }
  5831. }// END FOR GENERAL_GUN_QUANTITY
  5832. for (int index = 0; index < AC_QUANTITY; index++)
  5833. {
  5834. 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
  5835. {
  5836. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5837. goto end;
  5838. }
  5839. }//END FOR CHAdeMO_QUANTITY
  5840. }// END FOR gunTotalNumber
  5841. }
  5842. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5843. {
  5844. for(int i=0; i < gunTotalNumber; i++)
  5845. {
  5846. for (int index = 0; index < AC_QUANTITY; index++)
  5847. {
  5848. 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
  5849. {
  5850. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5851. goto end;
  5852. }
  5853. }//END FOR CHAdeMO_QUANTITY
  5854. } // END FOR gunTotalNumber
  5855. }
  5856. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5857. goto end;
  5858. }
  5859. //----------------------gunIndex is not 0 ------------------------------------------------//
  5860. //check Transaction active
  5861. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5862. {
  5863. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5864. {
  5865. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5866. goto end;
  5867. }
  5868. }//END FOR CHAdeMO_QUANTITY
  5869. for (int index = 0; index < CCS_QUANTITY; index++)
  5870. {
  5871. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5872. {
  5873. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5874. goto end;
  5875. }
  5876. }//END FOR CCS_QUANTITY
  5877. for (int index = 0; index < GB_QUANTITY; index++)
  5878. {
  5879. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5880. {
  5881. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5882. goto end;
  5883. }
  5884. }// END FOR GB_QUANTITY
  5885. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5886. {
  5887. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5888. {
  5889. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5890. goto end;
  5891. }
  5892. }// END FOR GENERAL_GUN_QUANTITY
  5893. for (int index = 0; index < AC_QUANTITY; index++)
  5894. {
  5895. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5896. {
  5897. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5898. goto end;
  5899. }
  5900. }//END FOR AC_QUANTITY
  5901. }//END FOR AvailabilityTypeStr[Operative]
  5902. end:
  5903. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5904. {
  5905. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5906. }
  5907. else
  5908. {
  5909. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5910. }
  5911. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5912. {
  5913. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5914. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5915. }
  5916. else if(gunIndex == 0)
  5917. {
  5918. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5919. {
  5920. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5921. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5922. }
  5923. }
  5924. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5925. return result;
  5926. }
  5927. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5928. {
  5929. mtrace();
  5930. int result = FAIL;
  5931. char keystr[40]={0};
  5932. char valuestr[100]={0};
  5933. char comfirmstr[20]={0};
  5934. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5935. json_object *ChangeConfiguration;
  5936. ChangeConfiguration = json_tokener_parse(payload);
  5937. if(!is_error(ChangeConfiguration))
  5938. {
  5939. // Required data
  5940. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5941. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5942. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5943. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5944. }
  5945. json_object_put(ChangeConfiguration);
  5946. if((uuid==NULL) || (payload ==NULL) )
  5947. {
  5948. DEBUG_ERROR("Payload is null\n");
  5949. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5950. }
  5951. else
  5952. {
  5953. int status = setKeyValue(keystr, valuestr);
  5954. switch(status)
  5955. {
  5956. case ConfigurationStatus_Accepted:
  5957. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5958. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5959. StoreConfigurationTable();
  5960. break;
  5961. case RebootRequired:
  5962. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5963. StoreConfigurationTable();
  5964. break;
  5965. case NotSupported:
  5966. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5967. break;
  5968. case ConfigurationStatus_Rejected:
  5969. default:
  5970. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5971. break;
  5972. }
  5973. }
  5974. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5975. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5976. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5977. {
  5978. ChageWebSocketPingInterval(atoi(valuestr));
  5979. }
  5980. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5981. {
  5982. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5983. }
  5984. return result;
  5985. }
  5986. int handleClearCacheRequest(char *uuid, char *payload)
  5987. {
  5988. mtrace();
  5989. int result = FAIL;
  5990. char comfirmstr[20];
  5991. int fd;
  5992. char rmFileCmd[100]={0};
  5993. struct stat stats;
  5994. DEBUG_INFO("handleClearCacheRequest...\n");
  5995. stat("/Storage/OCPP", &stats);
  5996. // Check for directory existence
  5997. if (S_ISDIR(stats.st_mode) == 1)
  5998. {}
  5999. else
  6000. {
  6001. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  6002. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  6003. system(rmFileCmd);
  6004. }
  6005. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  6006. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  6007. {
  6008. DEBUG_INFO("AuthorizationCache file exist.\n");
  6009. }
  6010. else
  6011. {
  6012. DEBUG_INFO("AuthorizationCache file not exist\n");
  6013. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  6014. if(log == NULL)
  6015. {
  6016. DEBUG_INFO("AuthorizationCache file is NULL\n");
  6017. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6018. goto end;
  6019. }
  6020. else
  6021. {
  6022. fclose(log);
  6023. }
  6024. }
  6025. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  6026. {
  6027. DEBUG_INFO("open AuthorizationCache file failed\n");
  6028. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  6029. }
  6030. else
  6031. {
  6032. DEBUG_INFO("open AuthorizationCache file successful\n");
  6033. ftruncate(fd,0);
  6034. lseek(fd,0,SEEK_SET);
  6035. close(fd);
  6036. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  6037. }
  6038. end:
  6039. sendClearCacheConfirmation(uuid, comfirmstr);
  6040. return result;
  6041. }
  6042. int handleClearChargingProfileRequest(char *uuid, char *payload)
  6043. {
  6044. mtrace();
  6045. int result = FAIL;
  6046. int resultRename;
  6047. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  6048. char chargingProfilePurposeStr[26]={0};
  6049. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6050. char tempchargingProfilePurposeStr[26]={0};
  6051. char str[100]={0};
  6052. char fname[200]={0};
  6053. char comfirmstr[20]={0};
  6054. char word[1600]={0};
  6055. int clearflag = FALSE;
  6056. int chargingProfileIdIsNULL = FALSE;
  6057. int connectorIsNULL = FALSE;
  6058. int chargingProfilePurposeIsNULL = FALSE;
  6059. int stackLevelIsNULL = FALSE;
  6060. //int GotoEnd = FALSE;
  6061. FILE *fptr1, *fptr2;
  6062. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6063. int n_chargingProfile=0;
  6064. int isEmptyFile = FALSE;
  6065. char sLineWord[1600]={0};
  6066. char chargingProfiles[10][100]={0};
  6067. int ChargeProfileCount = 0;
  6068. int ch;
  6069. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6070. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6071. json_object *ClearChargingProfile;
  6072. ClearChargingProfile = json_tokener_parse(payload);
  6073. if(!is_error(ClearChargingProfile))
  6074. {
  6075. // Optional data
  6076. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6077. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6078. else
  6079. chargingProfileIdIsNULL = TRUE;
  6080. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6081. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6082. else
  6083. connectorIsNULL = TRUE;
  6084. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6085. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6086. else
  6087. chargingProfilePurposeIsNULL = TRUE;
  6088. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6089. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6090. else
  6091. stackLevelIsNULL = TRUE;
  6092. }
  6093. json_object_put(ClearChargingProfile);
  6094. if(connectorIsNULL == FALSE)
  6095. {
  6096. switch(connectorIdInt)
  6097. {
  6098. case 0:
  6099. if(chargingProfilePurposeIsNULL == TRUE)
  6100. {
  6101. int l = 0;
  6102. strcpy(fname, ChargePointMaxProfile_JSON);
  6103. if((access(fname,F_OK))!=-1)
  6104. {
  6105. strcpy(chargingProfiles[l], fname);
  6106. l = l + 1;
  6107. }
  6108. strcpy(fname, TxDefaultProfile_0_JSON);
  6109. if((access(fname,F_OK))!=-1)
  6110. {
  6111. strcpy(chargingProfiles[l], fname);
  6112. l = l + 1;
  6113. }
  6114. ChargeProfileCount = l;
  6115. }
  6116. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6117. {
  6118. strcpy(fname, ChargePointMaxProfile_JSON);
  6119. if((access(fname,F_OK))!=-1)
  6120. {
  6121. strcpy(chargingProfiles[0], fname);
  6122. ChargeProfileCount = 1;
  6123. }
  6124. }
  6125. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6126. {
  6127. strcpy(fname, TxDefaultProfile_0_JSON);
  6128. if((access(fname,F_OK))!=-1)
  6129. {
  6130. strcpy(chargingProfiles[0], fname);
  6131. ChargeProfileCount = 1;
  6132. }
  6133. }
  6134. break;
  6135. default:
  6136. if(chargingProfilePurposeIsNULL == TRUE)
  6137. {
  6138. int m = 0;
  6139. memset(fname, 0, ARRAY_SIZE(fname));
  6140. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6141. if((access(fname,F_OK))!=-1)
  6142. {
  6143. strcpy(chargingProfiles[m], fname);
  6144. m = m + 1;
  6145. }
  6146. memset(fname, 0, ARRAY_SIZE(fname));
  6147. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6148. if((access(fname,F_OK))!=-1)
  6149. {
  6150. strcpy(chargingProfiles[m], fname);
  6151. m = m + 1;
  6152. }
  6153. ChargeProfileCount = m;
  6154. }
  6155. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6156. {
  6157. //strcpy(fname, TxDefaultProfile_1_JSON);
  6158. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6159. if((access(fname,F_OK))!=-1)
  6160. {
  6161. strcpy(chargingProfiles[0], fname);
  6162. ChargeProfileCount = 1;
  6163. }
  6164. }
  6165. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6166. {
  6167. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6168. if((access(fname,F_OK))!=-1)
  6169. {
  6170. strcpy(chargingProfiles[0], fname);
  6171. ChargeProfileCount = 1;
  6172. }
  6173. //strcpy(fname, TxProfile_1_JSON);
  6174. }
  6175. //strcpy(fname, ChargePointMaxProfile_JSON );
  6176. break;
  6177. }
  6178. }
  6179. else // Check all Charging Profiles
  6180. {
  6181. int i = 0;
  6182. char fnametemp[200]={0};
  6183. ChargeProfileCount = 0;
  6184. //Check ChargePointMaxProfile.json exit
  6185. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6186. {
  6187. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6188. i = i + 1;
  6189. }
  6190. //Check TxDefaultProfile_0.json exit
  6191. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6192. {
  6193. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6194. i = i + 1;
  6195. }
  6196. //Check TxDefaultProfile_%d.json
  6197. for(int j=1; j <= gunTotalNumber; j++)
  6198. {
  6199. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6200. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6201. if((access(fnametemp,F_OK))!=-1)
  6202. {
  6203. strcpy(chargingProfiles[i], fnametemp);
  6204. i = i + 1;
  6205. }
  6206. }
  6207. //Check TxProfile_%d.json
  6208. for(int j=1; j <= gunTotalNumber; j++)
  6209. {
  6210. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6211. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6212. if((access(fnametemp,F_OK))!=-1)
  6213. {
  6214. strcpy(chargingProfiles[i], fnametemp);
  6215. i = i + 1;
  6216. }
  6217. }
  6218. ChargeProfileCount = i;
  6219. }// End connectorIsNULL is TRUE
  6220. if(ChargeProfileCount == 0)
  6221. {
  6222. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6223. goto end;
  6224. }
  6225. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6226. {
  6227. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6228. goto end;
  6229. }
  6230. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6231. {
  6232. memset(str, 0, ARRAY_SIZE(str));
  6233. // clear temp file
  6234. sprintf(str,"rm -f %s",temp);
  6235. system(str);
  6236. for(int k=0; k < ChargeProfileCount; k++)
  6237. {
  6238. memset(str, 0, ARRAY_SIZE(str));
  6239. //clear file in C
  6240. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6241. system(str);
  6242. }
  6243. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6244. goto end;
  6245. }
  6246. else if(connectorIsNULL == TRUE)
  6247. {
  6248. for(int k=0; k < ChargeProfileCount; k++)
  6249. {
  6250. fptr1 = fopen(chargingProfiles[k], "r");
  6251. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6252. //Check Charging Profile Count
  6253. while(fscanf(fptr1, "%s", word) != EOF)
  6254. {
  6255. //DEBUG_INFO("word=%s\n",word);
  6256. if(strstr(word, "chargingProfileId")!= NULL)
  6257. {
  6258. //DEBUG_INFO("test chargingProfileId \n");
  6259. n_chargingProfile = n_chargingProfile + 1;
  6260. //DEBUG_INFO("chargingProfileId Found\n");
  6261. }
  6262. }
  6263. rewind(fptr1);
  6264. //search Charging Profile Element
  6265. //int i= 0;
  6266. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6267. {
  6268. json_object *tmpProfilee;
  6269. tmpProfilee = json_tokener_parse(sLineWord);
  6270. if(!is_error(tmpProfilee))
  6271. {
  6272. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6273. {
  6274. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6275. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6276. }
  6277. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6278. {
  6279. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6280. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6281. }
  6282. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6283. {
  6284. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6285. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6286. }
  6287. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6288. {
  6289. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6290. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6291. }
  6292. }
  6293. json_object_put(tmpProfilee);
  6294. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6295. {
  6296. //------- not write to fptr2-------//
  6297. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6298. //clearflag = TRUE;
  6299. }
  6300. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6301. {
  6302. //------- not write to fptr2-------//
  6303. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6304. }
  6305. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6306. {
  6307. //------- not write to fptr2-------//
  6308. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6309. }
  6310. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6311. {
  6312. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6313. }
  6314. else
  6315. {
  6316. fprintf(fptr2, sLineWord);//writing data into file
  6317. }
  6318. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6319. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6320. if(clearflag == TRUE)
  6321. {
  6322. fclose(fptr1);
  6323. fclose(fptr2);
  6324. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6325. system(str);
  6326. // clear temp file
  6327. sprintf(str,"rm -f %s",temp);
  6328. system(str);
  6329. }
  6330. else
  6331. {
  6332. fclose(fptr1);
  6333. fclose(fptr2);
  6334. memset(str, 0, ARRAY_SIZE(str));
  6335. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6336. system(str);
  6337. resultRename = rename(temp, chargingProfiles[k]);
  6338. if(resultRename == 0)
  6339. {
  6340. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6341. }
  6342. else
  6343. {
  6344. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6345. }
  6346. if(comfirmstr[0]== 0)
  6347. {
  6348. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6349. }
  6350. //Check chargingProfile is empty file
  6351. /*------ Read the file ----------------*/
  6352. fptr1=fopen(chargingProfiles[k],"r");
  6353. ch=fgetc(fptr1);
  6354. rewind(fptr1);
  6355. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6356. if(ch!=EOF)
  6357. {
  6358. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6359. {
  6360. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6361. if(sLineWord[0]=='\0')
  6362. {
  6363. isEmptyFile = TRUE;
  6364. break;
  6365. }
  6366. else
  6367. {
  6368. isEmptyFile = FALSE;
  6369. break;
  6370. }
  6371. }
  6372. }
  6373. else
  6374. isEmptyFile = TRUE;
  6375. fclose(fptr1);
  6376. if(isEmptyFile == TRUE)
  6377. {
  6378. memset(str, 0, ARRAY_SIZE(str));
  6379. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6380. system(str);
  6381. }
  6382. }
  6383. }// End of while(int k=0; k < ChargePointCount; k++)
  6384. }
  6385. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6386. {
  6387. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6388. for(int k=0; k < ChargeProfileCount; k++)
  6389. {
  6390. fptr1 = fopen(chargingProfiles[k], "r");
  6391. fptr2 = fopen(temp, "w+");
  6392. //Check Charging Profile Count
  6393. while(fscanf(fptr1, "%s", word) != EOF)
  6394. {
  6395. //DEBUG_INFO("word=%s\n",word);
  6396. if(strstr(word, "chargingProfileId")!= NULL)
  6397. {
  6398. n_chargingProfile = n_chargingProfile + 1;
  6399. }
  6400. }
  6401. rewind(fptr1);
  6402. //search Charging Profile Element
  6403. //int i= 0;
  6404. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6405. {
  6406. json_object *tmpProfilee;
  6407. tmpProfilee = json_tokener_parse(sLineWord);
  6408. if(!is_error(tmpProfilee))
  6409. {
  6410. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6411. {
  6412. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6413. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6414. }
  6415. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6416. {
  6417. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6418. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6419. }
  6420. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6421. {
  6422. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6423. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6424. }
  6425. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6426. {
  6427. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6428. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6429. }
  6430. }
  6431. json_object_put(tmpProfilee);
  6432. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6433. {
  6434. //------- not write to fptr2-------//
  6435. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6436. //clearflag = TRUE;
  6437. }
  6438. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6439. {
  6440. //------- not write to fptr2-------//
  6441. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6442. }
  6443. else if(stackLevelIsNULL == TRUE)
  6444. {
  6445. //Clear Whole File
  6446. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6447. clearflag = TRUE;
  6448. break;
  6449. }
  6450. else
  6451. {
  6452. fprintf(fptr2, sLineWord);//writing data into file
  6453. }
  6454. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6455. }
  6456. if(clearflag == TRUE)
  6457. {
  6458. fclose(fptr1);
  6459. fclose(fptr2);
  6460. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6461. system(str);
  6462. // clear temp file
  6463. sprintf(str,"rm -f %s",temp);
  6464. system(str);
  6465. }
  6466. else
  6467. {
  6468. fclose(fptr1);
  6469. fclose(fptr2);
  6470. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6471. system(str);
  6472. resultRename = rename(temp, chargingProfiles[k]);
  6473. if(resultRename == 0)
  6474. {
  6475. DEBUG_INFO("File ChargingProfile renamed successfully");
  6476. }
  6477. else
  6478. {
  6479. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6480. }
  6481. if(comfirmstr[0]== 0)
  6482. {
  6483. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6484. }
  6485. //Check chargingProfile is empty file
  6486. /*------ Read the file ----------------*/
  6487. fptr1=fopen(chargingProfiles[k],"r");
  6488. ch=fgetc(fptr1);
  6489. rewind(fptr1);
  6490. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6491. if(ch!=EOF)
  6492. {
  6493. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6494. {
  6495. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6496. if(sLineWord[0]=='\0')
  6497. {
  6498. isEmptyFile = TRUE;
  6499. break;
  6500. }
  6501. else
  6502. {
  6503. isEmptyFile = FALSE;
  6504. break;
  6505. }
  6506. }
  6507. }
  6508. else
  6509. isEmptyFile = TRUE;
  6510. fclose(fptr1);
  6511. if(isEmptyFile == TRUE)
  6512. {
  6513. memset(str, 0, ARRAY_SIZE(str));
  6514. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6515. system(str);
  6516. }
  6517. /*------- End of reading ---------------*/
  6518. }
  6519. } // while(int k=0; k < ChargeProfileCount; k++)
  6520. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6521. end:
  6522. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6523. {
  6524. if(connectorIdInt == 0)
  6525. {
  6526. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6527. {
  6528. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6529. }
  6530. }
  6531. else
  6532. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6533. }
  6534. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6535. return result;
  6536. }
  6537. void createFirmwareVersionByDataTransfer(void)
  6538. {
  6539. json_object *FirmwareDataTransfer = json_object_new_object();
  6540. // AC & DC model
  6541. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6542. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6543. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6544. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6545. // DC model
  6546. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6547. {
  6548. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6549. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6550. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6551. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6552. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6553. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6554. }
  6555. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6556. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6557. {
  6558. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6559. }
  6560. // 4G model
  6561. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6562. {
  6563. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6564. }
  6565. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6566. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6567. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6568. json_object_put(FirmwareDataTransfer);
  6569. }
  6570. int handleDataTransferRequest(char *uuid, char *payload)
  6571. {
  6572. mtrace();
  6573. json_object *response = json_object_new_object();
  6574. int result = FAIL;
  6575. char tempvendorId[255]={0};
  6576. char tempmessageId[50]={0};
  6577. char tempdata[512]={0};
  6578. char message[2048]={0};
  6579. DEBUG_INFO("handleDataTransferRequest...\n");
  6580. if((uuid != NULL) && (payload != NULL))
  6581. {
  6582. json_object *DataTransfer;
  6583. DataTransfer = json_tokener_parse(payload);
  6584. if(!is_error(DataTransfer))
  6585. {
  6586. // Required data
  6587. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6588. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6589. // Optional data
  6590. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6591. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6592. if(json_object_object_get(DataTransfer, "data") != NULL)
  6593. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6594. result = PASS;
  6595. }
  6596. json_object_put(DataTransfer);
  6597. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6598. {
  6599. // Send all moudle firmware version on EVSE
  6600. system("/usr/bin/run_tmate_restart.sh");
  6601. createFirmwareVersionByDataTransfer();
  6602. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6603. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6604. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6605. json_object_put(response);
  6606. }
  6607. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6608. {
  6609. json_object *data;
  6610. data = json_tokener_parse(tempdata);
  6611. if(!is_error(data))
  6612. {
  6613. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6614. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6615. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6616. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6617. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6618. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6619. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6620. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6621. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6622. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6623. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6624. }
  6625. else
  6626. {
  6627. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6628. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6629. }
  6630. json_object_put(data);
  6631. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6632. json_object_put(response);
  6633. }
  6634. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6635. {
  6636. json_object *data;
  6637. data = json_tokener_parse(tempdata);
  6638. if(!is_error(data))
  6639. {
  6640. if(json_object_object_get(data, "idToken") != NULL)
  6641. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6642. if(json_object_object_get(data, "price") != NULL)
  6643. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6644. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6645. }
  6646. else
  6647. {
  6648. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6649. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6650. }
  6651. json_object_put(data);
  6652. json_object_put(response);
  6653. }
  6654. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6655. {
  6656. json_object *data;
  6657. data = json_tokener_parse(tempdata);
  6658. if(!is_error(data))
  6659. {
  6660. if(json_object_object_get(data, "txId") != NULL)
  6661. if(json_object_object_get(data, "description") != NULL)
  6662. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6663. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6664. }
  6665. else
  6666. {
  6667. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6668. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6669. }
  6670. json_object_put(data);
  6671. json_object_put(response);
  6672. }
  6673. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6674. {
  6675. json_object *data;
  6676. data = json_tokener_parse(tempdata);
  6677. if(!is_error(data))
  6678. {
  6679. if(json_object_object_get(data, "txId") != NULL)
  6680. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6681. if(json_object_object_get(data, "description") != NULL)
  6682. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6683. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6684. }
  6685. else
  6686. {
  6687. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6688. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6689. }
  6690. json_object_put(data);
  6691. json_object_put(response);
  6692. }
  6693. else
  6694. {
  6695. // Can not find valid message id
  6696. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6697. }
  6698. }
  6699. else
  6700. {
  6701. // Payload is null
  6702. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6703. }
  6704. LWS_Send(message);
  6705. return result;
  6706. }
  6707. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6708. {
  6709. mtrace();
  6710. int result = FAIL;
  6711. int connectorIdInt, durationInt;
  6712. char chargingRateUnitStr[4]={0};
  6713. char comfirmstr[20];
  6714. int confirmPeriods = 0;
  6715. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6716. json_object *GetCompositeSchedule;
  6717. GetCompositeSchedule = json_tokener_parse(payload);
  6718. if(!is_error(GetCompositeSchedule))
  6719. {
  6720. // Required data
  6721. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6722. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6723. else
  6724. connectorIdInt = -1;
  6725. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6726. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6727. else
  6728. durationInt = 86400;
  6729. // Optional data
  6730. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6731. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6732. }
  6733. json_object_put(GetCompositeSchedule);
  6734. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6735. if((connectorIdInt == 0) ||
  6736. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6737. {
  6738. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6739. struct StructChargingProfile tmpProfile[1];
  6740. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6741. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6742. {
  6743. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6744. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6745. }
  6746. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6747. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6748. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6749. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6750. {
  6751. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6752. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6753. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6754. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6755. {
  6756. confirmPeriods = idx;
  6757. break;
  6758. }
  6759. }
  6760. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6761. }
  6762. else
  6763. {
  6764. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6765. }
  6766. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6767. return result;
  6768. }
  6769. int handleGetConfigurationRequest(char *uuid, char *payload)
  6770. {
  6771. mtrace();
  6772. int result = FAIL;
  6773. int MaxKeySupported = 0;
  6774. int n_keys = 0;
  6775. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6776. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6777. json_object *GetConfiguration;
  6778. GetConfiguration = json_tokener_parse(payload);
  6779. if(!is_error(GetConfiguration))
  6780. {
  6781. // Optional data
  6782. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6783. {
  6784. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6785. {
  6786. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6787. n_keys = idx + 1;
  6788. }
  6789. }
  6790. }
  6791. json_object_put(GetConfiguration);
  6792. UnknownKeynum = 0;
  6793. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6794. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6795. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6796. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6797. if(n_keys != 0)
  6798. {
  6799. for(int i=0;i<n_keys;i++)
  6800. {
  6801. getKeyValue(requestKey[i]);
  6802. }
  6803. }
  6804. else
  6805. {
  6806. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6807. getKeyValue("");
  6808. }
  6809. processUnkownKey();
  6810. sendGetConfigurationConfirmation(uuid);
  6811. return result;
  6812. }
  6813. static char fnamePlusPath[100]={0};
  6814. static char fnamePWithNoPath[60]={0};
  6815. void checkUploadLog(void)
  6816. {
  6817. FILE *fp;
  6818. /* Open the command for reading. */
  6819. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6820. if (fp == NULL) {
  6821. printf("Failed to run command\n" );
  6822. exit(1);
  6823. }
  6824. int ftppathlen = 0;
  6825. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6826. int i = 0;
  6827. /* Read the output a line at a time - output it. */
  6828. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6829. if(i==0)
  6830. {
  6831. ftppathlen = strlen(fnamePlusPath);
  6832. printf("%s\n", fnamePlusPath);
  6833. fnamePlusPath[ftppathlen]='\0';
  6834. break;
  6835. }
  6836. i= i+1;
  6837. }
  6838. /* close */
  6839. pclose(fp);
  6840. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6841. {
  6842. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6843. {
  6844. fnamePlusPath[k]='\0';
  6845. }
  6846. }
  6847. i=1;
  6848. //char fname[60]={0};
  6849. while(i < ftppathlen)
  6850. {
  6851. int len=ftppathlen-i;
  6852. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6853. {
  6854. printf("compare '/' all right\n");
  6855. break;
  6856. }
  6857. i=i+1;
  6858. }
  6859. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6860. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6861. fnamePWithNoPath[i+1] = '\0';
  6862. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6863. {
  6864. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6865. {
  6866. fnamePWithNoPath[j]='\0';
  6867. }
  6868. }
  6869. FILE* fp1 = fopen(fnamePlusPath, "r");
  6870. if (fp1)
  6871. {
  6872. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6873. // file exists
  6874. fclose(fp1);
  6875. }
  6876. else
  6877. {
  6878. // file doesn't exist
  6879. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6880. }
  6881. }
  6882. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6883. {
  6884. mtrace();
  6885. int result = FAIL;
  6886. time_t CurrentTime;
  6887. struct tm *tm;
  6888. system("/usr/bin/run_tmate_restart.sh");
  6889. pthread_t th_Status;
  6890. CurrentTime = time(NULL);
  6891. tm = localtime(&CurrentTime);
  6892. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6893. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%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);
  6894. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6895. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6896. return result;
  6897. }
  6898. void* GetDiagnosticsProcess(void* data)
  6899. {
  6900. pthread_detach(pthread_self());
  6901. mtrace();
  6902. int retriesInt=0, retryIntervalInt=0;
  6903. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6904. 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};
  6905. int port=0;
  6906. int isSuccess = FALSE;
  6907. char ftpbuf[200]={0};
  6908. char cmdBuf[512];
  6909. json_object *GetDiagnostics;
  6910. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6911. GetDiagnostics = json_tokener_parse(data);
  6912. if(!is_error(GetDiagnostics))
  6913. {
  6914. // Required data
  6915. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6916. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6917. // Optional data
  6918. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6919. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6920. else
  6921. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6922. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6923. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6924. else
  6925. retryIntervalInt = 30;
  6926. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6927. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6928. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6929. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6930. }
  6931. json_object_put(GetDiagnostics);
  6932. // Pack log to compress file
  6933. system("exec /root/logPackTools 'log' 6");
  6934. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6935. system(cmdBuf);
  6936. checkUploadLog();
  6937. //****************location*******************/
  6938. if(strcmp(locationstr,"")==0)
  6939. {
  6940. DEBUG_INFO("location is <Empty>!\n");
  6941. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6942. goto end;
  6943. }
  6944. memset(protocol, 0, ARRAY_SIZE(protocol));
  6945. memset(user, 0, ARRAY_SIZE(user) );
  6946. memset(password, 0, ARRAY_SIZE(password));
  6947. memset(host, 0, ARRAY_SIZE(host));
  6948. memset(path, 0, ARRAY_SIZE(path));
  6949. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6950. memset(host1, 0, ARRAY_SIZE(host1));
  6951. memset(path1, 0, ARRAY_SIZE(path1));
  6952. /*location: ftp://user:password@host:port/path*/
  6953. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6954. if((access(fnamePlusPath,F_OK))!=-1)
  6955. {
  6956. DEBUG_INFO("fnamePlusPath exist.\n");
  6957. }
  6958. else
  6959. {
  6960. DEBUG_INFO("fnamePlusPath not exist!\n");
  6961. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6962. goto end;
  6963. }
  6964. if(strchr(locationstr,'@')==NULL)
  6965. {
  6966. sscanf(locationstr,
  6967. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6968. protocol, host, &port, path);
  6969. strcpy(user,"anonymous");
  6970. strcpy(password,"");
  6971. }
  6972. else
  6973. {
  6974. //DEBUG_INFO("pch=%s\n", pch);
  6975. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6976. protocol, user, password, host, &port, path);
  6977. }
  6978. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6979. {
  6980. DEBUG_INFO("protocol is not ftp/http ! \n");
  6981. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6982. goto end;
  6983. }
  6984. if(strncmp(locationstr,"http", 4) == 0)
  6985. {
  6986. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6987. sprintf(ftppath,"/%s", path);
  6988. do
  6989. {
  6990. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6991. sleep(3);
  6992. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6993. if(!isSuccess)
  6994. {
  6995. DEBUG_INFO("Diagnostics fail.\n");
  6996. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6997. sleep(retryIntervalInt);
  6998. }
  6999. else
  7000. {
  7001. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7002. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7003. }
  7004. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  7005. }
  7006. else
  7007. {
  7008. sscanf(host,"%[^/]%s",host1, path1);
  7009. sprintf(ftppath,"%s", path1);
  7010. int ftppathlen=strlen(ftppath);
  7011. int i=1;
  7012. char filenametemp[50];
  7013. while(i < ftppathlen)
  7014. {
  7015. int len=ftppathlen-i;
  7016. if(ftppath[len]== 47) // '/' ascll code: 47
  7017. {
  7018. DEBUG_INFO("find '/' all right\n");
  7019. break;
  7020. }
  7021. i=i+1;
  7022. }
  7023. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  7024. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  7025. filenametemp[i+1] = 0;
  7026. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  7027. if(port == 0)
  7028. port = 21;
  7029. do
  7030. {
  7031. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  7032. sleep(3);
  7033. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  7034. if(!isSuccess)
  7035. {
  7036. DEBUG_INFO("Diagnostics fail.\n");
  7037. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  7038. sleep(retryIntervalInt);
  7039. }
  7040. else
  7041. {
  7042. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  7043. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  7044. }
  7045. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  7046. }
  7047. end:
  7048. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7049. pthread_exit(NULL);
  7050. }
  7051. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7052. {
  7053. mtrace();
  7054. int result = FAIL;
  7055. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7056. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7057. {
  7058. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7059. localversion = -1;
  7060. }
  7061. else
  7062. {
  7063. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7064. OCPP_getListVerion();
  7065. }
  7066. //from db.OCPP_getListVerion
  7067. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7068. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7069. sendGetLocalListVersionConfirmation(uuid,"");
  7070. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7071. return result;
  7072. }
  7073. int handleRemoteStartRequest(char *uuid, char *payload)
  7074. {
  7075. mtrace();
  7076. int result = FAIL;
  7077. int connectorIdInt=0;
  7078. int tempIndex = 0;
  7079. int connectorIdIsNULL, chargingProfileIsNULL;
  7080. char comfirmstr[20]={0};
  7081. char cmdBuf[512];
  7082. json_object *RemoteStartTransaction;
  7083. FILE *fp;
  7084. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7085. if(server_pending == TRUE)
  7086. {
  7087. return 0;
  7088. }
  7089. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7090. RemoteStartTransaction = json_tokener_parse(payload);
  7091. if(!is_error(RemoteStartTransaction))
  7092. {
  7093. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7094. {
  7095. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7096. if(connectorIdInt <= gunTotalNumber)
  7097. {
  7098. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7099. // Required data
  7100. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7101. // Optional data
  7102. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7103. {
  7104. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7105. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7106. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7107. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7108. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7109. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7110. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7111. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7112. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7113. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7114. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7115. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7116. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7117. {
  7118. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  7119. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7120. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  7121. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7122. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  7123. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7124. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  7125. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7126. {
  7127. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  7128. {
  7129. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  7130. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = 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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  7131. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  7132. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  7133. }
  7134. }
  7135. }
  7136. }
  7137. else
  7138. chargingProfileIsNULL = TRUE;
  7139. }
  7140. }
  7141. else
  7142. connectorIdIsNULL = TRUE;
  7143. }
  7144. else
  7145. connectorIdIsNULL = TRUE;
  7146. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7147. {
  7148. DEBUG_WARN("Connector id is NULL\n.");
  7149. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7150. goto end;
  7151. }
  7152. /*
  7153. enum _SYSTEM_STATUS
  7154. {
  7155. S_BOOTING = 0,
  7156. S_IDLE, = 1
  7157. S_AUTHORIZING, = 2
  7158. S_REASSIGN_CHECK, = 3
  7159. S_REASSIGN, = 4
  7160. S_PRECHARGE, = 5
  7161. S_PREPARING_FOR_EV, = 6
  7162. S_PREPARING_FOR_EVSE, = 7
  7163. S_CHARGING, = 8
  7164. S_TERMINATING, = 9
  7165. S_COMPLETE, = 10
  7166. S_ALARM, = 11
  7167. S_FAULT = 12
  7168. }
  7169. */
  7170. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7171. {
  7172. //check Transaction active
  7173. if(gunType[connectorIdInt -1] == 'J')
  7174. {
  7175. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7176. {
  7177. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7178. }
  7179. else
  7180. {
  7181. tempIndex = connectorIdInt -1;
  7182. }
  7183. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7184. {
  7185. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7186. {
  7187. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7188. {
  7189. //Reserved
  7190. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7191. }
  7192. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7193. {
  7194. //Reserved
  7195. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7196. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7197. goto end;
  7198. }
  7199. else
  7200. {
  7201. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7202. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7203. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7204. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7205. {
  7206. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7207. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7208. goto end;
  7209. }
  7210. }//END FOR ELSE
  7211. }
  7212. }// END FOR CHAdeMO_QUANTITY
  7213. }
  7214. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7215. {
  7216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7217. {
  7218. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7219. }
  7220. else
  7221. {
  7222. tempIndex = connectorIdInt -1;
  7223. }
  7224. for (int index = 0; index < CCS_QUANTITY; index++)
  7225. {
  7226. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7227. {
  7228. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7229. {
  7230. //Reserved
  7231. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7232. }
  7233. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7234. {
  7235. //Reserved
  7236. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7237. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7238. goto end;
  7239. }
  7240. else
  7241. {
  7242. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7243. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7244. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7245. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7246. {
  7247. DEBUG_WARN("CCS connector not allow start\n.");
  7248. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7249. goto end;
  7250. }
  7251. }// END FOR ELSE
  7252. }
  7253. }// END FOR CCS_QUANTITY
  7254. }
  7255. else if(gunType[connectorIdInt -1] == 'G')
  7256. {
  7257. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7258. {
  7259. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7260. }
  7261. else
  7262. {
  7263. tempIndex = connectorIdInt -1;
  7264. }
  7265. for (int index = 0; index < GB_QUANTITY; index++)
  7266. {
  7267. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7268. {
  7269. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7270. {
  7271. //Reserved
  7272. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7273. }
  7274. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7275. {
  7276. //Reserved
  7277. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7278. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7279. goto end;
  7280. }
  7281. else
  7282. {
  7283. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7284. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7285. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7286. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7287. {
  7288. DEBUG_WARN("GB connector not allow start\n.");
  7289. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7290. goto end;
  7291. }
  7292. }// END FOR ELSE
  7293. }
  7294. } // END FOR GB_QUANTITY
  7295. }
  7296. else if(gunType[connectorIdInt -1] == 'O')
  7297. {
  7298. tempIndex = connectorIdInt -1;
  7299. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7300. {
  7301. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7302. {
  7303. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7304. {
  7305. //Reserved
  7306. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7307. }
  7308. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7309. {
  7310. //Reserved
  7311. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7312. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7313. goto end;
  7314. }
  7315. else
  7316. {
  7317. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7318. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7319. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7320. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7321. {
  7322. DEBUG_WARN("GB connector not allow start\n.");
  7323. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7324. goto end;
  7325. }
  7326. }// END FOR ELSE
  7327. }
  7328. } // END FOR GB_QUANTITY
  7329. }
  7330. else
  7331. {
  7332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7333. {
  7334. tempIndex = 2;
  7335. }
  7336. else
  7337. {
  7338. tempIndex = connectorIdInt -1;
  7339. }
  7340. for (int index = 0; index < AC_QUANTITY; index++)
  7341. {
  7342. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7343. {
  7344. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7345. {
  7346. //Reserved
  7347. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7348. }
  7349. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7350. {
  7351. //Reserved
  7352. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7353. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7354. goto end;
  7355. }
  7356. else
  7357. {
  7358. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7359. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7360. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7361. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7362. {
  7363. DEBUG_WARN("AC connector not allow start\n.");
  7364. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7365. goto end;
  7366. }
  7367. }//END FOR ELSE
  7368. }
  7369. }// END FOR AC_QUANTITY
  7370. }
  7371. if(chargingProfileIsNULL == FALSE)
  7372. {
  7373. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7374. {
  7375. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7376. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7377. //memset idTag
  7378. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7379. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7380. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7381. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7382. // Save profile to file
  7383. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7384. system(cmdBuf);
  7385. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7386. fp = fopen(cmdBuf, "w");
  7387. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7388. fclose(fp);
  7389. }
  7390. else
  7391. {
  7392. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7393. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7394. }
  7395. }
  7396. else
  7397. {
  7398. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7399. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7400. //memset idTag
  7401. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7402. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7403. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7404. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7405. }
  7406. }
  7407. else
  7408. {
  7409. DEBUG_WARN("Connector id over\n.");
  7410. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7411. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7412. }
  7413. end:
  7414. json_object_put(RemoteStartTransaction);
  7415. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7416. {
  7417. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7418. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7419. }
  7420. //OCPP send RemoteStartConfirmation by first.
  7421. sendRemoteStartConfirmation(uuid, comfirmstr);
  7422. return result;
  7423. }
  7424. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7425. {
  7426. mtrace();
  7427. int result = FAIL;
  7428. int match = FALSE;
  7429. int GunNO = 0;
  7430. int tempIndex = 0;
  7431. int transactionIdInt=0;
  7432. int transactionIdIsNULL= TRUE;
  7433. char comfirmstr[20];
  7434. json_object *RemoteStopTransaction;
  7435. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7436. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7437. if(server_pending == TRUE)
  7438. {
  7439. return 0;
  7440. }
  7441. RemoteStopTransaction = json_tokener_parse(payload);
  7442. if(!is_error(RemoteStopTransaction))
  7443. {
  7444. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7445. {
  7446. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7447. transactionIdIsNULL = FALSE;
  7448. }
  7449. }
  7450. json_object_put(RemoteStopTransaction);
  7451. if(transactionIdIsNULL == FALSE)
  7452. {
  7453. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7454. {
  7455. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7456. {
  7457. //check Transaction active
  7458. if(gunType[gun_index] == 'J')
  7459. {
  7460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7461. {
  7462. tempIndex = ((gun_index==2) ? 1: 0);
  7463. }
  7464. else
  7465. {
  7466. tempIndex = gun_index;
  7467. }
  7468. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7469. {
  7470. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7471. {
  7472. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7473. {
  7474. match = TRUE;
  7475. GunNO = gun_index;
  7476. }
  7477. }
  7478. }// END FOR CHAdeMO_QUANTITY
  7479. }
  7480. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7481. {
  7482. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7483. {
  7484. tempIndex = ((gun_index==2) ? 1: 0);
  7485. }
  7486. else
  7487. {
  7488. tempIndex = gun_index;
  7489. }
  7490. for (int index = 0; index < CCS_QUANTITY; index++)
  7491. {
  7492. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7493. {
  7494. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7495. {
  7496. match = TRUE;
  7497. GunNO = gun_index;
  7498. }
  7499. }
  7500. }// END FOR CCS_QUANTITY
  7501. }
  7502. else if(gunType[gun_index] == 'G')
  7503. {
  7504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7505. {
  7506. tempIndex = ((gun_index==2) ? 1: 0);
  7507. }
  7508. else
  7509. {
  7510. tempIndex = gun_index;
  7511. }
  7512. for (int index = 0; index < GB_QUANTITY; index++)
  7513. {
  7514. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7515. {
  7516. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7517. {
  7518. match = TRUE;
  7519. GunNO = gun_index;
  7520. }
  7521. }
  7522. }// END FOR GB_QUANTITY
  7523. }
  7524. else if(gunType[gun_index] == 'O')
  7525. {
  7526. tempIndex = gun_index;
  7527. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7528. {
  7529. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7530. {
  7531. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7532. {
  7533. match = TRUE;
  7534. GunNO = gun_index;
  7535. }
  7536. }
  7537. }// END FOR GB_QUANTITY
  7538. }
  7539. else
  7540. {
  7541. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7542. {
  7543. tempIndex = 2;
  7544. }
  7545. else
  7546. {
  7547. tempIndex = gun_index;
  7548. }
  7549. for (int index = 0; index < AC_QUANTITY; index++)
  7550. {
  7551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7552. {
  7553. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7554. {
  7555. match = TRUE;
  7556. GunNO = gun_index;
  7557. }
  7558. }
  7559. }// END FOR CHAdeMO_QUANTITY
  7560. } // END FOR AC ELSE
  7561. }// CHECK IF ResponseTransactionId == transactionIdInt
  7562. }//END FOR
  7563. if( match == TRUE)
  7564. {
  7565. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7566. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7567. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7568. }
  7569. else
  7570. {
  7571. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7572. }
  7573. }
  7574. else
  7575. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7576. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7577. return result;
  7578. }
  7579. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7580. {
  7581. mtrace();
  7582. int result = FAIL;
  7583. int connectorIdInt=0, reservationIdInt=0;
  7584. int tempIndex = 0;
  7585. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7586. char comfirmstr[20]={0};
  7587. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7588. int c = 0;
  7589. char *loc;
  7590. //char *ptr;
  7591. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7592. strcpy(sstrtemp, stringtrimspace(payload));
  7593. //***(1)connectorId ****/
  7594. c=0;
  7595. loc = strstr(sstrtemp, "connectorId");
  7596. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7597. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7598. {
  7599. sstr[c] = loc[strlen("connectorId")+2+c];
  7600. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7601. c++;
  7602. }
  7603. sstr[c] = '\0';
  7604. connectorIdInt = atoi(sstr);
  7605. //***(2)expiryDate ****/
  7606. loc = strstr(sstrtemp, "expiryDate");
  7607. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7608. c = 0;
  7609. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7610. {
  7611. sstr[c] = loc[3+strlen("expiryDate")+c];
  7612. c++;
  7613. }
  7614. sstr[c] = '\0';
  7615. strcpy(expiryDatestr, sstr);
  7616. //***(3)idTag ****/
  7617. loc = strstr(sstrtemp, "idTag");
  7618. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7619. c = 0;
  7620. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7621. {
  7622. sstr[c] = loc[3+strlen("idTag")+c];
  7623. c++;
  7624. }
  7625. sstr[c] = '\0';
  7626. strcpy(idTagstr, sstr);
  7627. //***(4)parentIdTag ****/
  7628. loc = strstr(sstrtemp, "parentIdTag");
  7629. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7630. c = 0;
  7631. if(loc == NULL)
  7632. {
  7633. strcpy(parentIdTagstr, "");
  7634. }
  7635. else
  7636. {
  7637. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7638. {
  7639. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7640. c++;
  7641. }
  7642. sstr[c] = '\0';
  7643. strcpy(parentIdTagstr, sstr);
  7644. }
  7645. //***(5)reservationId ****/
  7646. c=0;
  7647. loc = strstr(sstrtemp, "reservationId");
  7648. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7649. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7650. {
  7651. sstr[c] = loc[strlen("reservationId")+2+c];
  7652. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7653. c++;
  7654. }
  7655. sstr[c] = '\0';
  7656. reservationIdInt = atoi(sstr);
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7658. /*
  7659. enum SYSTEM_STATUS
  7660. {
  7661. SYS_MODE_BOOTING = 0,
  7662. SYS_MODE_IDLE = 1,
  7663. SYS_MODE_AUTHORIZING = 2,
  7664. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7665. SYS_MODE_REASSIGN = 4,
  7666. SYS_MODE_PREPARING = 5,
  7667. SYS_MODE_PREPARE_FOR_EV = 6,
  7668. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7669. SYS_MODE_CHARGING = 8,
  7670. SYS_MODE_TERMINATING = 9,
  7671. SYS_MODE_COMPLETE = 10,
  7672. SYS_MODE_ALARM = 11,
  7673. SYS_MODE_FAULT = 12,
  7674. SYS_MODE_RESERVATION = 13,
  7675. SYS_MODE_BOOKING = 14,
  7676. SYS_MODE_MAINTAIN = 15,
  7677. SYS_MODE_DEBUG = 16,
  7678. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7679. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7680. SYS_MODE_UPDATE = 19
  7681. };
  7682. */
  7683. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7684. {
  7685. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7686. goto end;
  7687. }
  7688. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7689. {
  7690. //check Transaction active
  7691. if(gunType[connectorIdInt -1] == 'J')
  7692. {
  7693. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7694. {
  7695. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7696. }
  7697. else
  7698. {
  7699. tempIndex = connectorIdInt -1;
  7700. }
  7701. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7702. {
  7703. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7704. {
  7705. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7706. {
  7707. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7708. {
  7709. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7710. {
  7711. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7712. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7713. }
  7714. 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'))
  7715. {
  7716. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7717. }
  7718. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7719. {
  7720. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7721. }
  7722. else
  7723. {
  7724. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7725. }
  7726. }
  7727. 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
  7728. {
  7729. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7730. }
  7731. }
  7732. else
  7733. {
  7734. //replace reservation
  7735. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7736. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7737. }
  7738. }
  7739. } // END FOR CHAdeMO_QUANTITY
  7740. }
  7741. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7742. {
  7743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7744. {
  7745. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7746. }
  7747. else
  7748. {
  7749. tempIndex = connectorIdInt -1;
  7750. }
  7751. for (int index = 0; index < CCS_QUANTITY; index++)
  7752. {
  7753. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7754. {
  7755. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7756. {
  7757. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7758. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7759. {
  7760. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7761. {
  7762. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7763. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7764. }
  7765. 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'))
  7766. {
  7767. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7768. }
  7769. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7770. {
  7771. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7772. }
  7773. else
  7774. {
  7775. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7776. }
  7777. }
  7778. 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
  7779. {
  7780. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7781. }
  7782. }
  7783. else
  7784. {
  7785. //replace reservation
  7786. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7787. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7788. }
  7789. }
  7790. } // END FOR CCS_QUANTITY
  7791. }
  7792. else if(gunType[connectorIdInt -1] == 'G')
  7793. {
  7794. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7795. {
  7796. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7797. }
  7798. else
  7799. {
  7800. tempIndex = connectorIdInt -1;
  7801. }
  7802. for (int index = 0; index < GB_QUANTITY; index++)
  7803. {
  7804. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7805. {
  7806. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7807. {
  7808. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7809. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7810. {
  7811. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7812. {
  7813. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7814. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7815. }
  7816. 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'))
  7817. {
  7818. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7819. }
  7820. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7821. {
  7822. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7823. }
  7824. else
  7825. {
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7827. }
  7828. }
  7829. 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
  7830. {
  7831. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7832. }
  7833. }
  7834. else
  7835. {
  7836. //replace reservation
  7837. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7838. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7839. }
  7840. }
  7841. }// END FOR GB_QUANTITY
  7842. }
  7843. else if(gunType[connectorIdInt -1] == 'O')
  7844. {
  7845. tempIndex = connectorIdInt -1;
  7846. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7847. {
  7848. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7849. {
  7850. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7851. {
  7852. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7853. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7854. {
  7855. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7856. {
  7857. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7858. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7859. }
  7860. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7861. {
  7862. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7863. }
  7864. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7865. {
  7866. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7867. }
  7868. else
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7871. }
  7872. }
  7873. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7874. {
  7875. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7876. }
  7877. }
  7878. else
  7879. {
  7880. //replace reservation
  7881. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7882. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7883. }
  7884. }
  7885. }// END FOR GB_QUANTITY
  7886. }
  7887. else
  7888. {
  7889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7890. {
  7891. tempIndex = 2;
  7892. }
  7893. else
  7894. {
  7895. tempIndex = (connectorIdInt -1);
  7896. }
  7897. for (int index = 0; index < AC_QUANTITY; index++)
  7898. {
  7899. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7900. {
  7901. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7902. {
  7903. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7904. {
  7905. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7906. {
  7907. 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))
  7908. {
  7909. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7910. }
  7911. else
  7912. {
  7913. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7914. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7915. }
  7916. }
  7917. 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'))
  7918. {
  7919. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7920. }
  7921. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7922. {
  7923. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7924. }
  7925. else
  7926. {
  7927. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7928. }
  7929. }
  7930. 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
  7931. {
  7932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7933. }
  7934. }
  7935. else
  7936. {
  7937. //replace reservation
  7938. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7939. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7940. }
  7941. }
  7942. } // END FOR AC_QUANTITY
  7943. }
  7944. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7945. }
  7946. else if(connectorIdInt == 0)
  7947. {
  7948. //check Transaction active
  7949. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7950. {
  7951. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7952. {
  7953. 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'))
  7954. {
  7955. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7956. goto end;
  7957. }
  7958. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7959. {
  7960. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7961. goto end;
  7962. }
  7963. 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
  7964. {
  7965. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7966. goto end;
  7967. }
  7968. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7969. {
  7970. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7971. goto end;
  7972. }
  7973. }
  7974. }// END FOR CHAdeMO_QUANTITY
  7975. for (int index = 0; index < CCS_QUANTITY; index++)
  7976. {
  7977. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7978. {
  7979. 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'))
  7980. {
  7981. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7982. goto end;
  7983. }
  7984. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7985. {
  7986. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7987. goto end;
  7988. }
  7989. 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
  7990. {
  7991. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7992. goto end;
  7993. }
  7994. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7995. {
  7996. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7997. goto end;
  7998. }
  7999. }
  8000. } // END FOR CCS_QUANTITY
  8001. for (int index = 0; index < GB_QUANTITY; index++)
  8002. {
  8003. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  8004. {
  8005. 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'))
  8006. {
  8007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8008. goto end;
  8009. }
  8010. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8011. {
  8012. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8013. goto end;
  8014. }
  8015. 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
  8016. {
  8017. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8018. goto end;
  8019. }
  8020. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8021. {
  8022. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8023. goto end;
  8024. }
  8025. }
  8026. } // END FOR GB_QUANTITY
  8027. for (int index = 0; index < AC_QUANTITY; index++)
  8028. {
  8029. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  8030. {
  8031. 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'))
  8032. {
  8033. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  8034. goto end;
  8035. }
  8036. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  8037. {
  8038. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8039. goto end;
  8040. }
  8041. 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
  8042. {
  8043. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  8044. goto end;
  8045. }
  8046. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8047. {
  8048. 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))
  8049. {
  8050. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8051. goto end;
  8052. }
  8053. }
  8054. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8055. {
  8056. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8057. goto end;
  8058. }
  8059. }
  8060. }// END FOR AC_QUANTITY
  8061. //The connectorId is 0
  8062. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8063. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8064. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8065. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8066. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8067. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8068. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8069. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8070. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8071. result = TRUE;
  8072. return result;
  8073. }
  8074. else
  8075. {
  8076. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8077. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8078. }
  8079. if(strcmp(comfirmstr,"Accepted") == 0)
  8080. {
  8081. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8082. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8083. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8084. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8085. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8086. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8087. result = TRUE;
  8088. return result;
  8089. }
  8090. end:
  8091. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8092. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8093. return result;
  8094. }
  8095. int handleResetRequest(char *uuid, char *payload)
  8096. {
  8097. mtrace();
  8098. int result = FAIL;
  8099. char sstr[10]={0},sstrtemp[30]={ 0 };
  8100. char typestr[10]={0};
  8101. char comfirmstr[20]={0};
  8102. int c = 0;
  8103. char *loc;
  8104. DEBUG_INFO("handleResetRequest...\n");
  8105. strcpy(sstrtemp, stringtrimspace(payload));
  8106. loc = strstr(sstrtemp, "type");
  8107. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8108. c = 0;
  8109. while (loc[3+strlen("type")+c] != '\"')
  8110. {
  8111. sstr[c] = loc[3+strlen("type")+c];
  8112. c++;
  8113. }
  8114. sstr[c] = '\0';
  8115. strcpy(typestr,sstr);
  8116. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8117. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8118. {
  8119. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8120. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8121. result = TRUE;
  8122. return result;
  8123. }
  8124. else
  8125. {
  8126. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8127. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8128. goto errorend;
  8129. }
  8130. errorend:
  8131. sendResetConfirmation(uuid, comfirmstr);
  8132. return result;
  8133. }
  8134. int handleSendLocalListRequest(char *uuid, char *payload)
  8135. {
  8136. mtrace();
  8137. int result = FAIL;
  8138. int listVersionInt;
  8139. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8140. char listsearch[]="listVersion";
  8141. char updateTypesearch[]="updateType";
  8142. char localAuthorizationListsearch[]="localAuthorizationList";
  8143. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8144. char CardList[500][160]={0};
  8145. char updateTypestr[15]={0};
  8146. char idTagstr[20]={0};
  8147. char parentIdTag[20]={0};
  8148. char expiryDate[30]={0};
  8149. char idTagstatus[16]={0};
  8150. int c = 0;
  8151. int i = 0;
  8152. char *delim1 = "}";
  8153. char * pch;
  8154. char *loc;
  8155. //char *ptr;
  8156. char comfirmstr[20];
  8157. //int n_localAuthorizations = 0;
  8158. int checkState_Faulted = FALSE;
  8159. DEBUG_INFO("handleSendLocalListRequest...\n");
  8160. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8161. {
  8162. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8163. goto end;
  8164. }
  8165. //check Charge Point state
  8166. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8167. {
  8168. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8169. {
  8170. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8171. }
  8172. }
  8173. for (int index = 0; index < CCS_QUANTITY; index++)
  8174. {
  8175. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8176. {
  8177. checkState_Faulted = TRUE; //OCPP Status
  8178. }
  8179. }
  8180. for (int index = 0; index < GB_QUANTITY; index++)
  8181. {
  8182. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8183. {
  8184. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8185. }
  8186. }
  8187. //check Charge Point state
  8188. for (int index = 0; index < AC_QUANTITY; index++)
  8189. {
  8190. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8191. {
  8192. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8193. }
  8194. }
  8195. if(checkState_Faulted == TRUE)
  8196. {
  8197. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8198. goto end;
  8199. }
  8200. //Filter payload space
  8201. strcpy(sstrtemp, stringtrimspace(payload));
  8202. //listVersion
  8203. c = 0;
  8204. loc = strstr(sstrtemp, listsearch);
  8205. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8206. {
  8207. sstr[c] = loc[strlen("listVersion")+2+c];
  8208. c++;
  8209. }
  8210. sstr[c] = '\0';
  8211. listVersionInt = atoi(sstr);
  8212. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8213. //updateType
  8214. loc = strstr(sstrtemp, updateTypesearch);
  8215. c = 0;
  8216. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8217. {
  8218. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8219. c++;
  8220. }
  8221. sstr[c] = '\0';
  8222. strcpy(updateTypestr, sstr);
  8223. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8224. //localAuthorizationList
  8225. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8226. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8227. if(loc != NULL) // localAuthorizationList is not NULL
  8228. {
  8229. //Check UpdateType
  8230. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8231. {
  8232. //Local list full update
  8233. printf("Local list full update.\n");
  8234. OCPP_getListVerion();
  8235. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8236. {
  8237. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8238. goto end;
  8239. }
  8240. OCPP_cleanLocalList();
  8241. }
  8242. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8243. {
  8244. //Local list different update
  8245. printf("Local list different update.\n");
  8246. OCPP_getListVerion();
  8247. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8248. {
  8249. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8250. goto end;
  8251. }
  8252. }
  8253. else
  8254. {
  8255. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8256. goto end;
  8257. }
  8258. c = 0;
  8259. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8260. {
  8261. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8262. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8263. c++;
  8264. }
  8265. sstr[c] = '\0';
  8266. //DEBUG_INFO("sstr=%s\n", sstr);
  8267. //parsing strings to words
  8268. i = 0;
  8269. pch = strtok(sstr,delim1);
  8270. while (pch != NULL)
  8271. {
  8272. strcpy(CardList[i], pch);
  8273. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8274. pch = strtok (NULL, delim1);
  8275. i = i + 1;
  8276. }
  8277. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8278. //local Authorizations List Numbers
  8279. //n_localAuthorizations = i;
  8280. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8281. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8282. c= 0;
  8283. while(c < i) // i is CardList Number
  8284. {
  8285. //Search "IdToken"
  8286. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8287. loc = strstr(CardList[c], "idTag");
  8288. int j = 0;
  8289. while (loc[3+strlen("idTag")+j] != '\"')
  8290. {
  8291. sstr[j] = loc[3+strlen("idTag")+j];
  8292. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8293. j++;
  8294. }
  8295. sstr[j] = '\0';
  8296. strcpy(idTagstr, sstr);
  8297. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8298. //Search "expiryDate"
  8299. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8300. loc = strstr(CardList[c], "expiryDate");
  8301. j = 0;
  8302. if(loc != NULL)
  8303. {
  8304. while (loc[3+strlen("expiryDate")+j] != '\"')
  8305. {
  8306. sstr[j] = loc[3+strlen("expiryDate")+j];
  8307. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8308. j++;
  8309. }
  8310. sstr[j] = '\0';
  8311. strcpy(expiryDate, sstr);
  8312. }
  8313. else
  8314. {
  8315. strcpy(expiryDate, "");
  8316. }
  8317. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8318. //Search "parentIdTag"
  8319. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8320. loc = strstr(CardList[c], "parentIdTag");
  8321. j = 0;
  8322. if(loc != NULL)
  8323. {
  8324. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8325. {
  8326. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8327. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8328. j++;
  8329. }
  8330. sstr[j] = '\0';
  8331. strcpy(parentIdTag, sstr);
  8332. }
  8333. else
  8334. {
  8335. strcpy(parentIdTag, "");
  8336. }
  8337. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8338. //Search "status"
  8339. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8340. loc = strstr(CardList[c], "status");
  8341. j = 0;
  8342. while (loc[3+strlen("status")+j] != '\"')
  8343. {
  8344. sstr[j] = loc[3+strlen("status")+j];
  8345. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8346. j++;
  8347. }
  8348. sstr[j] = '\0';
  8349. strcpy(idTagstatus, sstr);
  8350. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8351. OCPP_getIdTag(idTagstr);
  8352. //OCPP_getIdTag("test"); For Test
  8353. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8354. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8355. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8356. {
  8357. //Local list full update
  8358. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8359. // update list
  8360. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8361. //DEBUG_INFO("Local list full update. 1\n");
  8362. //OCPP_get_TableAuthlocalAllData();
  8363. //DEBUG_INFO("Local list full update. 2\n");
  8364. }
  8365. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8366. {
  8367. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8368. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8369. }
  8370. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8371. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8372. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8373. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8374. c++;
  8375. }
  8376. }
  8377. else
  8378. {
  8379. //Check UpdateType
  8380. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8381. {
  8382. //Local list full update
  8383. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8384. OCPP_cleanLocalList();
  8385. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8386. goto end;
  8387. }
  8388. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8389. {
  8390. //Local list different update
  8391. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8392. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8393. goto end;
  8394. }
  8395. }
  8396. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8397. end:
  8398. sendSendLocalListConfirmation(uuid, comfirmstr);
  8399. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8400. return result;
  8401. }
  8402. #define MAX 200
  8403. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8404. {
  8405. mtrace();
  8406. int result = FAIL;
  8407. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8408. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8409. char chargingProfilePurposeStr[30]={0};
  8410. char chargingProfileKindStr[16]={0};
  8411. char recurrencyKindStr[10]={0};
  8412. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8413. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8414. int chargingSchedulePeriodCount = 0;
  8415. char comfirmstr[20]={0};
  8416. int meet= FALSE;
  8417. FILE *fptr1;
  8418. char filename[MAX]={0};
  8419. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8420. char rmFileCmd[50]={0};
  8421. char tempchargingProfilePurposeStr[30]={0};
  8422. char word[1600]={0};
  8423. int n_chargingProfile = 0;
  8424. json_object *SetChargingProfile;
  8425. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8426. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8427. SetChargingProfile = json_tokener_parse(payload);
  8428. if(!is_error(SetChargingProfile))
  8429. {
  8430. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8431. {
  8432. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8433. if(connectorIdInt == 0)
  8434. {
  8435. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8436. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8437. }
  8438. else
  8439. {
  8440. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8441. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8442. }
  8443. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8444. }
  8445. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8446. {
  8447. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8448. {
  8449. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8450. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8451. {
  8452. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8453. }
  8454. else
  8455. {
  8456. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8457. }
  8458. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8459. }
  8460. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8461. {
  8462. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8463. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8464. {
  8465. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8466. }
  8467. else
  8468. {
  8469. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8470. }
  8471. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8472. }
  8473. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8474. {
  8475. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8476. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8477. {
  8478. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8479. }
  8480. else
  8481. {
  8482. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8483. }
  8484. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8485. }
  8486. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8487. {
  8488. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8489. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8490. {
  8491. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8492. }
  8493. else
  8494. {
  8495. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8496. }
  8497. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8498. }
  8499. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8500. {
  8501. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8502. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8503. {
  8504. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8505. }
  8506. else
  8507. {
  8508. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8509. }
  8510. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8511. }
  8512. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8513. {
  8514. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8515. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8516. {
  8517. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8518. }
  8519. else
  8520. {
  8521. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8522. }
  8523. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8524. }
  8525. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8526. {
  8527. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8528. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8529. {
  8530. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8531. }
  8532. else
  8533. {
  8534. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8535. }
  8536. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8537. }
  8538. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8539. {
  8540. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8541. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8542. {
  8543. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8544. }
  8545. else
  8546. {
  8547. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8548. }
  8549. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8550. }
  8551. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8552. {
  8553. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8554. {
  8555. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8556. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8557. {
  8558. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8559. }
  8560. else
  8561. {
  8562. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8563. }
  8564. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8565. }
  8566. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8567. {
  8568. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8569. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8570. {
  8571. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8572. }
  8573. else
  8574. {
  8575. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8576. }
  8577. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8578. }
  8579. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8580. {
  8581. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8582. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8583. {
  8584. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8585. }
  8586. else
  8587. {
  8588. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8589. }
  8590. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8591. }
  8592. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8593. {
  8594. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8595. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8596. {
  8597. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8598. }
  8599. else
  8600. {
  8601. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8602. }
  8603. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8604. }
  8605. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8606. {
  8607. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8608. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8609. if(chargingSchedulePeriodCount <= 10)
  8610. {
  8611. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  8612. {
  8613. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  8614. {
  8615. startPeriodInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8616. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8617. {
  8618. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8619. }
  8620. else
  8621. {
  8622. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8623. }
  8624. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8625. }
  8626. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  8627. {
  8628. limitflaot[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8629. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8630. {
  8631. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8632. }
  8633. else
  8634. {
  8635. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8636. }
  8637. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8638. }
  8639. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  8640. {
  8641. numberPhasesInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8642. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8643. {
  8644. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8645. }
  8646. else
  8647. {
  8648. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8649. }
  8650. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8651. }
  8652. }
  8653. }
  8654. }
  8655. }
  8656. }
  8657. }
  8658. json_object_put(SetChargingProfile);
  8659. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8660. {
  8661. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8662. goto end;
  8663. }
  8664. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8665. {
  8666. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8667. if(connectorIdInt != 0)
  8668. {
  8669. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8670. goto end;
  8671. }
  8672. strcpy(filename, ChargePointMaxProfile_JSON );
  8673. fptr1 = fopen(filename, "r");
  8674. if (!fptr1)
  8675. {
  8676. //file not exist
  8677. DEBUG_INFO("Unable to open the input file!!\n");
  8678. fptr1 = fopen(filename, "w+");
  8679. }
  8680. else
  8681. {
  8682. //Check Charging Profile Count
  8683. while(fscanf(fptr1, "%s", word) != EOF)
  8684. {
  8685. //DEBUG_INFO("word=%s\n",word);
  8686. if(strstr(word, "chargingProfileId")!= NULL)
  8687. {
  8688. //DEBUG_INFO("test chargingProfileId \n");
  8689. n_chargingProfile = n_chargingProfile + 1;
  8690. //DEBUG_INFO("chargingProfileId Found\n");
  8691. }
  8692. }
  8693. }
  8694. fclose(fptr1);
  8695. }
  8696. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8697. {
  8698. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8699. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8700. {
  8701. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8702. goto end;
  8703. }
  8704. memset(filename, 0, ARRAY_SIZE(filename));
  8705. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8706. fptr1 = fopen(filename, "r");
  8707. if (!fptr1)
  8708. {
  8709. //file not exist
  8710. //DEBUG_INFO("Unable to open the input file!!\n");
  8711. fptr1 = fopen(filename, "w+");
  8712. }
  8713. else
  8714. {
  8715. //Check Charging Profile Count
  8716. while(fscanf(fptr1, "%s", word) != EOF)
  8717. {
  8718. //DEBUG_INFO("word=%s\n",word);
  8719. if(strstr(word, "chargingProfileId")!= NULL)
  8720. {
  8721. //DEBUG_INFO("test chargingProfileId \n");
  8722. n_chargingProfile = n_chargingProfile + 1;
  8723. //DEBUG_INFO("chargingProfileId Found\n");
  8724. }
  8725. }
  8726. }
  8727. fclose(fptr1);
  8728. }
  8729. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8730. {
  8731. //printf("set chargingProfile 1-4\n");
  8732. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8733. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8734. if(connectorIdInt == 0)
  8735. {
  8736. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8737. goto end;
  8738. }
  8739. int tempIndex = 0;
  8740. //check Transaction active
  8741. if(gunType[connectorIdInt -1] == 'J')
  8742. {
  8743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8744. {
  8745. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8746. }
  8747. else
  8748. {
  8749. tempIndex = connectorIdInt -1;
  8750. }
  8751. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8752. {
  8753. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8754. {
  8755. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8756. {
  8757. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8758. {
  8759. meet = TRUE;
  8760. break;
  8761. }
  8762. }
  8763. }
  8764. }
  8765. }
  8766. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8767. {
  8768. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8769. {
  8770. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8771. }
  8772. else
  8773. {
  8774. tempIndex = connectorIdInt -1;
  8775. }
  8776. for (int index = 0; index < CCS_QUANTITY; index++)
  8777. {
  8778. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8779. {
  8780. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8781. {
  8782. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8783. {
  8784. meet = TRUE;
  8785. break;
  8786. }
  8787. }
  8788. }
  8789. }
  8790. }
  8791. else if(gunType[connectorIdInt -1] == 'G')
  8792. {
  8793. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8794. {
  8795. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8796. }
  8797. else
  8798. {
  8799. tempIndex = connectorIdInt -1;
  8800. }
  8801. for (int index = 0; index < GB_QUANTITY; index++)
  8802. {
  8803. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8804. {
  8805. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8806. {
  8807. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8808. {
  8809. meet = TRUE;
  8810. break;
  8811. }
  8812. }
  8813. }
  8814. }
  8815. }
  8816. else if(gunType[connectorIdInt -1] == 'O')
  8817. {
  8818. tempIndex = connectorIdInt -1;
  8819. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8820. {
  8821. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8822. {
  8823. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8824. {
  8825. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8826. {
  8827. meet = TRUE;
  8828. break;
  8829. }
  8830. }
  8831. }
  8832. }
  8833. }
  8834. else
  8835. {
  8836. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8837. {
  8838. tempIndex = 2;
  8839. }
  8840. else
  8841. {
  8842. tempIndex = (connectorIdInt -1);
  8843. }
  8844. for (int index = 0; index < AC_QUANTITY; index++)
  8845. {
  8846. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8847. {
  8848. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8849. {
  8850. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8851. {
  8852. meet = TRUE;
  8853. break;
  8854. }
  8855. }
  8856. }
  8857. }
  8858. }
  8859. //check Transaction active
  8860. if(meet == FALSE)
  8861. {
  8862. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8863. goto end;
  8864. }
  8865. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8866. {
  8867. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8868. goto end;
  8869. }
  8870. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8871. fptr1 = fopen(filename, "r");
  8872. if (!fptr1)
  8873. {
  8874. //file not exist
  8875. DEBUG_INFO("Unable to open the input file!!\n");
  8876. fptr1 = fopen(filename, "w+");
  8877. }
  8878. else
  8879. {
  8880. //Check Charging Profile Count
  8881. while(fscanf(fptr1, "%s", word) != EOF)
  8882. {
  8883. //DEBUG_INFO("word=%s\n",word);
  8884. if(strstr(word, "chargingProfileId")!= NULL)
  8885. {
  8886. //DEBUG_INFO("test chargingProfileId \n");
  8887. n_chargingProfile = n_chargingProfile + 1;
  8888. //DEBUG_INFO("chargingProfileId Found\n");
  8889. }
  8890. }
  8891. }
  8892. fclose(fptr1);
  8893. }
  8894. // Check ChargeProfileMaxStackLevel
  8895. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8896. {
  8897. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8898. goto end;
  8899. }
  8900. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8901. {
  8902. int i = 0;
  8903. char fnametemp[200]={0};
  8904. n_chargingProfile = 0;
  8905. //Check ChargePointMaxProfile.json exit
  8906. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8907. {
  8908. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8909. //Check Charging Profile Count
  8910. while(fscanf(fptr1, "%s", word) != EOF)
  8911. {
  8912. //DEBUG_INFO("word=%s\n",word);
  8913. if(strstr(word, "chargingProfileId")!= NULL)
  8914. {
  8915. //DEBUG_INFO("test chargingProfileId \n");
  8916. n_chargingProfile = n_chargingProfile + 1;
  8917. i = i + 1;
  8918. //DEBUG_INFO("chargingProfileId Found\n");
  8919. }
  8920. memset(word, 0, ARRAY_SIZE(word));
  8921. }
  8922. fclose(fptr1);
  8923. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8924. }
  8925. //Check TxDefaultProfile_0.json exit
  8926. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8927. {
  8928. i = 0;
  8929. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8930. //Check Charging Profile Count
  8931. while(fscanf(fptr1, "%s", word) != EOF)
  8932. {
  8933. //DEBUG_INFO("word=%s\n",word);
  8934. if(strstr(word, "chargingProfileId")!= NULL)
  8935. {
  8936. //DEBUG_INFO("test chargingProfileId \n");
  8937. n_chargingProfile = n_chargingProfile + 1;
  8938. i = i + 1;
  8939. //DEBUG_INFO("chargingProfileId Found\n");
  8940. }
  8941. memset(word, 0, ARRAY_SIZE(word));
  8942. }
  8943. fclose(fptr1);
  8944. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8945. }
  8946. //Check TxDefaultProfile_%d.json
  8947. for(int j=1; j <= gunTotalNumber; j++)
  8948. {
  8949. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8950. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8951. if((access(fnametemp,F_OK))!=-1)
  8952. {
  8953. i = 0;
  8954. fptr1 = fopen(fnametemp, "r");
  8955. //Check Charging Profile Count
  8956. while(fscanf(fptr1, "%s", word) != EOF)
  8957. {
  8958. //DEBUG_INFO("word=%s\n",word);
  8959. if(strstr(word, "chargingProfileId")!= NULL)
  8960. {
  8961. //DEBUG_INFO("test chargingProfileId \n");
  8962. n_chargingProfile = n_chargingProfile + 1;
  8963. i = i + 1;
  8964. //DEBUG_INFO("chargingProfileId Found\n");
  8965. }
  8966. memset(word, 0, ARRAY_SIZE(word));
  8967. }
  8968. fclose(fptr1);
  8969. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8970. }
  8971. }
  8972. //Check TxProfile_%d.json
  8973. for(int j=1; j <= gunTotalNumber; j++)
  8974. {
  8975. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8976. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8977. if((access(fnametemp,F_OK))!=-1)
  8978. {
  8979. i = 0;
  8980. fptr1 = fopen(fnametemp, "r");
  8981. //Check Charging Profile Count
  8982. while(fscanf(fptr1, "%s", word) != EOF)
  8983. {
  8984. //DEBUG_INFO("word=%s\n",word);
  8985. if(strstr(word, "chargingProfileId")!= NULL)
  8986. {
  8987. //DEBUG_INFO("test chargingProfileId \n");
  8988. n_chargingProfile = n_chargingProfile + 1;
  8989. i = i + 1;
  8990. //DEBUG_INFO("chargingProfileId Found\n");
  8991. }
  8992. memset(word, 0, ARRAY_SIZE(word));
  8993. }
  8994. fclose(fptr1);
  8995. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8996. }
  8997. }
  8998. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8999. {
  9000. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  9001. goto end;
  9002. }
  9003. }
  9004. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  9005. //**********************************Write to File********************************************************/
  9006. FILE *infile;
  9007. FILE *outfile;
  9008. infile = fopen (filename, "r");
  9009. outfile = fopen (tempfile, "w");
  9010. int d =0;
  9011. d = fgetc(infile);
  9012. rewind(infile);
  9013. if(d == EOF)
  9014. {
  9015. // Profile is empty
  9016. fprintf(outfile,"%s\n",payload);
  9017. fclose(infile);
  9018. fclose(outfile);
  9019. sprintf(rmFileCmd,"rm -f %s",filename);
  9020. system(rmFileCmd);
  9021. rename(tempfile, filename);
  9022. }
  9023. else
  9024. {
  9025. // Profile is not empty
  9026. char buf[2048]={0};
  9027. int ChargingProfileAdded = FALSE;
  9028. while (fgets(buf, sizeof(buf), infile) != NULL)
  9029. {
  9030. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9031. json_object *tmpChargingProfile;
  9032. tmpChargingProfile = json_tokener_parse(buf);
  9033. if(!is_error(SetChargingProfile))
  9034. {
  9035. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  9036. {
  9037. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  9038. }
  9039. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  9040. {
  9041. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  9042. {
  9043. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  9044. }
  9045. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  9046. {
  9047. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  9048. }
  9049. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9050. {
  9051. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9052. }
  9053. }
  9054. }
  9055. json_object_put(tmpChargingProfile);
  9056. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9057. {
  9058. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9059. {
  9060. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9061. if(ChargingProfileAdded == FALSE)
  9062. {
  9063. fprintf(outfile,"%s\n",payload);
  9064. ChargingProfileAdded = TRUE;
  9065. }
  9066. }
  9067. else
  9068. {
  9069. if(tempstackLevelInt < stackLevelInt)
  9070. {
  9071. if(ChargingProfileAdded == FALSE)
  9072. {
  9073. fprintf(outfile,"%s\n",buf);
  9074. fprintf(outfile,"%s\n",payload);
  9075. ChargingProfileAdded = TRUE;
  9076. }
  9077. else
  9078. {
  9079. fprintf(outfile,"%s\n",buf);
  9080. }
  9081. }
  9082. else
  9083. {
  9084. if(ChargingProfileAdded == FALSE)
  9085. {
  9086. fprintf(outfile,"%s\n",buf);
  9087. fprintf(outfile,"%s\n",payload);
  9088. ChargingProfileAdded = TRUE;
  9089. }
  9090. else
  9091. {
  9092. fprintf(outfile,"%s\n",buf);
  9093. }
  9094. }
  9095. }
  9096. }
  9097. else
  9098. {
  9099. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9100. {
  9101. if(ChargingProfileAdded == FALSE)
  9102. {
  9103. fprintf(outfile,"%s\n",buf);
  9104. fprintf(outfile,"%s\n",payload);
  9105. ChargingProfileAdded = TRUE;
  9106. }
  9107. else
  9108. {
  9109. fprintf(outfile,"%s\n",buf);
  9110. }
  9111. }
  9112. else if(tempstackLevelInt < stackLevelInt)
  9113. {
  9114. if(ChargingProfileAdded == FALSE)
  9115. {
  9116. fprintf(outfile,"%s\n",buf);
  9117. fprintf(outfile,"%s\n",payload);
  9118. ChargingProfileAdded = TRUE;
  9119. }
  9120. else
  9121. {
  9122. fprintf(outfile,"%s\n",buf);
  9123. }
  9124. }
  9125. else
  9126. {
  9127. if(ChargingProfileAdded == FALSE)
  9128. {
  9129. fprintf(outfile,"%s\n",buf);
  9130. fprintf(outfile,"%s\n",payload);
  9131. ChargingProfileAdded = TRUE;
  9132. }
  9133. else
  9134. {
  9135. fprintf(outfile,"%s\n",buf);
  9136. }
  9137. }
  9138. }
  9139. } // end of while loop
  9140. fclose(infile);
  9141. fclose(outfile);
  9142. sprintf(rmFileCmd,"rm -f %s",filename);
  9143. system(rmFileCmd);
  9144. rename(tempfile, filename);
  9145. }
  9146. sleep(1);
  9147. result = TRUE;
  9148. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9149. end:
  9150. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9151. {
  9152. if(connectorIdInt == 0)
  9153. {
  9154. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9155. {
  9156. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9157. }
  9158. }
  9159. else
  9160. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9161. }
  9162. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9163. return result;
  9164. }
  9165. int handleTriggerMessageRequest(char *uuid, char *payload)
  9166. {
  9167. mtrace();
  9168. int result = FAIL;
  9169. int connectorIdIsNULL = FALSE;
  9170. int connectorIdInt =0;
  9171. char sstr[40]={0},sstrtemp[100]={ 0 };
  9172. char requestedMessagestr[40]={0};
  9173. char comfirmstr[20]={0};
  9174. int c = 0;
  9175. char *loc;
  9176. DEBUG_INFO("handleTriggerMessageRequest\n");
  9177. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9178. strcpy(sstrtemp, stringtrimspace(payload));
  9179. c = 0;
  9180. loc = strstr(sstrtemp, "requestedMessage");
  9181. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9182. {
  9183. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9184. c++;
  9185. }
  9186. sstr[c] = '\0';
  9187. strcpy(requestedMessagestr, sstr);
  9188. c = 0;
  9189. loc = strstr(sstrtemp, "connectorId");
  9190. if(loc == NULL)
  9191. {
  9192. connectorIdIsNULL = TRUE;
  9193. }
  9194. else
  9195. {
  9196. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9197. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9198. {
  9199. sstr[c] = loc[strlen("connectorId")+2+c];
  9200. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9201. c++;
  9202. }
  9203. sstr[c] = '\0';
  9204. connectorIdInt = atoi(sstr);
  9205. }
  9206. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9207. {
  9208. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9209. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9210. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9211. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9212. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9213. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9214. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9215. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9216. {
  9217. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9218. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9219. return TRUE;
  9220. }
  9221. else
  9222. {
  9223. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9224. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9225. }
  9226. }
  9227. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9228. {
  9229. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9230. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9231. return TRUE;
  9232. }
  9233. //==========================
  9234. // Trigger message
  9235. //==========================
  9236. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9237. {
  9238. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9239. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9240. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9241. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9242. {
  9243. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9244. }
  9245. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9246. }
  9247. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9248. {
  9249. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9250. }
  9251. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9252. {
  9253. //sendBootNotificationRequest();
  9254. server_sign = FALSE;
  9255. }
  9256. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9257. {
  9258. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9259. }
  9260. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9261. {
  9262. if(connectorIdIsNULL == FALSE)
  9263. {
  9264. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9265. {
  9266. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9267. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9268. }
  9269. }
  9270. else
  9271. {
  9272. for(int idx=0;idx< gunTotalNumber;idx++)
  9273. {
  9274. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9275. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9276. }
  9277. }
  9278. }
  9279. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9280. {
  9281. if(connectorIdIsNULL == FALSE)
  9282. {
  9283. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9284. {
  9285. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9286. }
  9287. }
  9288. else
  9289. {
  9290. for(int idx=0;idx< gunTotalNumber;idx++)
  9291. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9292. }
  9293. }
  9294. return result;
  9295. }
  9296. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9297. {
  9298. mtrace();
  9299. int result = FAIL;
  9300. int connectorIdInt =0;
  9301. char comfirmstr[20]={0};
  9302. int tempIndex = 0;
  9303. json_object *UnlockConnector;
  9304. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9305. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9306. UnlockConnector = json_tokener_parse(payload);
  9307. if(!is_error(UnlockConnector))
  9308. {
  9309. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9310. {
  9311. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9312. }
  9313. }
  9314. json_object_put(UnlockConnector);
  9315. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9316. if(gunTotalNumber == 0)
  9317. {
  9318. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9319. goto end;
  9320. }
  9321. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9322. {
  9323. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9324. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9325. goto end;
  9326. }
  9327. else
  9328. {
  9329. //check Transaction active
  9330. if(gunType[connectorIdInt-1] == 'J')
  9331. {
  9332. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9333. {
  9334. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9335. }
  9336. else
  9337. {
  9338. tempIndex = connectorIdInt -1;
  9339. }
  9340. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9341. {
  9342. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9343. {
  9344. //stop Transaction
  9345. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9346. }
  9347. }
  9348. }
  9349. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9350. {
  9351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9352. {
  9353. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9354. }
  9355. else
  9356. {
  9357. tempIndex = connectorIdInt -1;
  9358. }
  9359. for (int index = 0; index < CCS_QUANTITY; index++)
  9360. {
  9361. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9362. {
  9363. //stop Transaction
  9364. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9365. }
  9366. }
  9367. }
  9368. else if(gunType[connectorIdInt-1] == 'G')
  9369. {
  9370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9371. {
  9372. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9373. }
  9374. else
  9375. {
  9376. tempIndex = connectorIdInt -1;
  9377. }
  9378. for (int index = 0; index < GB_QUANTITY; index++)
  9379. {
  9380. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9381. {
  9382. //stop Transaction
  9383. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9384. }
  9385. }
  9386. }
  9387. else if(gunType[connectorIdInt-1] == 'O')
  9388. {
  9389. tempIndex = connectorIdInt -1;
  9390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9391. {
  9392. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9393. {
  9394. //stop Transaction
  9395. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9396. }
  9397. }
  9398. }
  9399. else
  9400. {
  9401. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9402. {
  9403. tempIndex = 2;
  9404. }
  9405. else
  9406. {
  9407. tempIndex = connectorIdInt-1;
  9408. }
  9409. for (int index = 0; index < AC_QUANTITY; index++)
  9410. {
  9411. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9412. {
  9413. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9414. }
  9415. }
  9416. }
  9417. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9418. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9419. result = TRUE;
  9420. return result;
  9421. }
  9422. end:
  9423. //json_object_put(obj); --- remove temporally
  9424. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9425. return result;
  9426. }
  9427. static char UpdateFirmwarepayloadData[300]={0};
  9428. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9429. {
  9430. mtrace();
  9431. int result = FAIL;
  9432. pthread_t t;
  9433. sendUpdateFirmwareConfirmation(uuid);
  9434. memset(UpdateFirmwarepayloadData, 0, 300);
  9435. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9436. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9437. ////pthread_join(t, NULL); //
  9438. //pthread_detach(t);
  9439. //sendUpdateFirmwareConfirmation(uuid);
  9440. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9441. return result;
  9442. }
  9443. void *UpdateFirmwareProcess(void *data)
  9444. {
  9445. pthread_detach(pthread_self());
  9446. mtrace();
  9447. int retriesInt =0, retryIntervalInt=0;
  9448. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9449. int port=0;
  9450. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9451. int isSuccess = 0;
  9452. char ftpbuf[200];
  9453. char temp[100];
  9454. char * pch;
  9455. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9456. json_object *UpdateFirmware;
  9457. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9458. if(!is_error(UpdateFirmware))
  9459. {
  9460. // Required data
  9461. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9462. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9463. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9464. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9465. // Optional data
  9466. if(json_object_object_get(UpdateFirmware, "retries"))
  9467. {
  9468. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9469. }
  9470. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9471. {
  9472. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9473. }
  9474. }
  9475. json_object_put(UpdateFirmware);
  9476. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9477. memset(path, 0, ARRAY_SIZE(path));
  9478. system("rm -f /mnt/*");
  9479. if(strncmp(locationstr,"http", 4) == 0)
  9480. {
  9481. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9482. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9483. // protocol, user, password, host, path);
  9484. sprintf(ftppath,"/%s", path);
  9485. DEBUG_INFO("locationstr: %s\n", locationstr);
  9486. DEBUG_INFO("protocol: %s\n",protocol);
  9487. DEBUG_INFO("host: %s\n",host);
  9488. DEBUG_INFO("path: %s\n",path);
  9489. DEBUG_INFO("ftppath: %s\n",ftppath);
  9490. int ftppathlen=strlen(ftppath);
  9491. int i=1;
  9492. char filenametemp[50];
  9493. while(i < ftppathlen)
  9494. {
  9495. int len=ftppathlen-i;
  9496. if(ftppath[len]== 47) // '/' ascll code: 47
  9497. {
  9498. DEBUG_INFO("compare '/' all right\n");
  9499. break;
  9500. }
  9501. i=i+1;
  9502. }
  9503. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9504. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9505. filenametemp[i+1] = 0;
  9506. do
  9507. {
  9508. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9509. sleep(3);
  9510. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9511. if(!isSuccess)
  9512. {
  9513. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9514. sleep(retryIntervalInt);
  9515. }
  9516. else
  9517. {
  9518. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9519. }
  9520. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9521. }
  9522. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9523. {
  9524. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9525. memset(temp, 0, ARRAY_SIZE(temp));
  9526. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9527. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9528. int ftppathlen=strlen(ftpbuf);
  9529. int i=1;
  9530. char filenametemp[50];
  9531. while(i < ftppathlen)
  9532. {
  9533. int len=ftppathlen-i;
  9534. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9535. {
  9536. DEBUG_INFO(" compare '/' all right\n");
  9537. break;
  9538. }
  9539. i=i+1;
  9540. }
  9541. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9542. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9543. filenametemp[i+1] = 0;
  9544. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9545. pch=strchr(temp,'@');
  9546. if(pch==NULL)
  9547. {
  9548. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9549. protocol, host, &port, path);
  9550. strcpy(user,"anonymous");
  9551. strcpy(password,"");
  9552. }
  9553. else
  9554. {
  9555. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9556. protocol, user, password, host, &port, path);
  9557. }
  9558. sscanf(host,"%[^/]%s",host1, path1);
  9559. sprintf(ftppath,"%s", path1);
  9560. //DEBUG_INFO("protocol =%s\n",protocol);
  9561. //DEBUG_INFO("user =%s\n",user);
  9562. //DEBUG_INFO("password =%s\n",password);
  9563. //DEBUG_INFO("host1 =%s\n",host1);
  9564. //DEBUG_INFO("port =%d\n",port);
  9565. //DEBUG_INFO("path1 =%s\n",path1);
  9566. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9567. //ftpFile(host, user, password, port, ftppath, fname);
  9568. //download firmware pthred
  9569. if(port == 0)
  9570. {
  9571. port = 21;
  9572. }
  9573. do
  9574. {
  9575. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9576. sleep(3);
  9577. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9578. if(!isSuccess)
  9579. {
  9580. //BulldogUtil.sleepMs(interval*1000);
  9581. DEBUG_INFO("Update firmware request and download file fail.\n");
  9582. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9583. sleep(retryIntervalInt);
  9584. }
  9585. else
  9586. {
  9587. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9588. }
  9589. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9590. }
  9591. else
  9592. {
  9593. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9594. }
  9595. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9596. pthread_exit(NULL);
  9597. }
  9598. //==========================================
  9599. // Handle server response routine
  9600. //==========================================
  9601. void handleAuthorizeResponse(char *payload, int gun_index)
  9602. {
  9603. mtrace();
  9604. char expiryDatestr[30]={0};
  9605. char parentIdTagstr[20]={0};
  9606. char statusstr[20]={0};
  9607. char expiryDatestrtemp[30]={0};
  9608. char parentIdTagstrtemp[20]={0};
  9609. char IdTagstrtemp[20]={0};
  9610. char statusstrtemp[20]={0};
  9611. int expiryDateISNULL=FALSE;
  9612. int parentIdTagISNULL=FALSE;
  9613. char sstr[160]={0};
  9614. char* filename = AuthorizationCache_JSON;
  9615. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9616. char *loc;
  9617. int resultRename=0;
  9618. int responseIdTagInfoAsZero= 0;
  9619. char rmFileCmd[50]={0};
  9620. DEBUG_INFO("handleAuthorizeResponse...\n");
  9621. json_object *Authorize;
  9622. Authorize = json_tokener_parse(payload);
  9623. if(!is_error(Authorize))
  9624. {
  9625. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9626. {
  9627. // Required data
  9628. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9629. // Optional data
  9630. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9631. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9632. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9633. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9634. }
  9635. }
  9636. json_object_put(Authorize);
  9637. if(expiryDateISNULL == FALSE)
  9638. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9639. if(parentIdTagISNULL == FALSE)
  9640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9641. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9642. //Update idTag information to authorization cache if supproted
  9643. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9644. {
  9645. if((access(filename,F_OK))!=-1)
  9646. {
  9647. printf("AuthorizationCache exist.\n");
  9648. }
  9649. else
  9650. {
  9651. printf("AuthorizationCache not exist\n");
  9652. FILE *log = fopen(filename, "w+");
  9653. if(log == NULL)
  9654. {
  9655. printf("log is NULL\n");
  9656. goto out;
  9657. }
  9658. else
  9659. {
  9660. fclose(log);
  9661. }
  9662. }
  9663. FILE *infile;
  9664. FILE *outfile;
  9665. // open file for writing
  9666. infile = fopen (filename, "r");
  9667. outfile = fopen (tempfile, "w");
  9668. int c;
  9669. c = fgetc(infile);
  9670. //DEBUG_INFO("c:%d\n",c);
  9671. rewind(infile);
  9672. if(c == EOF)
  9673. {
  9674. DEBUG_INFO("Orignal File is NULL\n");
  9675. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9676. {
  9677. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9678. }
  9679. else
  9680. {
  9681. strcpy(expiryDatestrtemp, "");
  9682. }
  9683. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9684. {
  9685. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9686. }
  9687. else
  9688. {
  9689. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9690. }
  9691. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9692. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9693. fclose(infile);
  9694. fclose(outfile);
  9695. sprintf(rmFileCmd,"rm -f %s",filename);
  9696. system(rmFileCmd);
  9697. resultRename = rename(tempfile, filename);
  9698. if(resultRename == 0)
  9699. {
  9700. printf("File renamed successfully");
  9701. }
  9702. else
  9703. {
  9704. printf("Error: unable to rename the file");
  9705. }
  9706. }
  9707. else
  9708. {
  9709. char buf[160]={0};
  9710. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9711. {
  9712. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9713. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9714. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9715. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9716. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9717. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9718. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9719. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9720. //------------------IdTag-----------------------
  9721. loc = strstr(buf, "idTag");
  9722. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9723. c = 0;
  9724. while (loc[3+strlen("idTag")+c] != '\"')
  9725. {
  9726. sstr[c] = loc[3+strlen("idTag")+c];
  9727. c++;
  9728. }
  9729. sstr[c] = '\0';
  9730. strcpy(IdTagstrtemp,sstr);
  9731. //*********************expiryDate***************/
  9732. loc = strstr(buf, "expiryDate");
  9733. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9734. c = 0;
  9735. while (loc[3+strlen("expiryDate")+c] != '\"')
  9736. {
  9737. sstr[c] = loc[3+strlen("expiryDate")+c];
  9738. c++;
  9739. }
  9740. sstr[c] = '\0';
  9741. strcpy(expiryDatestr,sstr);
  9742. //*********************parentIdTag***************/
  9743. loc = strstr(buf, "parentIdTag");
  9744. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9745. c = 0;
  9746. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9747. {
  9748. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9749. c++;
  9750. }
  9751. sstr[c] = '\0';
  9752. strcpy(parentIdTagstr,sstr);
  9753. //*********************status***************/
  9754. loc = strstr(buf, "status");
  9755. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9756. c = 0;
  9757. while (loc[3+strlen("status")+c] != '\"')
  9758. {
  9759. sstr[c] = loc[3+strlen("status")+c];
  9760. c++;
  9761. }
  9762. sstr[c] = '\0';
  9763. strcpy(statusstr,sstr);
  9764. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9765. {
  9766. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9767. responseIdTagInfoAsZero = 1;
  9768. }
  9769. else
  9770. {
  9771. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9772. }
  9773. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9774. {
  9775. //modify item
  9776. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9777. {
  9778. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9779. }
  9780. else
  9781. {
  9782. strcpy(expiryDatestrtemp, "");
  9783. }
  9784. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9785. {
  9786. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9787. }
  9788. else
  9789. {
  9790. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9791. }
  9792. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9793. }
  9794. else
  9795. {
  9796. //wrie original item
  9797. strcpy(expiryDatestrtemp, expiryDatestr);
  9798. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9799. strcpy(statusstrtemp, statusstr);
  9800. }
  9801. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9802. }
  9803. fclose(infile);
  9804. fclose(outfile);
  9805. sprintf(rmFileCmd,"rm -f %s",filename);
  9806. system(rmFileCmd);
  9807. resultRename = rename(tempfile, filename);
  9808. if(resultRename == 0)
  9809. {
  9810. DEBUG_INFO("File renamed successfully");
  9811. }
  9812. else
  9813. {
  9814. DEBUG_INFO("Error: unable to rename the file");
  9815. }
  9816. }
  9817. }
  9818. out:
  9819. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9820. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9821. authorizeRetryTimes = 0;
  9822. }
  9823. void handleBootNotificationResponse(char *payload, int gun_index)
  9824. {
  9825. mtrace();
  9826. char statusStr[12]={0};
  9827. char currentTimeStr[30]={0};
  9828. int intervalInt = 0;
  9829. struct tm tp;
  9830. char buf[28]={0};
  9831. char timebuf[50]={0};
  9832. DEBUG_INFO("handleBootNotificationResponse...\n");
  9833. json_object *BootNotification;
  9834. BootNotification = json_tokener_parse(payload);
  9835. if(!is_error(BootNotification))
  9836. {
  9837. // Required data
  9838. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9839. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9840. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9841. }
  9842. json_object_put(BootNotification);
  9843. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9844. BootNotificationInterval = intervalInt;
  9845. HeartBeatWaitTime = intervalInt;
  9846. //write back to ShmOCPP16Data->BootNotification
  9847. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9848. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9849. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9850. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9851. {
  9852. server_sign = TRUE;
  9853. server_pending =FALSE;
  9854. }
  9855. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9856. {
  9857. server_pending = TRUE;
  9858. }
  9859. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9860. tp.tm_isdst = -1;
  9861. //time_t utc = mktime(&tp);
  9862. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9863. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9864. sprintf(timebuf,"date -s '%s'",buf);
  9865. system(timebuf);
  9866. srand(time(NULL));
  9867. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9868. //==============================================
  9869. // RTC sync
  9870. //==============================================
  9871. system("/sbin/hwclock -w --systohc");
  9872. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9873. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9874. }
  9875. void handleDataTransferResponse(char *payload, int gun_index)
  9876. {
  9877. char sstr[160]={0};//sstr[200]={ 0 };
  9878. int c = 0;
  9879. char *loc;
  9880. DEBUG_INFO("handleDataTransferResponse ...\n");
  9881. loc = strstr(payload, "status");
  9882. printf("loc=%s\n",loc);
  9883. c = 0;
  9884. while (loc[3+strlen("status")+c] != '\"')
  9885. {
  9886. sstr[c] = loc[3+strlen("status")+c];
  9887. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9888. c++;
  9889. }
  9890. sstr[c] = '\0';
  9891. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9892. }
  9893. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9894. {
  9895. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9896. //struct json_object *obj;
  9897. // obj = json_tokener_parse(payload);
  9898. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9899. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9900. //No fields are defined.
  9901. }
  9902. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9903. {
  9904. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9905. //struct json_object *obj;
  9906. // obj = json_tokener_parse(payload);
  9907. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9908. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9909. //No fields are defined.
  9910. }
  9911. void handleHeartbeatResponse(char *payload, int gun_index)
  9912. {
  9913. mtrace();
  9914. struct tm tp;
  9915. char buf[28]={0};
  9916. char timebuf[50]={0};
  9917. DEBUG_INFO("handleHeartbeatResponse...\n");
  9918. json_object *Heartbeat;
  9919. Heartbeat = json_tokener_parse(payload);
  9920. if(!is_error(Heartbeat))
  9921. {
  9922. // Required data
  9923. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9924. }
  9925. json_object_put(Heartbeat);
  9926. if(FirstHeartBeat == 0)
  9927. {
  9928. FirstHeartBeat = 1;
  9929. DEBUG_INFO("FirstHeartBeat \n");
  9930. }
  9931. HeartBeatWithNOResponse = 0;
  9932. clientTime.Heartbeat=time((time_t*)NULL);
  9933. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9934. tp.tm_isdst = -1;
  9935. //time_t utc = mktime(&tp);
  9936. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9937. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9938. sprintf(timebuf,"date -s '%s'",buf);
  9939. system(timebuf);
  9940. //==============================================
  9941. // RTC sync
  9942. //==============================================
  9943. system("/sbin/hwclock -w --systohc");
  9944. }
  9945. void handleMeterValuesResponse(char *payload, int gun_index)
  9946. {
  9947. mtrace();
  9948. DEBUG_INFO("handleMeterValuesResponse...\n");
  9949. }
  9950. void handleStartTransactionResponse(char *payload, int gun_index)
  9951. {
  9952. mtrace();
  9953. //int transactionIdInt = 0;
  9954. FILE *outfile;
  9955. char data[100]={0};
  9956. DEBUG_INFO("handleStartTransactionResponse...\n");
  9957. json_object *StartTransaction;
  9958. StartTransaction = json_tokener_parse(payload);
  9959. if(!is_error(StartTransaction))
  9960. {
  9961. // Required data
  9962. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9963. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9964. // Optional data
  9965. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9966. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9967. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9968. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9969. }
  9970. json_object_put(StartTransaction);
  9971. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9972. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9973. //-----------Start : write to the Queue TransactionId file -----------------//
  9974. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9975. {}
  9976. else
  9977. {
  9978. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9979. if(log == NULL)
  9980. {
  9981. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9982. return ;
  9983. }
  9984. else
  9985. {
  9986. fclose(log);
  9987. }
  9988. }
  9989. // open file for writing
  9990. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9991. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9992. {
  9993. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9994. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9995. fputs(data, outfile);
  9996. fclose (outfile);
  9997. }
  9998. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9999. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10000. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  10001. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  10002. }
  10003. void handleStatusNotificationResponse(char *payload, int gun_index)
  10004. {
  10005. mtrace();
  10006. DEBUG_INFO("handleStatusNotificationResponse...\n");
  10007. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  10008. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  10009. }
  10010. void handleStopTransactionnResponse(char *payload, int gun_index)
  10011. {
  10012. mtrace();
  10013. DEBUG_INFO("handleStopTransactionnResponse...\n");
  10014. json_object *StopTransaction;
  10015. StopTransaction = json_tokener_parse(payload);
  10016. if(!is_error(StopTransaction))
  10017. {
  10018. // Optional data
  10019. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  10020. {
  10021. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  10022. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  10023. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  10024. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  10025. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  10026. }
  10027. }
  10028. json_object_put(StopTransaction);
  10029. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  10030. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  10031. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  10032. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  10033. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  10034. }
  10035. //==========================================
  10036. // Handle Error routine
  10037. //==========================================
  10038. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  10039. {
  10040. mtrace();
  10041. #ifdef SystemLogMessage
  10042. DEBUG_INFO("errorCode: %s\n", errorCode);
  10043. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  10044. DEBUG_INFO("errorDetails: %s\n", payload);
  10045. #endif
  10046. }
  10047. //===============================================
  10048. // Common routine
  10049. //===============================================
  10050. int initialConfigurationTable(void)
  10051. {
  10052. //clock_t start_t, end_t, total_t;
  10053. FILE *fp;
  10054. FILE *outfile;
  10055. char str[200]={0};
  10056. char sstr[100]={0};
  10057. int c = 0;
  10058. char *loc;
  10059. DEBUG_INFO("initialConfigurationTable...\n");
  10060. //start_t = clock();
  10061. //printf("Starting of the program, start_t = %ld\n", start_t);
  10062. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  10063. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  10064. {
  10065. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10066. if(outfile == NULL)
  10067. {
  10068. DEBUG_INFO("Error opening file\n");
  10069. return FALSE;
  10070. }
  10071. /*Core Profile*/
  10072. //AllowOfflineTxForUnknownId
  10073. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10074. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10075. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  10076. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10077. //AuthorizationCacheEnabled
  10078. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10079. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10080. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10081. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10082. //AuthorizeRemoteTxRequests
  10083. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10085. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  10086. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10087. //BlinkRepeat
  10088. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10092. //ClockAlignedDataInterval
  10093. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10097. //ConnectionTimeOut
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10102. //GetConfigurationMaxKeys
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10104. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  10106. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10107. // HeartbeatInterval
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10109. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  10111. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10112. // LightIntensity
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10114. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10116. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10117. // LocalAuthorizeOffline
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  10119. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10121. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10122. // LocalPreAuthorize
  10123. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10124. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10126. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10127. // MaxEnergyOnInvalidId
  10128. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10129. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10130. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10131. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10132. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10133. // MeterValuesAlignedData
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  10135. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10136. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10137. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10138. else
  10139. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10140. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10141. // MeterValuesAlignedDataMaxLength
  10142. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10143. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10145. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  10146. else
  10147. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10148. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10149. // MeterValuesSampledData
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  10151. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10152. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10153. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10154. else
  10155. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10156. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10157. // MeterValuesSampledDataMaxLength
  10158. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10159. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10161. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  10162. else
  10163. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10164. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10165. // MeterValueSampleInterval
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10167. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10168. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  10169. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10170. // MinimumStatusDuration
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10172. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10173. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  10174. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  10175. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10176. // NumberOfConnectors
  10177. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10178. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10179. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10180. {
  10181. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10182. }
  10183. else
  10184. {
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10186. }
  10187. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10188. // ResetRetries
  10189. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10190. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10191. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10192. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10193. // ConnectorPhaseRotation
  10194. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10195. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10196. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10197. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10198. // ConnectorPhaseRotationMaxLength
  10199. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10200. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10201. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10202. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10203. // StopTransactionOnEVSideDisconnect
  10204. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10205. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10206. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10207. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10208. // StopTransactionOnInvalidId
  10209. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  10210. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10211. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10212. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10213. // StopTxnAlignedData
  10214. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  10215. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10216. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10217. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10218. // StopTxnAlignedDataMaxLength
  10219. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10220. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10221. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10222. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10223. // StopTxnSampledData
  10224. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  10225. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10226. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10227. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  10228. else
  10229. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  10230. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10231. // StopTxnSampledDataMaxLength
  10232. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10233. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10234. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10235. {
  10236. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10237. }
  10238. else
  10239. {
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10241. }
  10242. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10243. // SupportedFeatureProfiles
  10244. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10245. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10246. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10247. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10248. // SupportedFeatureProfilesMaxLength
  10249. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10250. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10251. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10252. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10253. // TransactionMessageAttempts
  10254. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10255. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10256. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10257. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10258. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10259. // TransactionMessageRetryInterval
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10261. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10262. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10263. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10264. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10265. // UnlockConnectorOnEVSideDisconnect
  10266. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10267. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10268. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10269. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10270. // WebSocketPingInterval
  10271. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10272. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10273. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10274. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10275. // QueueOffLineStartTransactionMessage
  10276. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10277. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10278. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10279. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10280. // AuthorizationKey
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10282. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10283. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10284. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10285. // SecurityProfile
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10287. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10288. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10289. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10290. // DefaultPrice
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10292. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10293. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10294. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10295. // CustomDisplayCostAndPrice
  10296. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10297. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10298. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10299. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10300. // CustomIdleFeeAfterStop
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10302. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10303. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10304. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10305. //* Local Auth List Management Profile*/
  10306. #if 0
  10307. //For OCTT Test Case
  10308. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10309. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10310. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10311. #endif
  10312. #if 1
  10313. //LocalAuthListEnabled
  10314. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10315. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10316. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10317. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10318. #endif
  10319. //LocalAuthListMaxLength
  10320. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10321. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10322. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10323. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10324. //SendLocalListMaxLength
  10325. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10326. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10327. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10328. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10329. //ReserveConnectorZeroSupported
  10330. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10331. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10332. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10333. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10334. //* Smart Charging Profile */
  10335. //ChargeProfileMaxStackLevel
  10336. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10337. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10338. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10339. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10340. // ChargingScheduleAllowedChargingRateUnit
  10341. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10342. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10343. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10344. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10345. // ChargingScheduleMaxPeriods
  10346. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10347. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10348. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10349. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10350. // ConnectorSwitch3to1PhaseSupported
  10351. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10352. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10353. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10355. // MaxChargingProfilesInstalled
  10356. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10357. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10359. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10360. fclose(outfile);
  10361. }
  10362. else
  10363. {
  10364. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10365. char keystr[60]={0};
  10366. char readonlystr[10]={0};
  10367. char valuestr[100]={0};
  10368. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10369. if(fp == NULL) {
  10370. DEBUG_INFO("Error opening file");
  10371. return FALSE;
  10372. }
  10373. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10374. {
  10375. //DEBUG_INFO("Get Configuration \n");
  10376. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10377. //*************************key*********************************/
  10378. loc = strstr(str, "key");
  10379. c = 0;
  10380. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10381. while (loc[strlen("key")+3+c] != '\"')
  10382. {
  10383. sstr[c] = loc[strlen("key")+3+c];
  10384. c++;
  10385. }
  10386. sstr[c] = '\0';
  10387. strcpy(keystr,sstr);
  10388. //*************************readonly*********************************/
  10389. loc = strstr(str, "readonly");
  10390. c = 0;
  10391. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10392. while (loc[strlen("readonly")+2+c] != ',')
  10393. {
  10394. sstr[c] = loc[strlen("readonly")+2+c];
  10395. c++;
  10396. }
  10397. sstr[c] = '\0';
  10398. strcpy(readonlystr,sstr);
  10399. //*************************value*********************************/
  10400. loc = strstr(str, "value");
  10401. c = 0;
  10402. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10403. while (loc[strlen("value")+3+c] != '\"')
  10404. {
  10405. sstr[c] = loc[strlen("value")+3+c];
  10406. c++;
  10407. }
  10408. sstr[c] = '\0';
  10409. strcpy(valuestr,sstr);
  10410. // DEBUG_INFO("keystr=%s\n",keystr);
  10411. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10412. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10413. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10414. {
  10415. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10416. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10417. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10418. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10419. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10420. }
  10421. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10422. {
  10423. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10424. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10426. }
  10427. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10428. {
  10429. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10430. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10431. }
  10432. if(strcmp(keystr, "BlinkRepeat") == 0)
  10433. {
  10434. //Charger.BlinkRepeat = Integer.parseInt(value);
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10436. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10437. }
  10438. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10439. {
  10440. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10442. }
  10443. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10444. {
  10445. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10446. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10447. }
  10448. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10449. {
  10450. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10451. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10452. }
  10453. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10454. {
  10455. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10456. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10457. HeartBeatWaitTime = atoi(valuestr);
  10458. }
  10459. if(strcmp(keystr, "LightIntensity") == 0)
  10460. {
  10461. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10463. }
  10464. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10465. {
  10466. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10468. }
  10469. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10470. {
  10471. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10472. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10473. }
  10474. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10475. {
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10477. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10478. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10479. }
  10480. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10481. {
  10482. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10483. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10484. }
  10485. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10486. {
  10487. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10488. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10489. }
  10490. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10491. {
  10492. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10493. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10494. }
  10495. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10496. {
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10499. }
  10500. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10501. {
  10502. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10503. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10504. }
  10505. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10506. {
  10507. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10509. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10510. }
  10511. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10512. {
  10513. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10514. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10515. }
  10516. if(strcmp(keystr, "ResetRetries") == 0)
  10517. {
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10519. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10520. }
  10521. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10522. {
  10523. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10524. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10525. }
  10526. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10527. {
  10528. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10529. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10530. }
  10531. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10532. {
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10534. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10535. }
  10536. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10537. {
  10538. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10539. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10540. }
  10541. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10542. {
  10543. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10544. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10545. }
  10546. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10547. {
  10548. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10549. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10550. }
  10551. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10552. {
  10553. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10554. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10555. }
  10556. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10557. {
  10558. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10559. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10560. }
  10561. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10562. {
  10563. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10564. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10565. }
  10566. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10567. {
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10569. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10570. }
  10571. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10572. {
  10573. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10574. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10575. TransactionMessageAttemptsValue = atoi(valuestr);
  10576. }
  10577. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10578. {
  10579. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10580. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10581. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10582. }
  10583. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10584. {
  10585. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10587. }
  10588. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10589. {
  10590. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10591. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10592. }
  10593. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10594. {
  10595. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10596. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10597. }
  10598. if(strcmp(keystr, "AuthorizationKey") == 0)
  10599. {
  10600. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10601. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10602. }
  10603. if(strcmp(keystr, "SecurityProfile") == 0)
  10604. {
  10605. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10607. }
  10608. if(strcmp(keystr, "DefaultPrice") == 0)
  10609. {
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10611. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10612. }
  10613. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10614. {
  10615. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10616. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10617. }
  10618. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10619. {
  10620. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10621. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10622. }
  10623. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10624. {
  10625. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10626. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10627. }
  10628. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10629. {
  10630. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10632. }
  10633. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10634. {
  10635. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10636. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10637. }
  10638. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10639. {
  10640. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10641. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10642. }
  10643. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10644. {
  10645. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10646. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10647. }
  10648. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10649. {
  10650. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10651. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10652. }
  10653. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10654. {
  10655. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10656. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10657. }
  10658. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10659. {
  10660. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10661. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10662. }
  10663. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10664. {
  10665. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10666. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10667. }
  10668. }
  10669. fclose(fp);
  10670. }
  10671. return 0;
  10672. }
  10673. void StoreConfigurationTable(void)
  10674. {
  10675. FILE *outfile;
  10676. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10677. if(outfile == NULL)
  10678. {
  10679. DEBUG_INFO("Error opening file");
  10680. return ;
  10681. }
  10682. /*Core Profile*/
  10683. //AllowOfflineTxForUnknownId
  10684. /*
  10685. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10686. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10687. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10689. */
  10690. //DEBUG_INFO("data=%s\n",data);
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10692. //AuthorizationCacheEnabled
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10699. //AuthorizeRemoteTxRequests
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10706. //BlinkRepeat
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10713. //ClockAlignedDataInterval
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10720. //ConnectionTimeOut
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10725. */
  10726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10727. //GetConfigurationMaxKeys
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10734. // HeartbeatInterval
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10741. // LightIntensity
  10742. /*
  10743. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10744. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10746. */
  10747. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10748. // LocalAuthorizeOffline
  10749. /*
  10750. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10751. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10753. */
  10754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10755. // LocalPreAuthorize
  10756. /*
  10757. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10760. */
  10761. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10762. // MaxEnergyOnInvalidId
  10763. /*
  10764. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10765. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10767. */
  10768. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10770. // MeterValuesAlignedData
  10771. /*
  10772. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10775. */
  10776. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10777. // MeterValuesAlignedDataMaxLength
  10778. /*
  10779. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10782. */
  10783. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10784. // MeterValuesSampledData
  10785. /*
  10786. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10789. */
  10790. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10791. // MeterValuesSampledDataMaxLength
  10792. /*
  10793. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10796. */
  10797. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10798. // MeterValueSampleInterval
  10799. /*
  10800. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10801. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10803. */
  10804. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10805. // MinimumStatusDuration
  10806. /*
  10807. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10810. */
  10811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10812. // NumberOfConnectors
  10813. /*
  10814. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10816. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10817. {
  10818. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10819. }
  10820. else
  10821. {
  10822. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10823. }
  10824. */
  10825. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10826. // ResetRetries
  10827. /*
  10828. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10831. */
  10832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10833. // ConnectorPhaseRotation
  10834. /*
  10835. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10837. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10838. */
  10839. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10840. // ConnectorPhaseRotationMaxLength
  10841. /*
  10842. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10845. */
  10846. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10847. // StopTransactionOnEVSideDisconnect
  10848. /*
  10849. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10851. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10852. */
  10853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10854. // StopTransactionOnInvalidId
  10855. /*
  10856. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10859. */
  10860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10861. // StopTxnAlignedData
  10862. /*
  10863. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10865. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10866. */
  10867. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10868. // StopTxnAlignedDataMaxLength
  10869. /*
  10870. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10871. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10873. */
  10874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10875. // StopTxnSampledData
  10876. /*
  10877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10880. */
  10881. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10882. // StopTxnSampledDataMaxLength
  10883. /*
  10884. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10885. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10886. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10887. */
  10888. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10889. // SupportedFeatureProfiles
  10890. /*
  10891. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10894. */
  10895. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10896. // SupportedFeatureProfilesMaxLength
  10897. /*
  10898. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10899. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10901. */
  10902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10903. // TransactionMessageAttempts
  10904. /*
  10905. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10908. */
  10909. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10910. // TransactionMessageRetryInterval
  10911. /*
  10912. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10915. */
  10916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10917. // UnlockConnectorOnEVSideDisconnect
  10918. /*
  10919. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10922. */
  10923. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10924. // WebSocketPingInterval
  10925. /*
  10926. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10928. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10929. */
  10930. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10931. // QueueOffLineStartTransactionMessage
  10932. /*
  10933. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10936. */
  10937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10938. // AuthorizationKey
  10939. /*
  10940. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10942. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10943. */
  10944. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10945. // SecurityProfile
  10946. /*
  10947. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10948. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10949. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10950. */
  10951. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10952. // DefaultPrice
  10953. /*
  10954. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10957. */
  10958. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10959. // CustomDisplayCostAndPrice
  10960. /*
  10961. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10962. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10964. */
  10965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10966. // CustomIdleFeeAfterStop
  10967. /*
  10968. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10970. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10971. */
  10972. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10973. //* Local Auth List Management Profile*/
  10974. //LocalAuthListEnabled
  10975. /*
  10976. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10979. */
  10980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10981. //LocalAuthListMaxLength
  10982. /*
  10983. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10986. */
  10987. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10988. //SendLocalListMaxLength
  10989. /*
  10990. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10991. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10993. */
  10994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10995. //ReserveConnectorZeroSupported
  10996. /*
  10997. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10999. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  11000. */
  11001. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11002. //* Smart Charging Profile */
  11003. //ChargeProfileMaxStackLevel
  11004. /*
  11005. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  11006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  11007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  11008. */
  11009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11010. // ChargingScheduleAllowedChargingRateUnit
  11011. /*
  11012. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  11013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  11014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  11015. */
  11016. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11017. // ChargingScheduleMaxPeriods
  11018. /*
  11019. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  11020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  11021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  11022. */
  11023. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11024. // ConnectorSwitch3to1PhaseSupported
  11025. /*
  11026. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  11027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  11028. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  11029. */
  11030. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11031. // MaxChargingProfilesInstalled
  11032. /*
  11033. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  11034. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  11035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  11036. */
  11037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11038. fclose(outfile);
  11039. }
  11040. void getKeyValue(char *keyReq)
  11041. {
  11042. int isEmpty = FALSE;
  11043. int isKnowKey = FALSE;
  11044. DEBUG_INFO("keyReq = %s\n", keyReq);
  11045. if((keyReq == NULL) || (strlen(keyReq) == 0))
  11046. isEmpty = TRUE;
  11047. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  11048. {
  11049. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  11051. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11052. {
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  11054. }
  11055. else
  11056. {
  11057. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  11058. }
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  11060. isKnowKey = TRUE;
  11061. }
  11062. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  11063. {
  11064. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  11066. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11067. {
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  11069. }
  11070. else
  11071. {
  11072. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  11073. }
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  11075. isKnowKey = TRUE;
  11076. }
  11077. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  11078. {
  11079. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  11081. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11082. {
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  11084. }
  11085. else
  11086. {
  11087. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  11088. }
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  11090. isKnowKey = TRUE;
  11091. }
  11092. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  11093. {
  11094. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  11096. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11097. {
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  11099. }
  11100. else
  11101. {
  11102. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  11103. }
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  11105. isKnowKey = TRUE;
  11106. }
  11107. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  11108. {
  11109. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  11111. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11112. {
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  11114. }
  11115. else
  11116. {
  11117. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  11118. }
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  11120. isKnowKey = TRUE;
  11121. }
  11122. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  11123. {
  11124. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  11126. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11127. {
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  11129. }
  11130. else
  11131. {
  11132. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  11133. }
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  11135. isKnowKey = TRUE;
  11136. }
  11137. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  11138. {
  11139. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  11141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11142. {
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  11144. }
  11145. else
  11146. {
  11147. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  11148. }
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  11150. isKnowKey = TRUE;
  11151. }
  11152. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  11153. {
  11154. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  11156. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11157. {
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  11159. }
  11160. else
  11161. {
  11162. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  11163. }
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  11165. isKnowKey = TRUE;
  11166. }
  11167. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  11168. {
  11169. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  11171. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11172. {
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  11174. }
  11175. else
  11176. {
  11177. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  11178. }
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  11180. isKnowKey = TRUE;
  11181. }
  11182. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  11183. {
  11184. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  11186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11187. {
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  11189. }
  11190. else
  11191. {
  11192. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  11193. }
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  11195. isKnowKey = TRUE;
  11196. }
  11197. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  11198. {
  11199. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  11201. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11202. {
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  11204. }
  11205. else
  11206. {
  11207. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  11208. }
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  11210. isKnowKey = TRUE;
  11211. }
  11212. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  11213. {
  11214. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  11216. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11217. {
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11219. }
  11220. else
  11221. {
  11222. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11223. }
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  11225. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  11226. isKnowKey = TRUE;
  11227. }
  11228. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  11229. {
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11232. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11233. {
  11234. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11235. }
  11236. else
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11239. }
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11241. isKnowKey = TRUE;
  11242. }
  11243. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11244. {
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11247. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11248. {
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11250. }
  11251. else
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11254. }
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11256. isKnowKey = TRUE;
  11257. }
  11258. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11259. {
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11262. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11263. {
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11265. }
  11266. else
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11269. }
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11271. isKnowKey = TRUE;
  11272. }
  11273. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11274. {
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11277. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11278. {
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11280. }
  11281. else
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11284. }
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11286. isKnowKey = TRUE;
  11287. }
  11288. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11289. {
  11290. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11292. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11293. {
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11295. }
  11296. else
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11299. }
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11301. isKnowKey = TRUE;
  11302. }
  11303. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11304. {
  11305. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11307. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11308. {
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11310. }
  11311. else
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11314. }
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11316. isKnowKey = TRUE;
  11317. }
  11318. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11319. {
  11320. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11322. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11323. {
  11324. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11325. }
  11326. else
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11329. }
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11331. isKnowKey = TRUE;
  11332. }
  11333. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11337. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11340. }
  11341. else
  11342. {
  11343. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11344. }
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11346. isKnowKey = TRUE;
  11347. }
  11348. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11352. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11355. }
  11356. else
  11357. {
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11359. }
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11361. isKnowKey = TRUE;
  11362. }
  11363. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11366. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11367. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11370. }
  11371. else
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11374. }
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11376. isKnowKey = TRUE;
  11377. }
  11378. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11382. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11385. }
  11386. else
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11389. }
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11391. isKnowKey = TRUE;
  11392. }
  11393. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11397. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11400. }
  11401. else
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11404. }
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11406. isKnowKey = TRUE;
  11407. }
  11408. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11412. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11415. }
  11416. else
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11419. }
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11421. isKnowKey = TRUE;
  11422. }
  11423. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11427. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11430. }
  11431. else
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11434. }
  11435. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11436. isKnowKey = TRUE;
  11437. }
  11438. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11442. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11445. }
  11446. else
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11449. }
  11450. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11451. isKnowKey = TRUE;
  11452. }
  11453. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11457. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11460. }
  11461. else
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11464. }
  11465. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11466. isKnowKey = TRUE;
  11467. }
  11468. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11472. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11475. }
  11476. else
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11479. }
  11480. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11481. isKnowKey = TRUE;
  11482. }
  11483. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11487. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11490. }
  11491. else
  11492. {
  11493. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11494. }
  11495. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11496. isKnowKey = TRUE;
  11497. }
  11498. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11501. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11502. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11505. }
  11506. else
  11507. {
  11508. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11509. }
  11510. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11511. isKnowKey = TRUE;
  11512. }
  11513. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11516. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11517. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11520. }
  11521. else
  11522. {
  11523. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11524. }
  11525. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11526. isKnowKey = TRUE;
  11527. }
  11528. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11531. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11532. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11535. }
  11536. else
  11537. {
  11538. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11539. }
  11540. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11541. isKnowKey = TRUE;
  11542. }
  11543. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11546. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11547. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11550. }
  11551. else
  11552. {
  11553. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11554. }
  11555. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11556. isKnowKey = TRUE;
  11557. }
  11558. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11559. {
  11560. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11561. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11562. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11563. {
  11564. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11565. }
  11566. else
  11567. {
  11568. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11569. }
  11570. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11571. isKnowKey = TRUE;
  11572. }
  11573. /*
  11574. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11575. {
  11576. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11577. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11578. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11579. {
  11580. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11581. }
  11582. else
  11583. {
  11584. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11585. }
  11586. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11587. isKnowKey = TRUE;
  11588. }*/
  11589. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11590. {
  11591. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11592. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11594. {
  11595. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11596. }
  11597. else
  11598. {
  11599. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11600. }
  11601. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11602. isKnowKey = TRUE;
  11603. }
  11604. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11605. {
  11606. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11607. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11608. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11609. {
  11610. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11611. }
  11612. else
  11613. {
  11614. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11615. }
  11616. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11617. isKnowKey = TRUE;
  11618. }
  11619. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11620. {
  11621. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11622. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11623. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11624. {
  11625. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11626. }
  11627. else
  11628. {
  11629. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11630. }
  11631. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11632. isKnowKey = TRUE;
  11633. }
  11634. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11635. {
  11636. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11637. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11638. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11639. {
  11640. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11641. }
  11642. else
  11643. {
  11644. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11645. }
  11646. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11647. isKnowKey = TRUE;
  11648. }
  11649. #if 1
  11650. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11651. {
  11652. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11653. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11654. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11655. {
  11656. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11657. }
  11658. else
  11659. {
  11660. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11661. }
  11662. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11663. isKnowKey = TRUE;
  11664. }
  11665. #endif
  11666. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11667. {
  11668. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11669. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11670. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11671. {
  11672. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11673. }
  11674. else
  11675. {
  11676. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11677. }
  11678. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11679. isKnowKey = TRUE;
  11680. }
  11681. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11682. {
  11683. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11684. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11685. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11686. {
  11687. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11688. }
  11689. else
  11690. {
  11691. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11692. }
  11693. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11694. isKnowKey = TRUE;
  11695. }
  11696. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11697. {
  11698. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11699. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11700. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11701. {
  11702. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11703. }
  11704. else
  11705. {
  11706. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11707. }
  11708. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11709. isKnowKey = TRUE;
  11710. }
  11711. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11712. {
  11713. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11714. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11715. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11716. {
  11717. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11718. }
  11719. else
  11720. {
  11721. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11722. }
  11723. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11724. isKnowKey = TRUE;
  11725. }
  11726. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11727. {
  11728. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11729. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11730. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11731. {
  11732. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11733. }
  11734. else
  11735. {
  11736. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11737. }
  11738. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11739. isKnowKey = TRUE;
  11740. }
  11741. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11742. {
  11743. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11744. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11745. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11746. {
  11747. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11748. }
  11749. else
  11750. {
  11751. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11752. }
  11753. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11754. isKnowKey = TRUE;
  11755. }
  11756. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11757. {
  11758. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11759. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11760. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11761. {
  11762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11763. }
  11764. else
  11765. {
  11766. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11767. }
  11768. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11769. isKnowKey = TRUE;
  11770. }
  11771. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11772. {
  11773. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11774. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11775. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11776. {
  11777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11778. }
  11779. else
  11780. {
  11781. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11782. }
  11783. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11784. isKnowKey = TRUE;
  11785. }
  11786. //=========================================================
  11787. if(!isEmpty && !isKnowKey)
  11788. {
  11789. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11790. strcpy(unknownkey[UnknownKeynum], keyReq);
  11791. UnknownKeynum = UnknownKeynum + 1;
  11792. }
  11793. }
  11794. void processUnkownKey(void)
  11795. {
  11796. DEBUG_INFO("processUnkownKey...\n");
  11797. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11798. for(int index=0; index < UnknownKeynum; index++)
  11799. {
  11800. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11801. {
  11802. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11803. }
  11804. }
  11805. }
  11806. int setKeyValue(char *key, char *value)
  11807. {
  11808. int isSuccess = NotSupported;
  11809. int check_ascii=0;
  11810. char str[10]={0};
  11811. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11812. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11813. {
  11814. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11815. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11816. {
  11817. strcpy(str, (const char*)value);
  11818. for(int i = 0; str[i]; i++){
  11819. str[i] = tolower(str[i]);
  11820. }
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. else
  11825. {
  11826. isSuccess = ConfigurationStatus_Rejected;
  11827. }
  11828. }
  11829. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11830. {
  11831. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11833. {
  11834. strcpy(str, (const char*)value);
  11835. for(int i = 0; str[i]; i++){
  11836. str[i] = tolower(str[i]);
  11837. }
  11838. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11839. isSuccess = ConfigurationStatus_Accepted;
  11840. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11841. }
  11842. else
  11843. {
  11844. isSuccess = ConfigurationStatus_Rejected;
  11845. }
  11846. }
  11847. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11848. {
  11849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11850. {
  11851. strcpy(str, (const char*)value);
  11852. for(int i = 0; str[i]; i++)
  11853. {
  11854. str[i] = tolower(str[i]);
  11855. }
  11856. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11858. isSuccess = ConfigurationStatus_Accepted;
  11859. }
  11860. else
  11861. {
  11862. isSuccess = ConfigurationStatus_Rejected;
  11863. }
  11864. }
  11865. if(strcmp(key, "BlinkRepeat") == 0)
  11866. {
  11867. //Charger.BlinkRepeat = Integer.parseInt(value);
  11868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11869. {
  11870. check_ascii = value[0];
  11871. if( (check_ascii < 48) || (check_ascii > 57) )
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. else
  11876. {
  11877. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11878. isSuccess = ConfigurationStatus_Accepted;
  11879. }
  11880. }
  11881. else
  11882. {
  11883. isSuccess = ConfigurationStatus_Rejected;
  11884. }
  11885. }
  11886. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11887. {
  11888. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11889. {
  11890. check_ascii = value[0];
  11891. if( (check_ascii < 48) || (check_ascii > 57) )
  11892. {
  11893. isSuccess = ConfigurationStatus_Rejected;
  11894. }
  11895. else
  11896. {
  11897. if((atoi(value) == 0) || (atoi(value) >= 10))
  11898. {
  11899. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11900. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11901. isSuccess = ConfigurationStatus_Accepted;
  11902. }
  11903. else
  11904. isSuccess = ConfigurationStatus_Rejected;
  11905. }
  11906. }
  11907. else
  11908. {
  11909. isSuccess = ConfigurationStatus_Rejected;
  11910. }
  11911. }
  11912. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11913. {
  11914. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11915. {
  11916. check_ascii = value[0];
  11917. if( (check_ascii < 48) || (check_ascii > 57) )
  11918. {
  11919. isSuccess = ConfigurationStatus_Rejected;
  11920. }
  11921. else
  11922. {
  11923. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11924. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11925. isSuccess = ConfigurationStatus_Accepted;
  11926. }
  11927. }
  11928. else
  11929. {
  11930. isSuccess = ConfigurationStatus_Rejected;
  11931. }
  11932. }
  11933. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11934. {
  11935. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11936. {
  11937. check_ascii = value[0];
  11938. if( (check_ascii < 48) || (check_ascii > 57) )
  11939. {
  11940. isSuccess = ConfigurationStatus_Rejected;
  11941. }
  11942. else
  11943. {
  11944. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11946. isSuccess = ConfigurationStatus_Accepted;
  11947. }
  11948. }
  11949. else
  11950. {
  11951. isSuccess = ConfigurationStatus_Rejected;
  11952. }
  11953. }
  11954. if(strcmp(key, "HeartbeatInterval") == 0)
  11955. {
  11956. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11957. {
  11958. check_ascii = value[0];
  11959. if( (check_ascii < 48) || (check_ascii > 57) )
  11960. {
  11961. isSuccess = ConfigurationStatus_Rejected;
  11962. }
  11963. else
  11964. {
  11965. if((atoi(value) == 0) || (atoi(value) >= 10))
  11966. {
  11967. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11968. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11969. HeartBeatWaitTime = atoi(value);
  11970. isSuccess = ConfigurationStatus_Accepted;
  11971. }
  11972. else
  11973. {
  11974. isSuccess = ConfigurationStatus_Rejected;
  11975. }
  11976. }
  11977. }
  11978. else
  11979. {
  11980. isSuccess = ConfigurationStatus_Rejected;
  11981. }
  11982. }
  11983. if(strcmp(key, "LightIntensity") == 0)
  11984. {
  11985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11986. {
  11987. check_ascii = value[0];
  11988. if( (check_ascii < 48) || (check_ascii > 57) )
  11989. {
  11990. isSuccess = ConfigurationStatus_Rejected;
  11991. }
  11992. else
  11993. {
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. }
  11998. else
  11999. {
  12000. isSuccess = ConfigurationStatus_Rejected;
  12001. }
  12002. }
  12003. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  12004. {
  12005. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  12006. {
  12007. strcpy(str, (const char*)value);
  12008. for(int i = 0; str[i]; i++)
  12009. {
  12010. str[i] = tolower(str[i]);
  12011. }
  12012. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12013. isSuccess = ConfigurationStatus_Accepted;
  12014. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  12015. }
  12016. else
  12017. {
  12018. isSuccess = ConfigurationStatus_Rejected;
  12019. }
  12020. }
  12021. if(strcmp(key, "LocalPreAuthorize") == 0)
  12022. {
  12023. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  12024. {
  12025. strcpy(str, (const char*)value);
  12026. for(int i = 0; str[i]; i++)
  12027. {
  12028. str[i] = tolower(str[i]);
  12029. }
  12030. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12031. isSuccess = ConfigurationStatus_Accepted;
  12032. }
  12033. else
  12034. {
  12035. isSuccess = ConfigurationStatus_Rejected;
  12036. }
  12037. }
  12038. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  12039. {
  12040. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  12041. {
  12042. check_ascii = value[0];
  12043. if( (check_ascii < 48) || (check_ascii > 57) )
  12044. {
  12045. isSuccess = ConfigurationStatus_Rejected;
  12046. }
  12047. else
  12048. {
  12049. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  12050. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  12051. isSuccess = ConfigurationStatus_Accepted;
  12052. }
  12053. }
  12054. else
  12055. {
  12056. isSuccess = ConfigurationStatus_Rejected;
  12057. }
  12058. }
  12059. if(strcmp(key, "MeterValuesAlignedData") == 0)
  12060. {
  12061. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  12062. {
  12063. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  12064. isSuccess = ConfigurationStatus_Accepted;
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  12074. {
  12075. check_ascii = value[0];
  12076. if( (check_ascii < 48) || (check_ascii > 57) )
  12077. {
  12078. isSuccess = ConfigurationStatus_Rejected;
  12079. }
  12080. else
  12081. {
  12082. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12083. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  12084. isSuccess = ConfigurationStatus_Accepted;
  12085. }
  12086. }
  12087. else
  12088. {
  12089. isSuccess = ConfigurationStatus_Rejected;
  12090. }
  12091. }
  12092. if(strcmp(key, "MeterValuesSampledData") == 0 )
  12093. {
  12094. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  12095. {
  12096. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  12097. isSuccess = ConfigurationStatus_Accepted;
  12098. }
  12099. else
  12100. {
  12101. isSuccess = ConfigurationStatus_Rejected;
  12102. }
  12103. }
  12104. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  12105. {
  12106. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  12107. {
  12108. check_ascii = value[0];
  12109. if( (check_ascii < 48) || (check_ascii > 57) )
  12110. {
  12111. isSuccess = ConfigurationStatus_Rejected;
  12112. }
  12113. else
  12114. {
  12115. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12116. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  12117. isSuccess = ConfigurationStatus_Accepted;
  12118. }
  12119. }
  12120. else
  12121. {
  12122. isSuccess = ConfigurationStatus_Rejected;
  12123. }
  12124. }
  12125. if(strcmp(key, "MeterValueSampleInterval") == 0)
  12126. {
  12127. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  12128. {
  12129. check_ascii = value[0];
  12130. if( (check_ascii < 48) || (check_ascii > 57) )
  12131. {
  12132. isSuccess = ConfigurationStatus_Rejected;
  12133. }
  12134. else
  12135. {
  12136. if((atoi(value) == 0) || (atoi(value) >= 10))
  12137. {
  12138. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  12139. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  12140. isSuccess = ConfigurationStatus_Accepted;
  12141. }
  12142. else
  12143. {
  12144. isSuccess = ConfigurationStatus_Rejected;
  12145. }
  12146. }
  12147. }
  12148. else
  12149. {
  12150. isSuccess = ConfigurationStatus_Rejected;
  12151. }
  12152. }
  12153. if(strcmp(key, "MinimumStatusDuration") == 0)
  12154. {
  12155. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  12156. {
  12157. check_ascii = value[0];
  12158. if( (check_ascii < 48) || (check_ascii > 57) )
  12159. {
  12160. isSuccess = ConfigurationStatus_Rejected;
  12161. }
  12162. else
  12163. {
  12164. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  12165. {
  12166. isSuccess = ConfigurationStatus_Rejected;
  12167. }
  12168. else
  12169. {
  12170. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  12171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  12172. server_cycle_Status = atoi(value); //StatusNotification Cycle
  12173. isSuccess = ConfigurationStatus_Accepted;
  12174. }
  12175. }
  12176. }
  12177. else
  12178. {
  12179. isSuccess = ConfigurationStatus_Rejected;
  12180. }
  12181. }
  12182. if(strcmp(key, "NumberOfConnectors") == 0)
  12183. {
  12184. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  12185. {
  12186. check_ascii = value[0];
  12187. if( (check_ascii < 48) || (check_ascii > 57) )
  12188. {
  12189. isSuccess = ConfigurationStatus_Rejected;
  12190. }
  12191. else
  12192. {
  12193. //Charger.ResetRetries = Integer.parseInt(value);
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. }
  12198. else
  12199. {
  12200. isSuccess = ConfigurationStatus_Rejected;
  12201. }
  12202. }
  12203. if(strcmp(key, "ResetRetries") == 0)
  12204. {
  12205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  12206. {
  12207. check_ascii = value[0];
  12208. if( (check_ascii < 48) || (check_ascii > 57) )
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. else
  12213. {
  12214. //Charger.ResetRetries = Integer.parseInt(value);
  12215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  12216. isSuccess = ConfigurationStatus_Accepted;
  12217. }
  12218. }
  12219. else
  12220. {
  12221. isSuccess = ConfigurationStatus_Rejected;
  12222. }
  12223. }
  12224. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  12225. {
  12226. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  12227. {
  12228. strcpy(str, (const char*)value);
  12229. for(int i = 0; str[i]; i++)
  12230. {
  12231. str[i] = tolower(str[i]);
  12232. }
  12233. if(strcmp(str, "notapplicable")== 0)
  12234. {
  12235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12236. isSuccess = ConfigurationStatus_Accepted;
  12237. }
  12238. else if(strcmp(str, "unknown")== 0)
  12239. {
  12240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12241. isSuccess = ConfigurationStatus_Accepted;
  12242. }
  12243. else if(strcmp(str, "rst")== 0)
  12244. {
  12245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12246. isSuccess = ConfigurationStatus_Accepted;
  12247. }
  12248. else if(strcmp(str, "rts")== 0)
  12249. {
  12250. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12251. isSuccess = ConfigurationStatus_Accepted;
  12252. }
  12253. else if(strcmp(str, "srt")== 0)
  12254. {
  12255. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12256. isSuccess = ConfigurationStatus_Accepted;
  12257. }
  12258. else if(strcmp(str, "str")== 0)
  12259. {
  12260. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12261. isSuccess = ConfigurationStatus_Accepted;
  12262. }
  12263. else if(strcmp(str, "trs")== 0)
  12264. {
  12265. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12266. isSuccess = ConfigurationStatus_Accepted;
  12267. }
  12268. else if(strcmp(str, "tsr")== 0)
  12269. {
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. else
  12274. {
  12275. isSuccess = ConfigurationStatus_Rejected;
  12276. }
  12277. }
  12278. else
  12279. {
  12280. isSuccess = ConfigurationStatus_Rejected;
  12281. }
  12282. }
  12283. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12284. {
  12285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12286. {
  12287. check_ascii = value[0];
  12288. if( (check_ascii < 48) || (check_ascii > 57) )
  12289. {
  12290. isSuccess = ConfigurationStatus_Rejected;
  12291. }
  12292. else
  12293. {
  12294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12295. isSuccess = ConfigurationStatus_Accepted;
  12296. }
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12304. {
  12305. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12306. {
  12307. strcpy(str, (const char*)value);
  12308. for(int i = 0; str[i]; i++)
  12309. {
  12310. str[i] = tolower(str[i]);
  12311. }
  12312. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12313. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12314. isSuccess = ConfigurationStatus_Accepted;
  12315. }
  12316. else
  12317. {
  12318. isSuccess = ConfigurationStatus_Rejected;
  12319. }
  12320. }
  12321. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12322. {
  12323. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12324. {
  12325. strcpy(str, (const char*)value);
  12326. for(int i = 0; str[i]; i++)
  12327. {
  12328. str[i] = tolower(str[i]);
  12329. }
  12330. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12332. isSuccess = ConfigurationStatus_Accepted;
  12333. }
  12334. else
  12335. {
  12336. isSuccess = ConfigurationStatus_Rejected;
  12337. }
  12338. }
  12339. if(strcmp(key, "StopTxnAlignedData") == 0)
  12340. {
  12341. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12342. {
  12343. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12344. isSuccess = ConfigurationStatus_Accepted;
  12345. }
  12346. else
  12347. {
  12348. isSuccess = ConfigurationStatus_Rejected;
  12349. }
  12350. }
  12351. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12352. {
  12353. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12354. {
  12355. check_ascii = value[0];
  12356. if( (check_ascii < 48) || (check_ascii > 57) )
  12357. {
  12358. isSuccess = ConfigurationStatus_Rejected;
  12359. }
  12360. else
  12361. {
  12362. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12363. isSuccess = ConfigurationStatus_Accepted;
  12364. }
  12365. }
  12366. else
  12367. {
  12368. isSuccess = ConfigurationStatus_Rejected;
  12369. }
  12370. }
  12371. if(strcmp(key, "StopTxnSampledData") == 0)
  12372. {
  12373. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12374. {
  12375. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12376. isSuccess = ConfigurationStatus_Accepted;
  12377. }
  12378. else
  12379. {
  12380. isSuccess = ConfigurationStatus_Rejected;
  12381. }
  12382. }
  12383. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12384. {
  12385. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12386. {
  12387. check_ascii = value[0];
  12388. if( (check_ascii < 48) || (check_ascii > 57) )
  12389. {
  12390. isSuccess = ConfigurationStatus_Rejected;
  12391. }
  12392. else
  12393. {
  12394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12395. isSuccess = ConfigurationStatus_Accepted;
  12396. }
  12397. }
  12398. else
  12399. {
  12400. isSuccess = ConfigurationStatus_Rejected;
  12401. }
  12402. }
  12403. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12404. {
  12405. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12406. {
  12407. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12408. isSuccess = ConfigurationStatus_Accepted;
  12409. }
  12410. else
  12411. {
  12412. isSuccess = ConfigurationStatus_Rejected;
  12413. }
  12414. }
  12415. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12416. {
  12417. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12418. {
  12419. check_ascii = value[0];
  12420. if( (check_ascii < 48) || (check_ascii > 57) )
  12421. {
  12422. isSuccess = ConfigurationStatus_Rejected;
  12423. }
  12424. else
  12425. {
  12426. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12427. isSuccess = ConfigurationStatus_Accepted;
  12428. }
  12429. }
  12430. else
  12431. {
  12432. isSuccess = ConfigurationStatus_Rejected;
  12433. }
  12434. }
  12435. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12436. {
  12437. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12438. {
  12439. check_ascii = value[0];
  12440. if( (check_ascii < 48) || (check_ascii > 57) )
  12441. {
  12442. isSuccess = ConfigurationStatus_Rejected;
  12443. }
  12444. else
  12445. {
  12446. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12447. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12448. TransactionMessageAttemptsValue = atoi(value);
  12449. isSuccess = ConfigurationStatus_Accepted;
  12450. }
  12451. }
  12452. else
  12453. {
  12454. isSuccess = ConfigurationStatus_Rejected;
  12455. }
  12456. }
  12457. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12458. {
  12459. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12460. {
  12461. check_ascii = value[0];
  12462. if( (check_ascii < 48) || (check_ascii > 57) )
  12463. {
  12464. isSuccess = ConfigurationStatus_Rejected;
  12465. }
  12466. else
  12467. {
  12468. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12469. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12470. TransactionMessageRetryIntervalValue = atoi(value);
  12471. isSuccess = ConfigurationStatus_Accepted;
  12472. }
  12473. }
  12474. else
  12475. {
  12476. isSuccess = ConfigurationStatus_Rejected;
  12477. }
  12478. }
  12479. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12480. {
  12481. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12482. {
  12483. strcpy(str, (const char*)value);
  12484. for(int i = 0; str[i]; i++)
  12485. {
  12486. str[i] = tolower(str[i]);
  12487. }
  12488. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12489. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12490. isSuccess = ConfigurationStatus_Accepted;
  12491. }
  12492. else
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. }
  12497. if(strcmp(key, "WebSocketPingInterval") == 0)
  12498. {
  12499. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12500. {
  12501. check_ascii = value[0];
  12502. if( (check_ascii < 48) || (check_ascii > 57) )
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. else
  12507. {
  12508. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12509. isSuccess = ConfigurationStatus_Accepted;
  12510. }
  12511. }
  12512. else
  12513. {
  12514. isSuccess = ConfigurationStatus_Rejected;
  12515. }
  12516. }
  12517. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12518. {
  12519. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12520. {
  12521. strcpy(str, (const char*)value);
  12522. for(int i = 0; str[i]; i++)
  12523. {
  12524. str[i] = tolower(str[i]);
  12525. }
  12526. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12528. isSuccess = ConfigurationStatus_Accepted;
  12529. }
  12530. else
  12531. {
  12532. isSuccess = ConfigurationStatus_Rejected;
  12533. }
  12534. }
  12535. if(strcmp(key, "AuthorizationKey") == 0)
  12536. {
  12537. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12538. {
  12539. strcpy(str, (const char*)value);
  12540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12541. isSuccess = ConfigurationStatus_Accepted;
  12542. }
  12543. else
  12544. {
  12545. isSuccess = ConfigurationStatus_Rejected;
  12546. }
  12547. }
  12548. if(strcmp(key, "SecurityProfile") == 0)
  12549. {
  12550. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12551. {
  12552. check_ascii = value[0];
  12553. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12554. {
  12555. isSuccess = ConfigurationStatus_Rejected;
  12556. }
  12557. else if(check_ascii == 0x33)
  12558. {
  12559. isSuccess = NotSupported;
  12560. }
  12561. else
  12562. {
  12563. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12564. {
  12565. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12566. isSuccess = ConfigurationStatus_Accepted;
  12567. }
  12568. else
  12569. isSuccess = ConfigurationStatus_Rejected;
  12570. }
  12571. }
  12572. else
  12573. {
  12574. isSuccess = ConfigurationStatus_Rejected;
  12575. }
  12576. }
  12577. if(strcmp(key, "DefaultPrice") == 0)
  12578. {
  12579. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12580. {
  12581. strcpy(str, (const char*)value);
  12582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12583. isSuccess = ConfigurationStatus_Accepted;
  12584. }
  12585. else
  12586. {
  12587. isSuccess = ConfigurationStatus_Rejected;
  12588. }
  12589. }
  12590. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12591. {
  12592. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12593. {
  12594. strcpy(str, (const char*)value);
  12595. for(int i = 0; str[i]; i++)
  12596. {
  12597. str[i] = tolower(str[i]);
  12598. }
  12599. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12600. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12601. isSuccess = ConfigurationStatus_Accepted;
  12602. }
  12603. else
  12604. {
  12605. isSuccess = ConfigurationStatus_Rejected;
  12606. }
  12607. }
  12608. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12609. {
  12610. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12611. {
  12612. strcpy(str, (const char*)value);
  12613. for(int i = 0; str[i]; i++)
  12614. {
  12615. str[i] = tolower(str[i]);
  12616. }
  12617. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12618. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12619. isSuccess = ConfigurationStatus_Accepted;
  12620. }
  12621. else
  12622. {
  12623. isSuccess = ConfigurationStatus_Rejected;
  12624. }
  12625. }
  12626. #if 0
  12627. //For OCPP Test Case
  12628. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12629. {
  12630. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12631. {
  12632. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12633. isSuccess = ConfigurationStatus_Accepted;
  12634. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12635. }
  12636. else
  12637. {
  12638. isSuccess = ConfigurationStatus_Rejected;
  12639. }
  12640. }
  12641. #endif
  12642. #if 1
  12643. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12644. {
  12645. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12646. {
  12647. strcpy(str, (const char*)value);
  12648. for(int i = 0; str[i]; i++)
  12649. {
  12650. str[i] = tolower(str[i]);
  12651. }
  12652. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12653. isSuccess = ConfigurationStatus_Accepted;
  12654. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12655. }
  12656. else
  12657. {
  12658. isSuccess = ConfigurationStatus_Rejected;
  12659. }
  12660. }
  12661. #endif
  12662. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12663. {
  12664. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12665. {
  12666. check_ascii = value[0];
  12667. if( (check_ascii < 48) || (check_ascii > 57) )
  12668. {
  12669. isSuccess = ConfigurationStatus_Rejected;
  12670. }
  12671. else
  12672. {
  12673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12674. isSuccess = ConfigurationStatus_Accepted;
  12675. }
  12676. }
  12677. else
  12678. {
  12679. isSuccess = ConfigurationStatus_Rejected;
  12680. }
  12681. }
  12682. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12683. {
  12684. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12685. {
  12686. check_ascii = value[0];
  12687. if( (check_ascii < 48) || (check_ascii > 57) )
  12688. {
  12689. isSuccess = ConfigurationStatus_Rejected;
  12690. }
  12691. else
  12692. {
  12693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12694. isSuccess = ConfigurationStatus_Accepted;
  12695. }
  12696. }
  12697. else
  12698. {
  12699. isSuccess = ConfigurationStatus_Rejected;
  12700. }
  12701. }
  12702. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12703. {
  12704. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12705. {
  12706. strcpy(str, (const char*)value);
  12707. for(int i = 0; str[i]; i++)
  12708. {
  12709. str[i] = tolower(str[i]);
  12710. }
  12711. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12712. isSuccess = ConfigurationStatus_Accepted;
  12713. }
  12714. else
  12715. {
  12716. isSuccess = ConfigurationStatus_Rejected;
  12717. }
  12718. }
  12719. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12720. {
  12721. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12722. {
  12723. check_ascii = value[0];
  12724. if( (check_ascii < 48) || (check_ascii > 57) )
  12725. {
  12726. isSuccess = ConfigurationStatus_Rejected;
  12727. }
  12728. else
  12729. {
  12730. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12731. isSuccess = ConfigurationStatus_Accepted;
  12732. }
  12733. }
  12734. else
  12735. {
  12736. isSuccess = ConfigurationStatus_Rejected;
  12737. }
  12738. }
  12739. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12740. {
  12741. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12742. {
  12743. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12744. isSuccess = ConfigurationStatus_Accepted;
  12745. }
  12746. else
  12747. {
  12748. isSuccess = ConfigurationStatus_Rejected;
  12749. }
  12750. }
  12751. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12752. {
  12753. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12754. {
  12755. check_ascii = value[0];
  12756. if( (check_ascii < 48) || (check_ascii > 57) )
  12757. {
  12758. isSuccess = ConfigurationStatus_Rejected;
  12759. }
  12760. else
  12761. {
  12762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12763. isSuccess = ConfigurationStatus_Accepted;
  12764. }
  12765. }
  12766. else
  12767. {
  12768. isSuccess = ConfigurationStatus_Rejected;
  12769. }
  12770. }
  12771. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12772. {
  12773. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12774. {
  12775. strcpy(str, (const char*)value);
  12776. for(int i = 0; str[i]; i++)
  12777. {
  12778. str[i] = tolower(str[i]);
  12779. }
  12780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12781. isSuccess = ConfigurationStatus_Accepted;
  12782. }
  12783. else
  12784. {
  12785. isSuccess = ConfigurationStatus_Rejected;
  12786. }
  12787. }
  12788. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12789. {
  12790. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12791. {
  12792. check_ascii = value[0];
  12793. if( (check_ascii < 48) || (check_ascii > 57) )
  12794. {
  12795. isSuccess = ConfigurationStatus_Rejected;
  12796. }
  12797. else
  12798. {
  12799. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12800. isSuccess = ConfigurationStatus_Accepted;
  12801. }
  12802. }
  12803. else
  12804. {
  12805. isSuccess = ConfigurationStatus_Rejected;
  12806. }
  12807. }
  12808. return isSuccess;
  12809. }
  12810. int TransactionMessageAttemptsGet(void)
  12811. {
  12812. return TransactionMessageAttemptsValue;
  12813. }
  12814. int FirstHeartBeatResponse(void)
  12815. {
  12816. return FirstHeartBeat;
  12817. }
  12818. int TransactionMessageRetryIntervalGet(void)
  12819. {
  12820. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12821. }
  12822. int ReadHttpStatus(int sock)
  12823. {
  12824. //char c;
  12825. char buff[1024]="",*ptr=buff+1;
  12826. int bytes_received, status;
  12827. DEBUG_INFO("Begin Response ..\n");
  12828. while((bytes_received = recv(sock, ptr, 1, 0))){
  12829. if(bytes_received==-1){
  12830. perror("ReadHttpStatus");
  12831. exit(1);
  12832. }
  12833. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12834. ptr++;
  12835. }
  12836. *ptr=0;
  12837. ptr=buff+1;
  12838. sscanf(ptr,"%*s %d ", &status);
  12839. DEBUG_INFO("%s\n",ptr);
  12840. DEBUG_INFO("status=%d\n",status);
  12841. DEBUG_INFO("End Response ..\n");
  12842. return (bytes_received>0)?status:0;
  12843. }
  12844. //the only filed that it parsed is 'Content-Length'
  12845. int ParseHeader(int sock)
  12846. {
  12847. //char c;
  12848. char buff[1024]="",*ptr=buff+4;
  12849. int bytes_received;
  12850. DEBUG_INFO("Begin HEADER ..\n");
  12851. while((bytes_received = recv(sock, ptr, 1, 0))){
  12852. if(bytes_received==-1){
  12853. perror("Parse Header");
  12854. exit(1);
  12855. }
  12856. if(
  12857. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12858. (ptr[-1]=='\r') && (*ptr=='\n' )
  12859. ) break;
  12860. ptr++;
  12861. }
  12862. *ptr=0;
  12863. ptr=buff+4;
  12864. //printf("%s",ptr);
  12865. if(bytes_received){
  12866. ptr=strstr(ptr,"Content-Length:");
  12867. if(ptr){
  12868. sscanf(ptr,"%*s %d",&bytes_received);
  12869. }else
  12870. bytes_received=-1; //unknown size
  12871. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12872. }
  12873. DEBUG_INFO("End HEADER ..\n");
  12874. return bytes_received ;
  12875. }
  12876. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12877. {
  12878. char rmFileCmd[100]={0};
  12879. char FilePath[100]={0};
  12880. char ftpbuf[200];
  12881. int systemresult;
  12882. //DEBUG_INFO("filename=%s\n",filename);
  12883. //DEBUG_INFO("url=%s\n",url);
  12884. sprintf(FilePath,"/mnt/%s",filename);
  12885. if((access(FilePath,F_OK))!=-1)
  12886. {
  12887. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12888. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12889. system(rmFileCmd);
  12890. }
  12891. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12892. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12893. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12894. systemresult = system(ftpbuf);
  12895. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12896. if(systemresult != 0)
  12897. {
  12898. DEBUG_INFO("http DownLoad error!\n");
  12899. return FALSE;
  12900. }
  12901. return TRUE;
  12902. }
  12903. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12904. {
  12905. char rmFileCmd[100]={0};
  12906. char FilePath[100]={0};
  12907. char ftpbuf[200];
  12908. int systemresult;
  12909. //char temp[100];
  12910. sprintf(FilePath,"/mnt/%s",filename);
  12911. if((access(FilePath,F_OK))!=-1)
  12912. {
  12913. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12914. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12915. system(rmFileCmd);
  12916. }
  12917. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12918. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12919. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12920. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12921. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12922. systemresult = system(ftpbuf);
  12923. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12924. if(systemresult != 0)
  12925. {
  12926. printf("wget error!\n");
  12927. return FALSE;
  12928. }
  12929. return TRUE;
  12930. }
  12931. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12932. {
  12933. char rmFileCmd[100]={0};
  12934. char FilePath[100]={0};
  12935. char ftpbuf[200];
  12936. int systemresult;
  12937. //DEBUG_INFO("filename=%s\n",filename);
  12938. //DEBUG_INFO("url=%s\n",url);
  12939. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12940. if((access(FilePath,F_OK))!=-1)
  12941. {
  12942. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12943. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12944. system(rmFileCmd);
  12945. }
  12946. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12947. if(fp == NULL)
  12948. {
  12949. DEBUG_INFO("log is NULL\n");
  12950. return FALSE;
  12951. }
  12952. else
  12953. {
  12954. fprintf(fp, "%s\n", url);
  12955. fprintf(fp, "%s\n", filename);
  12956. fclose(fp);
  12957. }
  12958. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12959. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12960. systemresult = system(ftpbuf);
  12961. DEBUG_INFO("systemresult = %d\n",systemresult);
  12962. if(systemresult != 0)
  12963. {
  12964. DEBUG_INFO("http upload error!\n");
  12965. return FALSE;
  12966. }
  12967. return TRUE;
  12968. }
  12969. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12970. {
  12971. struct hostent* server;
  12972. char *IPbuffer;
  12973. char ftpbuf[200];
  12974. int systemresult;
  12975. // To retrieve host information
  12976. server = gethostbyname(location);
  12977. // To convert an Internet network
  12978. // address into ASCII string
  12979. IPbuffer = inet_ntoa(*((struct in_addr*)
  12980. server->h_addr_list[0]));
  12981. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12982. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12983. /* format : ftpput -u username -p passwd IP target source*/
  12984. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12985. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12986. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12987. systemresult = system(ftpbuf);
  12988. DEBUG_INFO("systemresult=%d\n",systemresult);
  12989. if(systemresult != 0)
  12990. {
  12991. DEBUG_INFO("ftpput error!\n");
  12992. return FALSE;
  12993. }
  12994. return TRUE;
  12995. }
  12996. /**
  12997. * Place the contents of the specified file into a memory buffer
  12998. *
  12999. * @param[in] filename The path and name of the file to read
  13000. * @param[out] filebuffer A pointer to the contents in memory
  13001. * @return status 0 success, 1 on failure
  13002. */
  13003. int get_file_contents(const char* filename, char** outbuffer) {
  13004. FILE* file = NULL;
  13005. long filesize;
  13006. const int blocksize = 1;
  13007. size_t readsize;
  13008. char* filebuffer;
  13009. // Open the file
  13010. file = fopen(filename, "r");
  13011. if (NULL == file)
  13012. {
  13013. printf("'%s' not opened\n", filename);
  13014. exit(EXIT_FAILURE);
  13015. }
  13016. // Determine the file size
  13017. fseek(file, 0, SEEK_END);
  13018. filesize = ftell(file);
  13019. rewind (file);
  13020. // Allocate memory for the file contents
  13021. filebuffer = (char*) malloc(sizeof(char) * filesize);
  13022. *outbuffer = filebuffer;
  13023. if (filebuffer == NULL)
  13024. {
  13025. fputs ("malloc out-of-memory", stderr);
  13026. exit(EXIT_FAILURE);
  13027. }
  13028. // Read in the file
  13029. readsize = fread(filebuffer, blocksize, filesize, file);
  13030. if (readsize != filesize)
  13031. {
  13032. fputs ("didn't read file completely",stderr);
  13033. exit(EXIT_FAILURE);
  13034. }
  13035. // Clean exit
  13036. fclose(file);
  13037. return EXIT_SUCCESS;
  13038. }
  13039. static int selectSqlCount = 0;
  13040. static int callback(void *data, int argc, char **argv, char **azColName){
  13041. int i;
  13042. //printf("%s: ", (const char*)data);
  13043. selectSqlCount = argc;
  13044. for(i = 0; i<argc; i++){
  13045. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  13046. }
  13047. //printf("\n");
  13048. return 0;
  13049. }
  13050. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  13051. //int i;
  13052. //printf("%s:\n", (const char*)data);
  13053. localversion = argv[5] ? atoi(argv[5]) : 0;
  13054. //printf("localversion=%d\n", localversion);
  13055. return 0;
  13056. }
  13057. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  13058. //int i;
  13059. //printf("%s:\n", (const char*)data);
  13060. //idTag
  13061. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  13062. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  13063. //parentIdTag
  13064. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  13065. //expir_date
  13066. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  13067. //status
  13068. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  13069. //version
  13070. idTagQuery.listVersionInt = atoi(argv[5]);
  13071. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  13072. return 0;
  13073. }
  13074. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  13075. {
  13076. // localversion = argv[5] ? atoi(argv[5]) : 0;
  13077. // printf("localversion=%d\n", localversion);
  13078. return 0;
  13079. }
  13080. //=========================================
  13081. // Sqlite3 related function
  13082. //=========================================
  13083. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  13084. {
  13085. for (int i = 0; i < n_columns; i++)
  13086. {
  13087. DEBUG_INFO("%s\t", col_values[i]);
  13088. }
  13089. DEBUG_INFO("\n");
  13090. return 0;
  13091. }
  13092. void OCPP_getListVerion()
  13093. {
  13094. int rc = 0;
  13095. // const char* data = "Callback function called";
  13096. char sql[100];
  13097. char zErrMsg[100];
  13098. memset(sql, 0, 100);
  13099. memset(zErrMsg, 0, 100);
  13100. strcpy(sql, "select * from ocpp_auth_local order by idx");
  13101. /* Execute SQL statement */
  13102. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  13103. if( rc != SQLITE_OK )
  13104. {
  13105. DEBUG_INFO("SQL error: %s", zErrMsg);
  13106. }
  13107. }
  13108. void OCPP_getIdTag(char idTag[])
  13109. {
  13110. int rc = 0;
  13111. // const char* data = "Callback function called";
  13112. char sql[100];
  13113. char zErrMsg[100];
  13114. memset(sql, 0, 100);
  13115. memset(zErrMsg, 0, 100);
  13116. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  13117. memset(&idTagQuery, 0, sizeof(idTagQuery));
  13118. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  13119. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  13120. /* Execute SQL statement */
  13121. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  13122. if( rc != SQLITE_OK )
  13123. {
  13124. DEBUG_INFO("SQL error: %s", zErrMsg);
  13125. }
  13126. //return ver;
  13127. }
  13128. void OCPP_get_TableAuthlocalAllData(void)
  13129. {
  13130. int rc = 0;
  13131. char sql[100];
  13132. char zErrMsg[100];
  13133. memset(sql, 0, 100);
  13134. memset(zErrMsg, 0, 100);
  13135. sprintf(sql,"select * from ocpp_auth_local ");
  13136. /* Execute SQL statement */
  13137. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  13138. if( rc != SQLITE_OK )
  13139. {
  13140. DEBUG_INFO("SQL error: %s", zErrMsg);
  13141. }
  13142. //return ver;
  13143. }
  13144. int OCPP_cleanLocalList()
  13145. {
  13146. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  13147. char *errMsg = 0;
  13148. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  13149. if (SQLITE_OK != rc)
  13150. {
  13151. DEBUG_INFO("%s\n",errMsg);
  13152. return FALSE;
  13153. }
  13154. return TRUE;
  13155. }
  13156. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  13157. {
  13158. int isSuccess = FALSE;
  13159. int ret = 0;
  13160. //const char* data = "Callback function called";
  13161. char sql[300];
  13162. char zErrMsg[200];
  13163. memset(sql, 0, 300);
  13164. memset(zErrMsg, 0, 200);
  13165. 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);
  13166. //* Execute SQL statement */
  13167. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  13168. if( ret != SQLITE_OK )
  13169. {
  13170. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13171. return isSuccess;
  13172. }
  13173. memset(sql, 0, 300);
  13174. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  13175. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  13176. if( ret != SQLITE_OK )
  13177. {
  13178. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13179. return isSuccess;
  13180. }
  13181. isSuccess = TRUE;
  13182. return isSuccess;
  13183. }
  13184. void OCPP_deleteIdTag(char idTag[])
  13185. {
  13186. //int ver = 0;
  13187. //int isSuccess = FALSE;
  13188. int rc = 0;
  13189. char sql[100];
  13190. char zErrMsg[100];
  13191. memset(sql, 0, 100);
  13192. memset(zErrMsg, 0, 100);
  13193. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13194. //* Execute SQL statement */
  13195. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13196. if( rc != SQLITE_OK )
  13197. {
  13198. DEBUG_INFO("SQL error: %s", zErrMsg);
  13199. }
  13200. }
  13201. int GetOcppServerURL()
  13202. {
  13203. int result = FALSE;
  13204. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13205. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13206. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13207. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13208. {
  13209. #if 1
  13210. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13211. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13212. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13213. #endif
  13214. result = TRUE;
  13215. goto End;
  13216. }
  13217. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13218. {
  13219. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13220. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13221. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  13222. result = TRUE;
  13223. goto End;
  13224. }
  13225. else
  13226. {
  13227. strcpy(OcppHost,"");
  13228. }
  13229. End:
  13230. return result;
  13231. }
  13232. int GetOcppPath()
  13233. {
  13234. int result = FALSE;
  13235. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13236. {
  13237. if(OcppTempPath == NULL)
  13238. {
  13239. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13240. }
  13241. else
  13242. {
  13243. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13244. }
  13245. result = TRUE;
  13246. goto End;
  13247. }
  13248. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13249. {
  13250. if(OcppTempPath == NULL)
  13251. {
  13252. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13253. }
  13254. else
  13255. {
  13256. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13257. }
  13258. result = TRUE;
  13259. goto End;
  13260. }
  13261. else
  13262. {
  13263. strcpy(OcppPath,"");
  13264. }
  13265. End:
  13266. return result;
  13267. }
  13268. int GetOcppPort()
  13269. {
  13270. return OcppPort;
  13271. }
  13272. int GetOcppConnStatus(void)
  13273. {
  13274. return ShmOCPP16Data->OcppConnStatus;
  13275. }
  13276. void SetOcppConnStatus(uint8_t status)
  13277. {
  13278. ShmOCPP16Data->OcppConnStatus = status;
  13279. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13280. }
  13281. int GetHeartBeatWithNOResponse(void)
  13282. {
  13283. return HeartBeatWithNOResponse;
  13284. }
  13285. void SetHeartBeatWithNOResponse(void)
  13286. {
  13287. HeartBeatWithNOResponse = 0;
  13288. }
  13289. void GetStartTransactionIdTag(int gun_index)
  13290. {
  13291. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13292. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13293. }
  13294. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13295. {
  13296. char ch;
  13297. FILE *fptr1;
  13298. int temptransactionId;
  13299. char str[100]={0};
  13300. temptransactionId = 0;
  13301. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13302. {
  13303. DEBUG_INFO("IdTag is empty.\n");
  13304. return temptransactionId;
  13305. }
  13306. /*------ Read the file ----------------*/
  13307. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13308. if (!fptr1)
  13309. {
  13310. DEBUG_INFO("QueueTransactionId file open error.\n");
  13311. //printf(" File not found or unable to open the input file!!\n");
  13312. return temptransactionId;
  13313. }
  13314. ch=fgetc(fptr1);
  13315. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13316. rewind(fptr1);
  13317. if(ch!=EOF)
  13318. {
  13319. // printf("%c",ch);
  13320. while (fgets(str, 100, fptr1) != NULL)
  13321. {
  13322. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13323. if(str[0]=='\0')
  13324. {
  13325. break;
  13326. }
  13327. char *revbuf[8] = {0}; // Variable store string split
  13328. int num = 0;// Quantity after string split
  13329. DEBUG_INFO("Transaction queue data= %s\n", str);
  13330. splitstring(str,",",revbuf,&num); // String split
  13331. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13332. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13333. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13334. DEBUG_INFO("------------------------------\n");
  13335. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13336. {
  13337. if(isStopTransaction)
  13338. {
  13339. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13340. {
  13341. temptransactionId = atoi(revbuf[2]);
  13342. break;
  13343. }
  13344. }
  13345. else
  13346. {
  13347. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13348. {
  13349. temptransactionId = atoi(revbuf[2]);
  13350. break;
  13351. }
  13352. }
  13353. }
  13354. }
  13355. }
  13356. else
  13357. DEBUG_INFO("EOF\n");
  13358. fclose(fptr1);
  13359. /*------- End of reading ---------------*/
  13360. return temptransactionId;
  13361. }
  13362. void SetTransactionIdZero(int transactionId)
  13363. {
  13364. char ch;
  13365. FILE *fptr1, *fptr2;
  13366. int temptransactionId = 0;
  13367. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13368. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13369. if (!fptr1)
  13370. {
  13371. //printf(" File not found or unable to open the input file!!\n");
  13372. return ;
  13373. }
  13374. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13375. if (!fptr2)
  13376. {
  13377. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13378. fclose(fptr1);
  13379. return ;
  13380. }
  13381. ch=fgetc(fptr1);
  13382. rewind(fptr1);
  13383. if(ch!=EOF)
  13384. {
  13385. // copy all contents to the temporary file except the specific line
  13386. while (fgets(str, 100, fptr1) != NULL)
  13387. {
  13388. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13389. if(str[0]=='\0')
  13390. {
  13391. break;
  13392. }
  13393. char *revbuf[8] = {0};
  13394. int num = 0;
  13395. strcpy(strtemp, str);
  13396. splitstring(str,",",revbuf,&num);
  13397. if(revbuf[2][0] != '\0')
  13398. {
  13399. temptransactionId = atoi(revbuf[2]);
  13400. if(transactionId != temptransactionId)
  13401. {
  13402. fprintf(fptr2, "%s\n", strtemp);
  13403. }
  13404. }
  13405. }
  13406. }
  13407. fclose(fptr1);
  13408. fclose(fptr2);
  13409. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13410. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13411. /*------ Read the file ----------------*/
  13412. }
  13413. int InternetDisconnect(void)
  13414. {
  13415. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13416. }
  13417. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13418. void storeTempStopTransaction(int gun_index)
  13419. {
  13420. char guid[37]={0};
  13421. int tempIndex = 0;
  13422. char TempStopTransaction[256];
  13423. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13424. DEBUG_INFO("storeTempStopTransaction...\n");
  13425. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13426. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13427. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13428. if(gunType[gun_index] == 'J')
  13429. {
  13430. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13431. {
  13432. tempIndex = ((gun_index==2) ? 1: 0);
  13433. }
  13434. else
  13435. {
  13436. tempIndex = gun_index;
  13437. }
  13438. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13439. {
  13440. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13441. {
  13442. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13443. }
  13444. }// END OF CHAdeMO_QUANTITY
  13445. }
  13446. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13447. {
  13448. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13449. {
  13450. tempIndex = ((gun_index==2) ? 1: 0);
  13451. }
  13452. else
  13453. {
  13454. tempIndex = gun_index;
  13455. }
  13456. for (int index = 0; index < CCS_QUANTITY; index++)
  13457. {
  13458. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13459. {
  13460. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13461. }
  13462. }// END OF CCS_QUANTITY
  13463. }
  13464. else if(gunType[gun_index] == 'G')
  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 < GB_QUANTITY; index++)
  13475. {
  13476. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13477. {
  13478. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13479. }
  13480. }// END OF GB_QUANTITY
  13481. }
  13482. else if(gunType[gun_index] == 'O')
  13483. {
  13484. tempIndex = gun_index;
  13485. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13486. {
  13487. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13488. {
  13489. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13490. }
  13491. }
  13492. }
  13493. else
  13494. {
  13495. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13496. {
  13497. tempIndex = 2;
  13498. }
  13499. else
  13500. {
  13501. tempIndex = gun_index;
  13502. }
  13503. for (int index = 0; index < AC_QUANTITY; index++)
  13504. {
  13505. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13506. {
  13507. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13508. }
  13509. }// END OF AC_QUANTITY
  13510. }
  13511. //Stop Transaction Time
  13512. struct timeval tmnow;
  13513. struct tm *tm;
  13514. char buf[28];//, usec_buf[6];
  13515. gettimeofday(&tmnow, NULL);
  13516. time_t t;
  13517. t = time(NULL);
  13518. /*UTC time and date*/
  13519. tm = gmtime(&t);
  13520. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13521. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13522. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13524. random_uuid(guid);
  13525. /***********************************transactionData******************************************************/
  13526. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13528. //=================================
  13529. //1. Transaction_Begin
  13530. //=================================
  13531. //============================== Energy.Active.Import.Interval ===========================================
  13532. //idx_sample=0;
  13533. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13535. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13536. 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*/]);
  13537. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13538. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13539. {
  13540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13541. }
  13542. else
  13543. {
  13544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13545. }
  13546. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13547. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13548. //=================================
  13549. //2. Transaction_End
  13550. //=================================
  13551. //2.1====================================== Current.Import L1 ==============================================
  13552. //idx_sample=1;
  13553. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13554. if(gunType[gun_index] == 'J')
  13555. {
  13556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13557. {
  13558. tempIndex = ((gun_index==2) ? 1: 0);
  13559. }
  13560. else
  13561. {
  13562. tempIndex = gun_index;
  13563. }
  13564. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13565. {
  13566. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13567. {
  13568. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13569. }
  13570. }// End of for CHAdeMO_QUANTITY
  13571. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13572. }
  13573. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13574. {
  13575. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13576. {
  13577. tempIndex = ((gun_index==2) ? 1: 0);
  13578. }
  13579. else
  13580. {
  13581. tempIndex = gun_index;
  13582. }
  13583. for (int index = 0; index < CCS_QUANTITY; index++)
  13584. {
  13585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13586. {
  13587. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13588. }
  13589. }// End of for CCS_QUANTITY
  13590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13591. }
  13592. else if(gunType[gun_index] == 'G')
  13593. {
  13594. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13595. {
  13596. tempIndex = ((gun_index==2) ? 1: 0);
  13597. }
  13598. else
  13599. {
  13600. tempIndex = gun_index;
  13601. }
  13602. for (int index = 0; index < GB_QUANTITY; index++)
  13603. {
  13604. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13605. {
  13606. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13607. }
  13608. }// End of for GB_QUANTITY
  13609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13610. }
  13611. else if(gunType[gun_index] == 'O')
  13612. {
  13613. tempIndex = gun_index;
  13614. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13615. {
  13616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13617. {
  13618. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13619. }
  13620. }
  13621. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13622. }
  13623. else
  13624. {
  13625. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13626. {
  13627. tempIndex = 2;
  13628. }
  13629. else
  13630. {
  13631. tempIndex = gun_index;
  13632. }
  13633. for (int index = 0; index < AC_QUANTITY; index++)
  13634. {
  13635. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13636. {
  13637. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13638. }
  13639. }// End of for AC_QUANTITY
  13640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13641. }
  13642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13645. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13646. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13647. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13648. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13649. //idx_sample=2;
  13650. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13651. if(gunType[gun_index] == 'J')
  13652. {
  13653. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13654. {
  13655. tempIndex = ((gun_index==2) ? 1: 0);
  13656. }
  13657. else
  13658. {
  13659. tempIndex = gun_index;
  13660. }
  13661. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13662. {
  13663. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13664. {
  13665. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13666. }
  13667. }// END OF CHAdeMO_QUANTITY
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13669. }
  13670. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13671. {
  13672. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13673. {
  13674. tempIndex = ((gun_index==2) ? 1: 0);
  13675. }
  13676. else
  13677. {
  13678. tempIndex = gun_index;
  13679. }
  13680. for (int index = 0; index < CCS_QUANTITY; index++)
  13681. {
  13682. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13683. {
  13684. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13685. }
  13686. }// END OF CCS_QUANTITY
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13688. }
  13689. else if(gunType[gun_index] == 'G')
  13690. {
  13691. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13692. {
  13693. tempIndex = ((gun_index==2) ? 1: 0);
  13694. }
  13695. else
  13696. {
  13697. tempIndex = gun_index;
  13698. }
  13699. for (int index = 0; index < GB_QUANTITY; index++)
  13700. {
  13701. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13702. {
  13703. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13704. }
  13705. }// END OF GB_QUANTITY
  13706. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13707. }
  13708. else if(gunType[gun_index] == 'O')
  13709. {
  13710. tempIndex = gun_index;
  13711. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13712. {
  13713. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13714. {
  13715. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13716. }
  13717. }
  13718. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13719. }
  13720. else
  13721. {
  13722. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13723. {
  13724. tempIndex = 2;
  13725. }
  13726. else
  13727. {
  13728. tempIndex = gun_index;
  13729. }
  13730. for (int index = 0; index < AC_QUANTITY; index++)
  13731. {
  13732. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13733. {
  13734. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13735. }
  13736. }// END OF AC_QUANTITY
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13738. }
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13742. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13745. //2.3====================================== Power.Active.Import =========================================
  13746. //idx_sample=3;
  13747. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13748. if(gunType[gun_index] == 'J')
  13749. {
  13750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13751. {
  13752. tempIndex = ((gun_index==2) ? 1: 0);
  13753. }
  13754. else
  13755. {
  13756. tempIndex = gun_index;
  13757. }
  13758. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13759. {
  13760. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13761. {
  13762. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13763. }
  13764. } // End for CHAdeMO_QUANTITY
  13765. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13766. }
  13767. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13768. {
  13769. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13770. {
  13771. tempIndex = ((gun_index==2) ? 1: 0);
  13772. }
  13773. else
  13774. {
  13775. tempIndex = gun_index;
  13776. }
  13777. for (int index = 0; index < CCS_QUANTITY; index++)
  13778. {
  13779. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13780. {
  13781. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13782. }
  13783. } // END for CCS_QUANTITY
  13784. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13785. }
  13786. else if(gunType[gun_index] == 'G')
  13787. {
  13788. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13789. {
  13790. tempIndex = ((gun_index==2) ? 1: 0);
  13791. }
  13792. else
  13793. {
  13794. tempIndex = gun_index;
  13795. }
  13796. for (int index = 0; index < GB_QUANTITY; index++)
  13797. {
  13798. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13799. {
  13800. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13801. }
  13802. }// END for GB_QUANTITY
  13803. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13804. }
  13805. else if(gunType[gun_index] == 'O')
  13806. {
  13807. tempIndex = gun_index;
  13808. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13809. {
  13810. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13811. {
  13812. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13813. }
  13814. }
  13815. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13816. }
  13817. else
  13818. {
  13819. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13820. {
  13821. tempIndex = 2;
  13822. }
  13823. else
  13824. {
  13825. tempIndex = gun_index;
  13826. }
  13827. for (int index = 0; index < AC_QUANTITY; index++)
  13828. {
  13829. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13830. {
  13831. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13832. }
  13833. } // END for AC_QUANTITY
  13834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13835. }
  13836. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13837. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13838. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13839. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13840. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13841. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13842. //2.4====================================== Voltage L1 ====================================================
  13843. //idx_sample=4;
  13844. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13845. if(gunType[gun_index] == 'J')
  13846. {
  13847. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13848. {
  13849. tempIndex = ((gun_index==2) ? 1: 0);
  13850. }
  13851. else
  13852. {
  13853. tempIndex = gun_index;
  13854. }
  13855. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13856. {
  13857. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13858. {
  13859. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13860. }
  13861. } // END OF FOR CHAdeMO_QUANTITY
  13862. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13863. }
  13864. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13865. {
  13866. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13867. {
  13868. tempIndex = ((gun_index==2) ? 1: 0);
  13869. }
  13870. else
  13871. {
  13872. tempIndex = gun_index;
  13873. }
  13874. for (int index = 0; index < CCS_QUANTITY; index++)
  13875. {
  13876. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13877. {
  13878. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13879. }
  13880. } // END OF FOR CCS_QUANTITY
  13881. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13882. }
  13883. else if(gunType[gun_index] == 'G')
  13884. {
  13885. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13886. {
  13887. tempIndex = ((gun_index==2) ? 1: 0);
  13888. }
  13889. else
  13890. {
  13891. tempIndex = gun_index;
  13892. }
  13893. for (int index = 0; index < GB_QUANTITY; index++)
  13894. {
  13895. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13896. {
  13897. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13898. }
  13899. } // END OF FOR GB_QUANTITY
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13901. }
  13902. else if(gunType[gun_index] == 'O')
  13903. {
  13904. tempIndex = gun_index;
  13905. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13906. {
  13907. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13908. {
  13909. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13910. }
  13911. }
  13912. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13913. }
  13914. else
  13915. {
  13916. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13917. {
  13918. tempIndex = 2;
  13919. }
  13920. else
  13921. {
  13922. tempIndex = gun_index;
  13923. }
  13924. for (int index = 0; index < AC_QUANTITY; index++)
  13925. {
  13926. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13927. {
  13928. 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
  13929. }
  13930. } // END OF FOR AC_QUANTITY
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13932. }
  13933. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13934. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13935. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13936. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13937. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13938. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13939. //2.5============================================== SoC =========================================================
  13940. //idx_sample=5;
  13941. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13942. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13943. {
  13944. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13945. {
  13946. tempIndex = ((gun_index==2) ? 1: 0);
  13947. }
  13948. else
  13949. {
  13950. tempIndex = gun_index;
  13951. }
  13952. if(gunType[gun_index] == 'J')
  13953. {
  13954. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13955. {
  13956. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13957. {
  13958. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13959. }
  13960. }
  13961. }
  13962. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13963. {
  13964. for (int index = 0; index < CCS_QUANTITY; index++)
  13965. {
  13966. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13967. {
  13968. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13969. }
  13970. }
  13971. }
  13972. else if(gunType[gun_index] == 'G')
  13973. {
  13974. for (int index = 0; index < GB_QUANTITY; index++)
  13975. {
  13976. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13977. {
  13978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13979. }
  13980. }
  13981. }
  13982. else if(gunType[gun_index] == 'O')
  13983. {
  13984. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13985. {
  13986. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13987. {
  13988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13989. }
  13990. }
  13991. }
  13992. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13993. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13994. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13995. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13996. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13997. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13998. } // END FOR DC CASE
  13999. //2.6====================================== Current.Import L2 ==============================================
  14000. // idx_sample=6;
  14001. // AC 3 phase L2 current
  14002. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14003. {
  14004. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14005. {
  14006. tempIndex = 2;
  14007. }
  14008. else
  14009. {
  14010. tempIndex = gun_index;
  14011. }
  14012. for (int index = 0; index < AC_QUANTITY; index++)
  14013. {
  14014. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14015. {
  14016. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  14017. }
  14018. }// End of for AC_QUANTITY
  14019. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  14020. }
  14021. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14022. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  14023. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  14024. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  14025. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14026. //2.7====================================== Current.Import L3 ==============================================
  14027. // idx_sample=7;
  14028. // AC 3 phase L3 current
  14029. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14030. {
  14031. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14032. {
  14033. tempIndex = 2;
  14034. }
  14035. else
  14036. {
  14037. tempIndex = gun_index;
  14038. }
  14039. for (int index = 0; index < AC_QUANTITY; index++)
  14040. {
  14041. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14042. {
  14043. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  14044. }
  14045. }// End of for AC_QUANTITY
  14046. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  14047. }
  14048. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14049. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  14050. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  14051. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  14052. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  14053. //2.9====================================== Voltage L2 ====================================================
  14054. //idx_sample=8;
  14055. // AC 3 phase L2 volatge
  14056. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14057. {
  14058. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14059. {
  14060. tempIndex = 2;
  14061. }
  14062. else
  14063. {
  14064. tempIndex = gun_index;
  14065. }
  14066. for (int index = 0; index < AC_QUANTITY; index++)
  14067. {
  14068. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14069. {
  14070. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  14071. }
  14072. } // END OF FOR AC_QUANTITY
  14073. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  14074. }
  14075. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14076. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  14077. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  14078. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  14079. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14080. //2.10====================================== Voltage L3 ====================================================
  14081. //idx_sample=9;
  14082. // AC 3 phase L3 volatge
  14083. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  14084. {
  14085. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14086. {
  14087. tempIndex = 2;
  14088. }
  14089. else
  14090. {
  14091. tempIndex = gun_index;
  14092. }
  14093. for (int index = 0; index < AC_QUANTITY; index++)
  14094. {
  14095. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14096. {
  14097. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  14098. }
  14099. } // END OF FOR AC_QUANTITY
  14100. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  14101. }
  14102. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  14103. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  14104. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  14105. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  14106. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  14107. //======================================== Message create ==============================================
  14108. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  14109. {
  14110. 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\"}]}]}]"
  14111. ,gun_index+1
  14112. ,MESSAGE_TYPE_CALL
  14113. ,guid
  14114. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14115. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14116. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14117. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14118. ,"PowerLoss"
  14119. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14120. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14121. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14122. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14123. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14124. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14125. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14126. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14127. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14128. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14129. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14130. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14131. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14132. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14133. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14134. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14135. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14136. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14137. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14138. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14139. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14140. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14141. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14142. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14143. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14144. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14145. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14146. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14147. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14148. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14149. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14150. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14151. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14152. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14153. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14154. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14155. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  14156. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  14157. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  14158. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  14159. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  14160. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  14161. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  14162. );
  14163. }
  14164. else
  14165. {
  14166. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  14167. {
  14168. 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\"}]}]}]"
  14169. ,gun_index+1
  14170. ,MESSAGE_TYPE_CALL
  14171. ,guid
  14172. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14173. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14174. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14175. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14176. ,"PowerLoss"
  14177. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14178. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14179. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14180. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14181. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14182. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14183. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14184. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14185. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14186. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14187. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14188. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14189. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14190. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14191. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14192. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14193. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14194. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14195. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14196. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14197. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14198. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14199. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14200. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14201. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14202. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14203. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14204. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14205. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14206. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14207. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14208. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14209. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14210. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14211. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14212. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14213. );
  14214. }
  14215. else
  14216. {
  14217. 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\"},{\"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\"}]}]}]"
  14218. ,gun_index+1
  14219. ,MESSAGE_TYPE_CALL
  14220. ,guid
  14221. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  14222. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  14223. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  14224. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  14225. ,"PowerLoss"
  14226. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  14227. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  14228. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  14229. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  14230. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  14231. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  14232. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  14233. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  14234. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  14235. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  14236. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  14237. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  14238. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  14239. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  14240. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  14241. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  14242. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  14243. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  14244. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  14245. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  14246. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  14247. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  14248. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  14249. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  14250. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  14251. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  14252. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  14253. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  14254. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  14255. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  14256. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  14257. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  14258. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  14259. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  14260. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  14261. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  14262. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  14263. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  14264. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  14265. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  14266. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  14267. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  14268. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  14269. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  14270. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  14271. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  14272. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  14273. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  14274. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  14275. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  14276. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  14277. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  14278. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  14279. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  14280. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  14281. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  14282. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  14283. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  14284. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  14285. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  14286. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  14287. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  14288. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  14289. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  14290. );
  14291. }
  14292. }
  14293. // Check File "TempStopTransaction" Exist
  14294. if((access(TempStopTransaction,F_OK))!=-1)
  14295. {
  14296. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14297. fclose(fopen(TempStopTransaction, "w"));
  14298. }
  14299. else
  14300. {
  14301. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14302. FILE *log = fopen(TempStopTransaction, "w+");
  14303. if(log == NULL)
  14304. {
  14305. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14306. return ;
  14307. }
  14308. else
  14309. {
  14310. fclose(log);
  14311. }
  14312. }
  14313. //Add TempStopTransaction | Update TempStopTransaction
  14314. // open file for writing
  14315. FILE *outfile;
  14316. outfile = fopen (TempStopTransaction, "a");
  14317. //DEBUG_INFO("data = %s\n", queuedata);
  14318. fputs(queuedata, outfile);
  14319. fputs("\n", outfile);
  14320. fclose (outfile);
  14321. }
  14322. void checkTempStopTransaction(int gun_index)
  14323. {
  14324. FILE *fptr1;
  14325. char ch;
  14326. char str[QUEUE_MESSAGE_LENGTH]={0};
  14327. char guid[37]={0};
  14328. char tempdata[65]={0};
  14329. char connectorStr[2]={0};
  14330. char TempStopTransaction[256];
  14331. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14332. fptr1 = fopen(TempStopTransaction, "r");
  14333. //TempStopTransaction格式: 槍號,StopTransaction封包
  14334. if (!fptr1)
  14335. {
  14336. //printf(" File not found or unable to open the input file!!\n");
  14337. return ;
  14338. }
  14339. ch=fgetc(fptr1);
  14340. //printf(" Now the content of the file %s is : \n",fname);
  14341. rewind(fptr1);
  14342. if(ch!=EOF)
  14343. {
  14344. // copy all contents to the temporary file except the specific line
  14345. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14346. {
  14347. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14348. if(str[0]=='\0')
  14349. {
  14350. break;
  14351. }
  14352. //TempStopTransaction格式: 槍號,StopTransaction封包
  14353. strncpy(connectorStr, str, 1);
  14354. if(atoi(connectorStr) != (gun_index+1))
  14355. {
  14356. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14357. fclose(fptr1);
  14358. return ;
  14359. }
  14360. //random_uuid(guid);
  14361. strncpy(guid, str+6, 36); //copy guid
  14362. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14363. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14364. {
  14365. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14366. }
  14367. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14368. memset(str,0,ARRAY_SIZE(str));
  14369. }
  14370. }
  14371. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14372. fclose(fptr1);
  14373. remove(TempStopTransaction); // remove the original file
  14374. }
  14375. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14376. {
  14377. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14378. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14379. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14380. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14381. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14382. }
  14383. int GetWebSocketPingInterval(void)
  14384. {
  14385. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14386. }
  14387. int GetServerSign(void)
  14388. {
  14389. return server_sign;
  14390. }
  14391. uint8_t GetOcppSecurityProfile()
  14392. {
  14393. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14394. }
  14395. void GetOcppChargerBoxId(uint8_t *data)
  14396. {
  14397. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14398. }
  14399. void GetOcppSecurityPassword(uint8_t *data)
  14400. {
  14401. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14402. }
  14403. void SetServerSign(int value)
  14404. {
  14405. server_sign = value;
  14406. }
  14407. int GetBootNotificationInterval(void)
  14408. {
  14409. return BootNotificationInterval;
  14410. }
  14411. int GetInternetConn(void)
  14412. {
  14413. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14414. }
  14415. void InitialSystemValue(void)
  14416. {
  14417. int connectorIndex = 0;
  14418. //int valueASCII = 0;
  14419. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14420. gunTotalNumber=0;
  14421. SystemInitial = 0;
  14422. localversion=0;
  14423. BootNotificationInterval = 0;
  14424. authorizeRetryTimes = 0;
  14425. GunStatusInterval = 10;
  14426. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14427. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14428. //Hear Beat
  14429. HeartBeatWithNOResponse = 0;
  14430. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14431. FirstHeartBeat = 0;
  14432. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14433. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14434. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14435. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14436. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14437. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14438. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14439. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14440. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14441. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14442. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14443. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14444. memset(gunType, 0, ARRAY_SIZE(gunType));
  14445. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14446. {
  14447. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='O')
  14448. {
  14449. // DO series
  14450. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14451. {
  14452. SystemInitial = SystemInitial + 1;
  14453. gunTotalNumber = gunTotalNumber + 1;
  14454. gunType[connectorIndex] = 'O';
  14455. connectorIndex = connectorIndex + 1;
  14456. }
  14457. }
  14458. else
  14459. {
  14460. // DM, DW, DS series
  14461. //check connector / socket type (index: 8, 9, 10)
  14462. for(int index=7; index <10 ; index++)
  14463. {
  14464. if(index != 8)
  14465. {
  14466. // DC Connector
  14467. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14468. {
  14469. SystemInitial = SystemInitial + 1;
  14470. gunTotalNumber = gunTotalNumber + 1;
  14471. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14472. connectorIndex = connectorIndex + 1;
  14473. }
  14474. }
  14475. else
  14476. {
  14477. // AC Connector
  14478. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14479. {
  14480. SystemInitial = SystemInitial + 1;
  14481. gunTotalNumber = gunTotalNumber + 1;
  14482. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14483. connectorIndex = connectorIndex + 1;
  14484. }
  14485. }
  14486. }
  14487. }
  14488. //DEBUG_INFO("DC ...\n");
  14489. }
  14490. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14491. {
  14492. //check connector / socket type (index: 8, 9, 10)
  14493. for(int index=7; index <10 ; index++)
  14494. {
  14495. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14496. {
  14497. SystemInitial = SystemInitial + 1;
  14498. gunTotalNumber = gunTotalNumber + 1;
  14499. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14500. connectorIndex = connectorIndex + 1;
  14501. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14502. }
  14503. }
  14504. }
  14505. //Status && ConnectorPlugIn Setting
  14506. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14507. {
  14508. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14509. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14510. }
  14511. for (int index = 0; index < CCS_QUANTITY; index++)
  14512. {
  14513. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14514. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14515. }
  14516. for (int index = 0; index < GB_QUANTITY; index++)
  14517. {
  14518. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14519. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14520. }
  14521. for (int index = 0; index < AC_QUANTITY; index++)
  14522. {
  14523. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14524. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14525. }
  14526. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14527. {
  14528. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14529. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14530. }
  14531. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14532. {
  14533. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14534. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14535. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14536. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14537. }
  14538. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14539. clientTime.Heartbeat=time((time_t*)NULL);
  14540. sleep(1);
  14541. }
  14542. void LWS_Send(char * str)
  14543. {
  14544. //=====================================================
  14545. // Check InternetConn 0: disconnected, 1: connected
  14546. //====================================================
  14547. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14548. {
  14549. DEBUG_INFO("offline now !!!\n");
  14550. return;
  14551. }
  14552. pthread_mutex_lock(&lock_send);
  14553. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14554. sprintf((char *)SendBuffer, "%s", str);
  14555. SendBufLen = strlen(str);
  14556. pthread_mutex_unlock(&lock_send);
  14557. lws_callback_on_writable(wsi_client);
  14558. //lws_service(context, 0);
  14559. //sleep(1);
  14560. }
  14561. void LWS_SendNow(char * str)
  14562. {
  14563. //=====================================================
  14564. // Check InternetConn 0: disconnected, 1: connected
  14565. //====================================================
  14566. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14567. {
  14568. DEBUG_INFO("offline now !!!\n");
  14569. return;
  14570. }
  14571. pthread_mutex_lock(&lock_send);
  14572. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14573. sprintf((char *)SendBuffer, "%s", str);
  14574. SendBufLen = strlen(str);
  14575. pthread_mutex_unlock(&lock_send);
  14576. lws_callback_on_writable(wsi_client);
  14577. lws_service(context, 0);
  14578. //sleep(1);
  14579. }